The tool is intended for experimentation with data processing
Sign sample data
Root CA Certificate & Private key from previous PKI example
Signer Certificate & Private key from previous PKI example
Data for signature
Не мысля гордый свет забавить,
Вниманье дружбы возлюбя,
Хотел бы я тебе представить
Залог достойнее тебя,
Достойнее души прекрасной,
Святой исполненной мечты,
Поэзии живой и ясной,
Высоких дум и простоты;
Но так и быть — рукой пристрастной
Прими собранье пестрых глав,
Полусмешных, полупечальных,
Простонародных, идеальных,
Небрежный плод моих забав,
Бессонниц, легких вдохновений,
Незрелых и увядших лет,
Ума холодных наблюдений
И сердца горестных замет.
Data signature CMS PKCS#7 formatSign data method
var modes = new Function( 'return (' + signType.value + ')' )();
try {
var content = gostCrypto.coding.Chars.decode(message.textContent, 'utf-8');
var finish, msg;
if (modes.digest) {
// Create digested data info
msg = new gostCrypto.cms.DigestedDataContentInfo();
msg.writeDetached(modes.detached);
finish = msg.encloseContent(content, provider.value);
} else {
// Import CA root certificate
var cacert = new gostCrypto.cert.X509(certAndKeyCA.textContent);
// Import private key of the signer
var key = new gostCrypto.asn1.PrivateKeyInfo(signerCert.textContent);
// Import certificate of the signer
var cert = new gostCrypto.cert.X509(signerCert.textContent);
// Create signed data info
msg = new gostCrypto.cms.SignedDataContentInfo();
msg.setEnclosed(content);
msg.writeDetached(modes.detached);
// Add certificate
if (modes.certpath)
msg.content.certificates = [cert];
// Add new signature
finish = msg.addSignature(key, cert, modes.attrs);
}
// Wait and print result
finish.then(function() {
// Output signed data
signedData.textContent = msg.encode('PEM');
}).catch(function(reason) {
alert(reason.message);
});
} catch(e) {
alert(e.message);
}
Verify signature
Signed data verification method
var modes = new Function( 'return (' + signType.value + ')' )();
try {
// Create a signed data info
var data = signedData.textContent, verifier, msg;
// Get the content for detached mode
var content = modes.detached &&
gostCrypto.coding.Chars.decode(message.textContent, 'utf-8');
if (modes.digest) {
// Verify message digest
msg = new gostCrypto.cms.DigestedDataContentInfo(data);
verifier = msg.verify(content);
} else {
msg = new gostCrypto.cms.SignedDataContentInfo(data);
// Check the signature
if (modes.certpath) {
// Use the CA root certificate
var cacert = new gostCrypto.cert.X509(certAndKeyCA.textContent);
var trustPolicy = new gostCrypto.cert.TrustedCAPolicy([cacert]);
verifier = msg.verify(trustPolicy, content);
} else {
// Use the signer's certificate
var cert = new gostCrypto.cert.X509(signerCert.textContent);
verifier = msg.verifySignature(cert, content);
}
}
verifier.then(function () {
// Signature verified
verified.value = 'Yes: Signature verified';
}, function (reason) {
// Reject if signature not verified
verified.value = 'No: ' + reason.message;
});
} catch (e) {
alert(e.message);
}