Created
September 17, 2014 14:57
-
-
Save pbakondy/660191dde4be81088d34 to your computer and use it in GitHub Desktop.
RSA Encrypt with forge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* RSA Encrypt a String with Public Key | |
* | |
* @uses forge encryption library | |
* @param <String> text - string to encode | |
* @param <BigInteger> modulus - public key modulus | |
* @param <BigInteger> exponent - public key exponent | |
* @return <String> - encoded string in hex | |
*/ | |
function RSAEncrypt(text, modulus, exponent) { | |
text = forge.util.encodeUtf8(text); | |
var publicKey = forge.pki.setRsaPublicKey(modulus, exponent); | |
var encrypted = publicKey.encrypt(text); | |
return forge.util.bytesToHex(encrypted); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment