Nodejs crypto library:
Example:
<script type="text/javascript">
var crypto = require('crypto');
var fs = require("fs");
var plaintext = "test";
var privateKey = fs.readFileSync("rsakey1024.txt", "utf8");
var publicKey = fs.readFileSync("publickey1024.txt", "utf8");
/*-----------------------------------------------------------*
* ENCRYPT: RSA 1024 bit *
*-----------------------------------------------------------*/
var cipertext = _encrypt(plaintext, privateKey);
// verification
var result = _verify(plaintext, cipertext, publicKey);
if (result == false) {
console.log("encryption failed!!!");
}
/********************************************************************
IMPLEMENTING FUNCTIONS...
********************************************************************/
function _encrypt(plaintext, privateKey)
{
var signer = crypto.createSign("RSA-SHA256");
signer.update(plaintext);
var sign = signer.sign(privateKey, "hex");
return (sign);
}
function _verify(plaintext, cipertext, publicKey)
{
var verifier = crypto.createVerify("RSA-SHA256");
verifier.update(plaintext);
var result = verifier.verify(publicKey, cipertext, "hex");
return (result);
}
</script>
keys are not supported: