Salesforce Asked by Dibyaranjan Sahoo on January 17, 2021
I have an encrypted token(Encrypted in Java system with AES256 algorithm and PKCS7 padding).
when I try to decrypt in SF using crypto class. some of the information is missing from the original token.
As Crypto class supports PKCS5 padding, I doubt this is the problem.
Any help will be highly appreciated how to decrypt correctly using PKCS7 padding in SF. Following is the sample code I’m using
String beforeEncryption =
‘{"UserId":12345,"Role":"testRole","LicenceNumber":"123456789","EmiartesId":"784198012345678","LicenceAuthority":"test","Expiry":"2020-11-13T15:27:16.6847792+04:00"}’;
String encrypted =
‘D7dEjNTmJdbQDbNokTwiwaWqetSDnXnxH4+Eqzi34sRvyl/jOqLud6IQKYU3kylgUQCFsib6eENaq2KLhXx/fgChPIXCCGZMsw+/Euo2z9ZVzjk0Kq4VzP3LWb1GRHl4ygJJ8f2GN/JgBBZiyqAXb3CHKBjwwxHddZLkxvX7WcHyX9Odvt3Eh+fmbw6jJtPWH5lKBSx2jOQSAsBjaMENbqDU7Rqhg9p4Eq21zoXvRoI=’;
Blob decodedEncryptedText=EncodingUtil.base64Decode(encrypted);
Blob cryptoKey=Blob.valueOf('NW7LbO3xdUmXZEIvjYkzxA==AxC0Eh1o');
Blob decryptedData = Crypto.decryptWithManagedIV('AES256',cryptoKey,decodedEncryptedText);
system.Debug('--valuee'+decryptedData.toString());
//After decrypting in Apex using apex crypto method
Decrypted text =
‘"Role":"testRole","LicenceNumber":"123456789","EmiartesId":"784198012345678","LicenceAuthority":"test","Expiry":"2020-11-13T15:27:16.6847792+04:00"}’
Issue: {"UserId":12345,
is missing in the decrypted text.
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP