crypto-pro-js/examples/react/src/components/CryptoPro/Sign.js
2020-03-28 21:11:00 +03:00

28 lines
675 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React from 'react';
import { createSignature } from 'crypto-pro';
function Sign({certificate, onSign, onError, children}) {
async function sign() {
// Вычислинный hash по ГОСТ Р 34.11-94 для строки: "abc"
const hash = 'b285056dbf18d7392d7677369524dd14747459ed8143997e163b2986f92fd42c';
const hashBase64 = window.btoa(hash);
try {
onSign(await createSignature(certificate.thumbprint, hashBase64));
} catch (error) {
onError(error.message);
}
}
return (
<button
type="button"
disabled={!certificate}
onClick={sign}>
{children}
</button>
);
}
export default Sign;