You need to sign in to do that
Don't have an account?
we-mp
Crypto class - InvalidParameterValue
Hello,
I am trying to encrypt and decrypt a password using the Crypto class.
try{ Blob cryptoKey = Crypto.generateAesKey(128); Blob data = Blob.valueOf(weUserRec.password__c); Blob encryptedData = Crypto.encryptWithManagedIV('AES128', cryptoKey, data); Blob decrypt = Crypto.decryptWithManagedIV('AES128', cryptoKey, data); }catch(Exception e){ System.debug(e.getMessage()); }
The above is throwing an exception with message "Invalid initialization vector. Must be 16 bytes" (InvalidParameterValue).
Since the SF provided Managed IV methods are used here (the code is almost exactly like the sample), why does it throw this error?
Thanks.
According to your code, you encrypted a string and trying to decrypt it, but decryption is logical only for encrypted data and you passed simple string data as parameter in decryption method rather than encrypted data.
Blob decrypt = Crypto.decryptWithManagedIV('AES128', cryptoKey, data);
It should be:
Blob decrypt = Crypto.decryptWithManagedIV('AES128', cryptoKey, encryptedData );
Hope this helps.
Thanks. That helped.
I have another related question. I am saving the key and password value in a Custom Setting object. Both values are converted to String and then stored.
In another controller, I am retrieving the value and decrypting the password:
The decryptWithManagedIV throws an exception with message "
Any thoughts on why this exception is thrown?
Thank you.
I'm also running into this issue.
Has anyone found a reason/answer?
Thanks
I'm having the same problem as well. I need to be able to store the key and use it to decrypt data in another application. If we supply our own key, what format should that be in?
I am experiencing the same problem, how did you finaly solve it?
Try this code.
It works.
Good Luck