Card Details
GetCard Details
https://base_url/api/v1/card/9893762577829/details
Decrypting an Encrypted String
Prerequisites
Before proceeding with decryption, ensure that you have the following:-
The
encryptedStringto be decrypted (e.g expiryYear, expiryMonth, firstSix, lastFour) from the response. -
The decryption key: To get this key, use the suffix of your source-key after the underscore "_". e.g With a source-key, "TSB_abcdefghijk02", the decryption key will be "abcdefghijk02"
// Example source-key
const source-key = "TSB_abcdefghijk02";
// Split the string by the underscore and get the second part
const decryptionKey = encryptedString.split('_')[1];
// Output the result
console.log(decryptionKey); // Output: abcdefghijk02
- Decrypting the
encryptedStringusingAES-256-CBCalgorithm
const crypto = require('crypto');
/**
* Decrypts an encrypted string using AES-256-CBC algorithm.
*
* @param {string} encryptedData - The encrypted data in hex format.
* @param {string} secretKey - The secret key used for decryption.
* @returns {void} - Outputs the decrypted data to the console.
*/
const decryptString = (encryptedData, sourceKey) => {
try {
// Convert the encrypted data from hex to a Buffer
const encryptedDataBuffer = Buffer.from(encryptedData, 'hex');
// Extract the Initialization Vector (IV) from the first 16 bytes of the encrypted data
const iv = encryptedDataBuffer.subarray(0, 16);
// Extract the actual encrypted text from the remaining bytes
const encryptedText = encryptedDataBuffer.subarray(16);
// Generate a 32-byte key by hashing the secret key using SHA-256
const key = crypto
.createHash('sha256')
.update(String(sourceKey))
.digest('base64')
.substring(0, 32);
// Define the encryption algorithm
const algorithm = 'aes-256-cbc';
// Create a decipher object using the algorithm, key, and IV
const decipher = crypto.createDecipheriv(algorithm, key, iv);
// Decrypt the encrypted text
let decryptedData = decipher.update(encryptedText);
decryptedData = Buffer.concat([decryptedData, decipher.final()]);
// Output the decrypted data as a string
console.log(decryptedData.toString());
} catch (error) {
// Log any errors that occur during decryption
console.error('Decryption error:', error);
} finally {
// Exit the process
process.exit(0);
}
};
decryptString("c708c5ee70b8d2b12170e1c0e15a919adab6470766f064b9f033cf971558195c0a3e2bc1a79cbe8b4f45b5e9c28c16a6", "89959e9bffb78a6488c7c0")
/**
* Decrypts a string using AES-256-CBC encryption.
*
* @param string $encryptedData The encrypted data in hexadecimal format.
* @param string $secretKey The secret key used for decryption.
* @return string The decrypted data.
*/
function decryptString($encryptedData, $sourceKey) {
// Convert the hexadecimal encrypted data to binary
$encryptedBin = hex2bin($encryptedData);
// Extract the initialization vector (IV) from the first 16 bytes of the binary data
$iv = substr($encryptedBin, 0, 16);
// Extract the encrypted text from the remaining bytes
$encryptedText = substr($encryptedBin, 16);
// Generate a 32-byte key by hashing the secret key using SHA-256 and encoding it in base64
$key = substr(base64_encode(hash('sha256', $sourceKey, true)), 0, 32);
// Define the encryption algorithm
$algorithm = "aes-256-cbc";
// Decrypt the data using OpenSSL
$decryptedData = openssl_decrypt($encryptedText, $algorithm, $key, OPENSSL_RAW_DATA, $iv);
// Return the decrypted data
return $decryptedData;
}
echo decryptString("c708c5ee70b8d2b12170e1c0e15a919adab6470766f064b9f033cf971558195c0a3e2bc1a79cbe8b4f45b5e9c28c16a6", "89959e9bffb78a6488c7c0")
?>
| AUTHORIZATION Bearer Token | |
|---|---|
This folder is using Bearer Token from collection Source Bank - radix. | |
Example Request
Card Details
Example Response
200 OK