function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ankush SamudralaAnkush Samudrala 

Encryption and Decryption problem

//For Encryption I used This:
Blob cryptoKey =EncryptURLClass.cryptoKeyVal;//// getting Static variable from public  class
 Blob data = Blob.valueOf(userName);
 Blob encryptedData = Crypto.encryptWithManagedIV('AES128', cryptoKey, data)
 strEncrptedData= EncodingUtil.base64Encode(encryptedData); 
 pageref.getParameters().put('uname',strEncrptedData);
 return pageref;  

After redirecting to this page I taken the uname(in Encrypted form) and performd as below

//For Decryption I followed this way.(This is in another class,I mean i am dng encryption in one class,decryption in another class)
 encryptdta=apexpages.currentpage().getParameters().get('uname');
      blob data = EncodingUtil.base64Decode(encryptdta);  
      Blob cryptoKey = EncryptURLClass.cryptoKeyVal;// getting Static variable from public  class
      Blob decryptedData = Crypto.decryptWithManagedIV('AES128', cryptoKey, data);
     string uname= decryptedData.toString();

I have getting below error:
Visualforce Error

System.SecurityException: Given final block not properly padded.

I Know that it becs of missmatch of key,thats y i have using same key from another class as static val.

Can you please share ur thoughts on the desired approach.
Thank you.