title: Data Encryption using RSA in javascript
body: <p>I am using RSA Encryption using <a href="http://www-cs-students.stanford.edu/~tjw/jsbn/" rel="nofollow">JSBN</a></p>
  
  <p>When I write following code, I am getting error - " 'null' is not an object (evaluating 'this.n.bitLength')" on 92th line(var m = pkcs1pad2(text,(this.n.bitLength()+7)>>3);) in rsa.js file - <a href="http://www-cs-students.stanford.edu/~tjw/jsbn/rsa.js" rel="nofollow">http://www-cs-students.stanford.edu/~tjw/jsbn/rsa.js</a></p>
  
  <pre><code>var rsa = new RSAKey();
  var pk = "----BEGIN PUBLIC KEY----\r\n"+
  "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0\r\n"+
  "FPqri0cb2JZfXJ/DgYSF6vUpwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/\r\n"+
  "3j+skZ6UtW+5u09lHNsj6tQ51s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQAB\r\n"+
  "----END PUBLIC KEY----";
  rsa.setPublic(pk);
  var data = rsa.encrypt('hello world');
  </code></pre>
  
  <p>List of files included :<br/>
  jsbn.js,<br/>
  prng4.js,<br/>
  rng.js,<br/>
  rsa.js</p>