RSA Signing and Verification in JavaScript

This project have been moved to github (http://kjur.github.com/jsrsasign/) on Mar 1, 2012. This page have *NEVER* been maintained. I'm glad if you update URL links to this page . Thanks :)
Kenji Urushima
Sep 25, 2010

The 'RSA-Sign JavaScript Library' is a open source free pure JavaScript implementation of PKCS#1 v2.1 RSASSA-PKCS1-v1_5 RSA signing and validation algorithm.

DEMO

SOURCE CODES

The 'rsa-sign' library contains following source codes.

LICENSE

The 'RSA-Sign JavaScript Library' is licensed under the terms of the MIT license reproduced below.

How to sign

var rsa = new RSAKey(); rsa.readPrivateKeyFromPEMString(_PEM_PRIVATE_KEY_STRING_); var hSig = rsa.signString("aaa", "sha1"); // sign a string "aaa" with key

How to verify signature

vr x509 = new X509(); x509.readCertPEM(_PEM_X509CERT_STRING_); var result = x509.subjectPublicKeyRSA.verifyString("aaa", _HEX_SIGNATURE_);

How to add supported signature algorithms

The script "rsa-sign.js" currently supports SHA1withRSA and SHA256withRSA signature algorithms. However you can extend other signature algorithms such like MD5withRSA or SHA512withRSA by just specifying two variables in it.
_RSASIGN_DIHEAD['md5'] = "30..."; // Hexadecimal DigestInfo prefix for MD5 _RSASIGN_HASHHEXFUNC['md5'] = md5hex; // function which returns value in hex.

Required Third Party Source Codes

Copyright © 2010 Kenji Urushima. All rights reserved.

CHANGES