I am trying to encrypt a string using AES256 then converting it to Hex.
I am supplied a Hex key so I tried going online and converting the Hex to text and using that value in my class but I keep getting an error message "Invalid private key. Must be 32 bytes"
The think the actual size of the key is 27 bytes and that is the issue. What is a better way to to convert the hex key into a format that I can be used in the encryption? The key I supplied is not the actual result, this is for reference only.
public static String encrypt(String toEncrypt){
string nonHexKey = '23432%^$^%^';
Blob newKey= Blob.valueOf(nonHexKey);
Blob encrypted = Crypto.encryptWithManagedIV('AES256', newKey,Blob.valueOf(toEncrypt));
String encodedCiphertextAndIV = EncodingUtil.convertToHex(encrypted);
EncodingUtil.convertFromHex
is your friend