Skip to main content

Signature Generation

Signature digunakan untuk proses autentikasi request yang di kirimkan ke QRIS MPM. SpeedCash menggunakan 2 type signature Asymmetric Without Token dan Asymmertic with token untuk proses mengambil token B2B diperlukan Asymmetric Without Token dan untuk autentikasi service lainya menggunakan Asymmertic with token

Rumus Signature Without Token

stringToSign = client_ID + "|" + X-TIMESTAMP
signature = SHA256withRSA (Private_Key, stringToSign)

Source Code Pembuatan Signature Asymetric without token

<?php
$clientId = 'your_client_id';
$timestamp = 'your_timestamp';

// Construct the string to sign
$stringToSign = $clientId . '|' . $timestamp;

// Load your private key (assuming it's in PEM format)
$privateKey = openssl_pkey_get_private('file://path/to/your/private_key.pem');

// Create a signature
$signature = '';
openssl_sign($stringToSign, $signature, $privateKey, OPENSSL_ALGO_SHA256);

// Encode the signature in base64
$base64Signature = base64_encode($signature);

echo "your signature : $base64Signature";
?>

Rumus Signature with Token

stringToSign = HTTPMethod +”:“+ pathUrl +":"+ AccessToken +":“+ Lowercase(HexEncode(SHA- 256(minify(RequestBody))))+ ":“ +  X- TIMESTAMP
signature = HMAC_SHA512(clientSecret, stringToSign)

Source Code Pembuatan Signature Asymetric with token

<?php
$dateTime = new DateTime();
$dateTime->setTimezone(new DateTimeZone('Asia/Jakarta'));
$timeStamp = $dateTime->format(DateTime::ATOM);

// accessToken bisa di isi dari yang di dapatkan di service token B2B
$accessToken = "6223e366-6bb6-4486-8ada-dc3831ad9204";

//clientSecret bisa di isi dari yang sudah di kirim lewat email
$clientSecret = '42f0e4ae-0158-4218-8e8b-e5d804a6bd24';

// endpoinUrl bisa di isi sesuai dengan path dari servicenya
$endPointUrl = '/v1.0/registration-account-creation';

//request body bisa di isi payload sesuai dengan servicenya
$requestBody = [
"originalReferenceNo" => "5188671",
"merchantId" => "1212667",
"serviceCode" => "47",
];

$body = json_encode($requestBody, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$sha256Hash = hash('sha256', $body, true);

$hexEncode = strtolower(bin2hex($sha256Hash));
$stringToSign = "POST:{$endPointUrl}:{$accessToken}:{$hexEncode}:{$timeStamp}";
$stringToSignUtf8 = mb_convert_encoding($stringToSign, 'UTF-8');
$hmac = hash_hmac('sha512', $stringToSignUtf8, $clientSecret, true);
$genHmac = base64_encode($hmac);

print_r($genHmac);