question

Bryan Cruz avatar image
Bryan Cruz asked Raymond Lee Deactivated answered

Dev Pay API Card Encrypt

Before last year ended I was working on integrating our in-house POS system with the Developer API. I used a mix of the V2 and V3 API to accomplish it.
I had it working last December and January and stopped working on it and put it in Production. The people that use the POS tried it and they were happy with it. However, they were trying to start using this feature and they can't anymore. I noticed that on the response I'm getting
{
    "paymentId": "FXX23YAAJKBX8",
    "result": "DECLINED",
    "failureMessage": "CRYPTO FAILURE"
}

I'm using C# to make the encryption and the RSACryptoServiceProvider Class to make the encryption

byte[] modulus = m.ToByteArray();
byte[] exponent = e.ToByteArray();
var rsaServer = new RSACryptoServiceProvider(2048);
var keyParameters = new RSAParameters{
    Modulus = modulus,
    Exponent = exponent,
};

rsaServer.PersistKeyInCsp = false;
rsaServer.ImportParameters(keyParameters);

using (var rsa = new RSACryptoServiceProvider(2048))
    {
        try
        {
            // Encrypting data with public key issued
            rsa.FromXmlString(publickeyXml);
            var EncryptedUtf8CardNumber = rsa.Encrypt(utf8CardNumber, true);

            // converting encrypting to base64
            string base64EncryptedCardNumber = Convert.ToBase64String(EncryptedUtf8CardNumber);
            
            return base64EncryptedCardNumber;
        }
        catch (Exception ex)
        {
            return "ERROR: " + ex.Message;
        }
        finally
        {
            rsa.PersistKeyInCsp = false;
        }
    }

Was something changed on the API regarding payment?
Tried to run the transaction on the sandbox and same issue
Sandbox MID (Currently in use to debug the problem) = 86DHG1WM70AP6

Thank you very much in advance,
Payments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Raymond Lee avatar image
Raymond Lee Deactivated answered
Nothing was changed on the API regarding developer pay API's encrypting process.

For your C# implementation, one thing I would check is that the byte arrays you are passing into RSACryptoServiceProvider are big-endian byte arrays, as that is what it expects.

Assuming that m and e are BigIntegers, and you are using ToByteArray() of the BigInteger class, you can see in the docs that the results are little-endian. That means you will need to reverse the byte arrays before passing them into RSAParameters to pass to RSACryptoServiceProvider.

We have examples of using our developer pay API here, and there is one for C# that you can use as reference.
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community