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
VVKrishnaVVKrishna 

16Byte Hexadecimal value is changed to 32Bytes when it is converted as Blob

I am having a hexadecimal value of 32 characters which I am storing in String(as salesforce do not have any data type for hexadecimal). When I am converting this String to Blob and using the blob for encryption, the blob size is changed to 32Bytes (each character is been considered as 1 byte unlike the regular hexadecimal where 2 characters make a byte). Can any one please let me know how to store hexadecimal values in Salesforce and how to convert it accordingly so that the size does not change. Or do we have any way to convert it to blob where we get only 16bytes instead of 32 bytes

sfdcfoxsfdcfox

You have to store the BASE64 form of your key, not the hex form. Storing the key as a hex string really does make it 32 bytes, not the orginal 16. To get the Blob from the BASE64 string, use the EncodingUtil.base64decode(String) function.

 

Here is an example case:

 

String keyAsBase64 = '9JalR14a+xk/Kdal51+3A===';
Blob keyAsBlob = EncodingUtil.base64Decode(keyAsBase64);
// keyAsBase64.size() should be 24, keyAsBlob.size() is 16

 

VVKrishnaVVKrishna

Thanks for your reply.  I have actually performed the same and have got the result.  But I have one more problem, I have integer to be encrypted but encryptionwithManagedIV will take only blob.valueOf(string).  can you please help me out with this

sfdcfoxsfdcfox
For encryption, you would have to convert the integer to a string using String.valueOf(Integer) before encrypting. To decrypt, you first decrypt back into a string then use Integer.valueOf(String) to get the native Integer back. Encryption can only be performed on text.
Sunitha Ganji 3Sunitha Ganji 3
I have executed in Anonymous Window and was success, but where can I get the 32Bit user key for my password:
String keyAsBase64 = 'RjFuJHRyb0ludGVncmF0aW9uJA==';
Blob keyAsBlob = EncodingUtil.base64Decode(keyAsBase64);

I need to 32bit User key for Integrationg Salesforce in a HTML POST page, How can I get 32bit User Key for my password