This is a classic vulnerability found during security testing. A malicious user opens browser DevTools, edits the payment amount from 10000 to 100 in the request payload, and submits it to the PG. The payment goes through at the lower amount.
Any time data flows through a browser before reaching your server, tampering is a real threat. Hecto Financial addresses this with a two-layer security model: encryption to hide sensitive data and hashing to detect tampering. Neither alone is sufficient — you need both.
This article explains how each technique works and how to implement them correctly.
These terms get conflated constantly in the field. They serve distinct purposes.
| Encryption | Hash | |
|---|---|---|
| Purpose | Confidentiality (hide data) | Integrity (detect tampering) |
| Reversible | Yes (two-way) | No (one-way) |
| Analogy | A locked safe | A tamper-evident seal |
| Applied to | Card numbers, account numbers, PII | Order details, payment amounts |
| Algorithm used by Hecto Financial | AES-256/ECB/PKCS5Padding | SHA-256 |
Encryption transforms data into an unreadable form. Only the party that holds the key — the PG — can decrypt it back to the original value.
A hash function maps data to a fixed-length string. Change even a single character of the input, and the output hash changes completely.
Each technique alone has a critical gap:
The two-layer approach closes both gaps: encryption hides the content, hashing prevents substitution.
Use this for sensitive fields like card numbers.
Algorithm: AES-256/ECB/PKCS5Padding
const crypto = require('crypto');
function encryptAES256(text, key) {
// Key must be exactly 32 bytes
const cipher = crypto.createCipheriv('aes-256-ecb', key, null);
cipher.setAutoPadding(true); // PKCS5 padding applied automatically
let encrypted = cipher.update(text, 'utf8', 'base64');
encrypted += cipher.final('base64');
return encrypted;
}
// Example
const secretKey = 'pgSettle30y739r82jtd709yOfZ2yK5K'; // 32 bytes
const cardNum = '1234567812345678';
const encryptedCardNum = encryptAES256(cardNum, secretKey);
console.log('Encrypted card number:', encryptedCardNum);
For pktHash generation, the order of fields is fixed. Do not deviate from it.
function generatePktHash(mchtId, method, mchtTrdNo, trdDt, trdTm, trdAmt, hashKey) {
// Fixed concatenation order (PG credit card payment)
const rawString = mchtId + method + mchtTrdNo + trdDt + trdTm + trdAmt(plaintext) + hashKey;
// SHA-256 hash, hex-encoded (lowercase)
const hash = crypto.createHash('sha256').update(rawString, 'utf8').digest('hex');
return hash;
}
// Example — credit card payment
const mchtId = 'nx_mid_il'; // Merchant ID
const method = 'CARD'; // Payment method
const mchtTrdNo = 'ORDER20231126001'; // Merchant order number
const trdDt = '20231126'; // Transaction date (YYYYMMDD)
const trdTm = '153000'; // Transaction time (HHMMSS)
const trdAmt = '10000'; // Transaction amount (plaintext)
const hashKey = 'ST1009281328226982205'; // Hash authentication key
const pktHash = generatePktHash(mchtId, method, mchtTrdNo, trdDt, trdTm, trdAmt, hashKey);
console.log('Generated pktHash:', pktHash);
Security in payment systems is not optional.
Implement both correctly, and you've protected your customers' data and closed the door on the most common payment tampering attacks.
Need technical support?
Code Samples
HectoFinancial GitHub