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

Third party System cannot decode AES 128 String Unrecognized base64 character: \

We have a Callout method where we are sending JSON data after encrypting data with AES 128 to an external system but external system Cannot decode this as they are getting error like "Unrecognized Base 64 string , String Contains a Non-Base 64 Character". However we have a webservice which is getting called by external system and we are are serializing the response and sending AES 128 encrypted response and they are able to decrypt it correctly. The can see the differnce between these 2 from my Logs that one of the response contains "/" which might be the problem here. What i don't understand is i am using 1 single method to decrypt every callout or webservice request Body or response data respectively but one is giving error and other is not

Web service respose data we are sending:

Call Out Request Body we are Posting


Method Used to create AES encryted data

public static String getEncryptedData(String inputData){
        String b64Data = EncodingUtil.base64Encode(Blob.valueOf(inputData));
        Blob key = EncodingUtil.base64Decode(KEY);
        Blob IV =  EncodingUtil.base64Decode(IV);
        Blob encryptedData = Crypto.encrypt('AES128', key, IV, Blob.valueOf(b64Data));
        //encrypted string
        String encodedprdata = EncodingUtil.base64Encode(encryptedData);
        return encodedprdata;

Also, My Json String which i will encrypyt for Callout request body contain an attribute which is MD5 encrypted 

public static String getMD5EncryptedData(String inputData){
         Blob hash = Crypto.generateDigest('MD5', Blob.valueOf(inputData));
        String sign = EncodingUtil.convertToHex(hash);
        return sign;

Have anyone ever faced this kind of issue and this is really irritating me and going clueless over this. Can someone please help on this? Thanks in advance