2

We are integrating salesforce with external system. External system has two factor authentication process.

  1. We are calling first URL to get challenge. - Working fine.

  2. We need to decrypt challenge in step2. We have an issue to decrypt the challenge, the error is:

    "Invalid parameter exception, private key must have 16 bytes" .

    String challenge = 'NdqeqeqYQVyWaq0jYyB71Odhog==';
    blob challenge1 = EncodingUtil.base64Decode(challenge);
    String mkey = 'zxvfg12';// client ask to convert into 16bytes but salesforce doesn't support.
    blob base64key = EncodingUtil.base64Decode(mpin);
    Blob decrypted = Crypto.decryptWithManagedIV('AES128', base64key, challenge1);
    system.debug('.......'+decrypted);
    String decryptedString = decrypted.toString();
    System.debug('......'+decryptedString);
    

Is it possible to decrypt in Salesforce?

  • 3
    That's not a 16 byte key. It's not even a valid base 64 string. Yes, you can decrypt in Salesforce, but you need the right key. – sfdcfox Jul 30 '18 at 7:38
  • Sfdcfox, Yes that is not 16 byte key. We need to convert to 16 byte array . We are not able to convert in salesforce hence salesforce doesn't support byte data type. – siva krishna Jul 30 '18 at 10:15
  • We are requested customer to get 16 byte array. Please see below String challenge = 'XF9kkKtLbjYgkub2Dv7Esg=='; blob challenge1 = EncodingUtil.base64Decode(challenge); blob base64key = EncodingUtil.base64Decode('UGFzczEyAAAAAAAAAAAAAA=='); Blob decrypted = Crypto.decryptWithManagedIV('AES128',base64key,challenge1); system.debug('.......'+decrypted); String decryptedString = decrypted.toString(); System.debug('......'+decryptedString);// Result is Empty string – siva krishna Jul 30 '18 at 10:18
  • Please edit your question with any additional information or clarification rather than posting in comments. – David Reed Jul 30 '18 at 17:06
  • Any time encryption is in use, it is critical to be precise about how the encryption is being performed. You need to have the right key in the right format, use the matching algorithm and cipher mode, supply the initialization vector as expected by decryptWithManagedIV(), and so forth. If you don't know any of those factors, you need to go find out from the source system. – David Reed Jul 30 '18 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.