• Sujal Gupta 10
  • NEWBIE
  • 0 Points
  • Member since 2016


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hi,

I am trying to encrypt and decrypt the data, I got error while decrypt the data. Please find the code below.

Encrypt Code: 

             Blob cryptoKey = Crypto.generateAesKey(256);
             Blob data = Blob.valueOf(opps.id);
             Blob encryptedData = Crypto.encryptWithManagedIV('AES256', cryptoKey , data );
             String b64Data = EncodingUtil.base64Encode(encryptedData);
             opps.EncryptedKey__c = b64Data ;  

Decrypt Code :

            Blob cryptoKey = Crypto.generateAesKey(256);
            Blob data = EncodingUtil.base64Decode(opps.EncryptedKey__c);
            Blob decryptedData = Crypto.decryptWithManagedIV('AES256', cryptoKey , data);
            String dryptData = decryptedData.toString();
            opps.Unecrypt__c = dryptData; 

The above encrypt code is working fine, the decrypt code is not working i got the below error. Please i need urgent help.

Error :
FATAL_ERROR|System.SecurityException: Given final block not properly padded

Thanks in advance.