2

Cybersource is asking to generate a digest from payload using byte array. However we don't have bytes in apex. I'm getting SHA-256=k3t9b6mL4zCMDTOi7N1uLQMu9XxrjwOr5yRXnTG0G1A= hash when I try to compute the digest, but cybersource returns SHA-256=S7Euokf7I2meKLJOT3+zYG/yjTMsQR5mbT9fwGvueI8= hash when I'm using their platform to generate it. Below is my code, can someone point out what I'm doing wrong? This is the url for Cybersource instruction.

public static String generateDigest() {
        String body = '{'
                        +'"clientReferenceInformation": {'
                            +'"code": "US200025617"'
                            +'},'
                        +'"orderInformation": {'
                            +'"amountDetails": {'
                                +'"totalAmount": "110.41",'
                                +'"currency": "USD"'
                                +'}'
                            +'}'
                        +'}';
        Blob b = Blob.valueOf(body);
        String digest = EncodingUtil.base64Encode(Crypto.generateDigest('SHA-256', b));
        digest = 'SHA-256='+ digest;
        System.debug(digest);
        
        return digest;

1 Answer 1

0

I just needed to make sure to have exact same String both in my code, and Cybersource Developer API portal. I just needed to remove spaces both in Apex, and Cybersource Developer API portal, and was able to generate exact same digest in both places. So above code works as expected.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .