Salesforce InvalidParameterValueException

Salesforce InvalidParameterValueException

Exception:

System.InvalidParameterValueException: Invalid private key. Must be 16 bytes.

Resolution:

When we use Crypto.encryptWithManagedIV(), the key should be at least 16 bytes.

Sample Code:

/* Encryption */
Blob key = Blob.valueOf(
	'1234567890=abcde'
);
Blob blobData = Blob.valueOf(
	'Sample Data to be encrypted'
);
Blob encryptedBlob = Crypto.encryptWithManagedIV(
	'AES128', 
	key, 
	blobData
);
/* Decryption */
Blob decryptedBlob = Crypto.decryptWithManagedIV(
	'AES128',
	 key, 
	 encryptedBlob
);
String decryptedString = decryptedBlob.toString();
System.debug(
	decryptedString
);

Leave a Reply