title: Sign data in node js and verify it in Java
body: <p>I'm creating the keys pair with <a href="https://nodejs.org/api/crypto.html" rel="nofollow noreferrer">crypto</a> in nodejs.</p>
  
  <pre><code>var { publicKey, privateKey } = generateKeyPairSync('rsa', {
          modulusLength: 1024,
          publicKeyEncoding: {
            type: 'spki',
            format: 'pem'
          },
          privateKeyEncoding: {
            type: 'pkcs8',
            format: 'pem',
            cipher: 'aes-256-cbc',
            passphrase: ''
          }
        });
  </code></pre>
  
  <p>The publicKey generated is:</p>
  
  <p><code>"-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDCnwiV6Opd+3TZf9N1z9GVhxtY\nnqWiFRIsqUOR/vXXge8hbhgm5ITKfZtvyO92Lk+5Tl1Qdrb+OfNcKmBHkGUEdBib\nXCNEXj7SOhQTBH0PnV++8+xJXoutsiJU9Z+sjMCFivbd5wgBizXcY8U9SQfYb+Iv\nNQ8FBL4nV8lMiwAp8QIDAQAB\n-----END PUBLIC KEY-----\n"</code></p>
  
  <p>I'm trying to sign a message and verify it in Java.</p>
  
  <p>The problem I'm having is to parse the string key (sign key) to <code>PublicKey</code> in Java with:</p>
  
  <pre><code>public static PublicKey loadPublicKey(String stored) throws GeneralSecurityException, IOException {
          byte[] data = Base64.getDecoder().decode((stored.getBytes()));
          X509EncodedKeySpec spec = new X509EncodedKeySpec(data);
          KeyFactory fact = KeyFactory.getInstance("RSA");
          return fact.generatePublic(spec);
      }
  </code></pre>
  
  <p>The error shown is :</p>
  
  <p><code>Exception in thread "main" java.lang.IllegalArgumentException: Illegal base64 character a</code></p>
  
  <p>How can I verify the message?</p>
  
  <p>Thank you in advance</p>