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
darrenw_ukdarrenw_uk 

AES128 encryption using Crypto.encryptWithManagedIV

I'm trying to construct a url in a controller and one of the parameters need to be AES128 encrypted, and then urlencoded. I've been given a base64encoded key to use, and I'm attempting to use Crypto.encryptWithManagedIV class to encrypt the param like so:

 

Blob encryptionKey = EncodingUtil.base64Decode('xxxxxxxxxxxxxxxxxx');
    String payloadStr = 'text to be encoded';
    Blob payload = Blob.valueof(payloadStr);
    Blob encryptedPayload = Crypto.encryptWithManagedIV('AES128', encryptionKey, payload);
    myUrl = 'http://www.mysite.com/myPage.aspx?a=' + EncodingUtil.urlEncode(encryptedPayload.Tostring(),'UTF-8');

 

The error I'm getting is Invalid private key. Must be 16 bytes.

 

 

_Prasu__Prasu_

How many bytes does your encryption key contains?