Skip to content

signature

oabdoun edited this page Dec 5, 2014 · 9 revisions

Payment Signature

Signatures are HMAC-SHA1s of payment data, generated using your "merchant secret key" as the cryptographic key. In the payment flow, there are 2 signatures: the one you generate and send to CitrusPay as part of the "make payment" request to start the payment flow (the request signature), the one CitrusPay generates and send to you as part of the response to your "return URL" at the end of the payment flow (the response signature).

Request signature

This is the HMAC-SHA1 of the string

merchantAccessKey=<access_key>&transactionId=<order_id>&amount=<order_amount>

where:

  • <access_key> is your "merchant access key"
  • <order_id> is your order (or transaction) identifier
  • <order_amount> is the numeric value of the amount of your order (or transaction)

Response signature

This is the HMAC-SHA1 of the string

<TxId><TxStatus><amount><pgTxnNo><issuerRefNo><authIdCode><firstName><lastName><pgRespCode><addressZip>

where <param> is the value of the parameter named param in the response posted by CitrusPay to your "return URL".

Implementation

Most modern platforms come with an HMAC-SHA1 implementation. The signature your are passing / receiving is actually the hexadecimal encoding of the HMAC.

As an example, here is a couple of HMAC-SHA1 implementation in different programming languages, for sample "merchant secret key" 647c4c37ce8d84d09c83f836faf97aae722e716a and signing string "foo bar". Expected result being 19157bfd6eb14e50c2522631eb2dd9f978ecdb90...

Node.js

var crypto = require('crypto');
var hmac = crypto.createHmac(
    'sha1', 
    '647c4c37ce8d84d09c83f836faf97aae722e716a');
hmac.update('foo bar');
var signature = hmac.digest('hex');
console.log(signature);

Java

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.security.Key;
import javax.xml.bind.DatatypeConverter;
...
Mac hmac = Mac.getInstance("HmacSHA1");
Key key = new SecretKeySpec(
    "647c4c37ce8d84d09c83f836faf97aae722e716a".getBytes(),
    "HmacSHA1");
hmac.init(key);
hmac.update("foo bar".getBytes());
String signature = DatatypeConverter.printHexBinary(hmac.doFinal());
signature = signature.toLowerCase();
System.out.println(signature);

csharp

using System;
using System.Security.Cryptography;
using System.Text;
using System.IO;
...
byte[] key = Encoding.ASCII.GetBytes("647c4c37ce8d84d09c83f836faf97aae722e716a");
HMACSHA1 hmac = new HMACSHA1(key);
MemoryStream stream = new MemoryStream(Encoding.ASCII.GetBytes("foo bar"));
string signature = BitConverter.ToString(hmac.ComputeHash(stream))
	.Replace("-", "")
	.ToLower();

Clone this wiki locally