Print this page

Why are special or additional characters added to our decrypted text?

Knowledge Article Number 000181832
Description When the Apex Crypto Class is used to encrypt some value using methods encryptWithManagedIV() or encrypt() the encrypted text may or may not be URL or Base64 encoded. When the encrypted blob is sent to an external source and decrypted, the text is prefixed with special characters e.g. ��WVv�>US�/\RI��
Resolution - As per the documentation for Crypto Class, the encryptWithManagedIV() method manages the initialization vector for you, where as the encrypt() method takes the initialization vector as an argument.
- This vector is stored in the leading 128 bits (16 bytes) of the blob.
- This should not be a surprise, as this initialization vector is required to decrypt the text (for example, the openssl "enc -d" command takes -iv as a required argument)
- These leading characters can be dismissed form the decrypted text after the decryption process

promote demote