title: rsa js pidCrypt encryption java decryption
body: <p>I am trying to encrypt some simple message with pidCrypt in browser, then decrypt it with java crypto on the server. But I kept getting the error message:</p>
  
  <p><strong>javax.crypto.IllegalBlockSizeException: Data must not be longer than 128 bytes</strong></p>
  
  <p><strong>Keys:</strong></p>
  
  <p>keys are generated with openssl genrsa (sslery).
  The private key then converted to pkcs#8 der format and read into java code</p>
  
  <p><strong>JS code snippet:</strong></p>
  
  <pre><code>/*---* ENCRYPT: RSA 1024 bit ---------*/  
  
   // public key  
   var params = certParser(publickey);  
   var key = pidCryptUtil.decodeBase64(params.b64);  
  
  
   // new RSA instance  
   var rsa = new pidCrypt.RSA();  
  
  
  /* RSA encryption 
   * get the modulus and exponent from certificate (ASN1 parsing) 
   * pem(Array of Bytes)        
   */  
  
   // ASN1 parsing  
   var asn = pidCrypt.ASN1.decode(pidCryptUtil.toByteArray(key));  
   var tree = asn.toHexTree();  
  
   // setting the public key for encryption with retrieved ASN.1 tree  
   rsa.setPublicKeyFromASN(tree);  
  
   /*** encrypt */  
   var crypted = rsa.encrypt(plaintext);  
   //var crypted64 = pidCryptUtil.encodeBase64(crypted);
  </code></pre>
  
  <p><strong>java code snippet:</strong></p>
  
  <pre><code>       Cipher cipher = Cipher.getInstance("RSA");  
         cipher.init(Cipher.DECRYPT_MODE, myPrivKey);  
         byte[] descryptedData = cipher.doFinal(cyphertext.getBytes());  
  </code></pre>