Skip to main content

Signature Validation

Partner wajib melakukan validasi pada request callback yang kami kirimkan

Public Key

Dalam validasi signature callback partner memerlukan public key milik speedcash pada prosesnya. Untuk production akan dikirimkan via email dengan format tertentu.

Rumus Signature

Signature pada validasi callback mengambil data pada header request yang dikirimkan speedcash.


stringToSign = HTTPMethod +":"+ EndpointUrl +":"+ Lowercase(HexEncode(SHA-256(minify(RequestBody)))) + ":" + TimeStamp
signature = base64_decode(SHA256withRSA(private_key, stringToSign))

Source Code Validasi Signature Callback

$path = '/v1.0/debit/notify';
$timestamp = ''; //ambil dari header X-TIMESTAMP
$signature = ''; //ambil dari header X-SIGNATURE
$httpMethod = 'POST';
$partnerId = ''; //ambil dari header X-PARTNER-ID
$body = '' // ambil dari body payload

$payload = json_encode($body, JSON_UNESCAPED_SLASHES);

$stringToSignArr = [
$httpMethod,
$path,
strtolower(bin2hex(hash('sha256', $payload, true))),
$timestamp
];

$stringToSign = implode(':', $stringToSignArr);

try {
$publicKey = openssl_get_publickey($publicKey);
$verify = openssl_verify($stringToSign, base64_decode($signature), $publicKey, OPENSSL_ALGO_SHA256);

if($verify !== 1){
$response = [
'message' => 'Cannot verify signature'
];

print_r($response);
} else {
$response = [
'responseCode' => '2005600',
'responseMessage' => 'Successful'
];

print_r($response);
}


} catch(Exception $e) {
$response = [
'message' => 'Invalid signature {'.$e->getMessage().'}'
];

print_r($response);
}