xxxxxxxxxx
rsa_signhash_pkcs(pRsaKey,cHashValue) ---> return a string containing RSA PKCS signature
xxxxxxxxxx
rsa_sign_pkcs(pRsaKey,cData) ---> return a string containing RSA PKCS signature
xxxxxxxxxx
/* sign a document using RSA-PKCS with SHA256.
* digest OID added manually
*/
try
/* read Alice private key */
rsaKeyPEM = Read("alice_private_key.pem")
rsaKey = rsa_import_pem(rsaKeyPEM)
/* read file content */
cFileContent = Read ("document.txt")
/* hash content */
digest = SHA256(cFileContent)
/* digest OID of SHA256 */
digestOID = hex2str("3031300d060960864801650304020105000420")
/* perform PKCS signing */
dataToSign = digestOID + digest
cSignature = rsa_sign_pkcs(rsaKey,dataToSign)
/* store the signature */
Write("document.txt.pkcs1.sig", cSignature)
catch
See "Unexpected error occured: " + cCatchError + nl
done
xxxxxxxxxx
/* sign a document using RSA-PKCS with SHA256.
*/
try
/* read Alice private key */
rsaKeyPEM = Read("alice_private_key.pem")
rsaKey = rsa_import_pem(rsaKeyPEM)
/* read file content */
cFileContent = Read ("document.txt")
/* hash content */
digest = SHA256(cFileContent)
/* perform PKCS signing */
cSignature = rsa_signhash_pkcs(rsaKey,digest)
/* store the signature */
Write("document.txt.pkcs1.sig", cSignature)
catch
See "Unexpected error occured: " + cCatchError + nl
done