0

What's the way of doing this? I tried using CryptoJS on angular and Crypto Module on node, without success I keep getting description error

Angular encrypt method :

 _rsaEnc(p) {
    var e = new JSEncrypt();
    const key = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDlOJu6TyygqxfWT7eLtGDwajtNFOb9I5XRb6khyfD1Yt3YiCgQWMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76xFxdU6jE0NQ+Z+zEdhUTooNRaY5nZiu5PgDB0ED/kaskaskKAS';
    e.setPublicKey(key);

    return e.encrypt(p);
  }

Node decrypt method

privK = {
          key: fs.readFileSync('./app/services/private.pem').toString(),
          passphrase: 'xxxxxx'
      };
      var buf = Buffer.from(base64Data, 'base64');

      origData = crypto.privateDecrypt(privK, buf);
     return origData.toString('utf-8');

error:

Error: error:040A1079:rsa routines:RSA_padding_check_PKCS1_OAEP_mgf1:oaep decoding error

5

1 Answer 1

1

Ended up changing the angular lib to jsencrypt, CryptoJS doesnt support RSA, and changed node lib to node-rsa to set the encryption scheme to pkcs1 with

myDecrypter.setOptions({encryptionScheme: 'pkcs1'});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.