fix(payment): align AES calls with upstream v11 operation signatures

The v11 sync changed the AESEncrypt/AESDecrypt operation argument
layouts (purely additive):
  - AESDecrypt inserted 'ivLength' at args[2] and appended 'ivFromInput'
    at args[8].
  - AESEncrypt appended 'Include IV in output' at args[6].

PaymentDataCipher still passed the old positional layout, so AESDecrypt
read args[7].string off undefined, erroring the 4 Payment Decrypt/
Re-Encrypt tests. Realign both call sites; pass ivFromInput/includeIV
'Off' to preserve the prior behaviour (IV supplied explicitly, never
sliced from or prepended to the data).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
J8k3 2026-06-15 08:30:39 -04:00
parent 1045fcc3c5
commit 514c97c5b2

View File

@ -91,13 +91,15 @@ function encryptPaymentData(inputHex, profile, keyHex, ivHex, ksn, dukptVariant)
if (profile.startsWith("AES ")) { if (profile.startsWith("AES ")) {
const aes = new AESEncrypt(); const aes = new AESEncrypt();
const mode = profile.substring(4); const mode = profile.substring(4);
// AESEncrypt args: [key, iv, mode, inputType, outputType, AAD, includeIV]
ciphertextHex = aes.run(plaintextHex, [ ciphertextHex = aes.run(plaintextHex, [
{ string: effectiveKeyHex, option: "Hex" }, { string: effectiveKeyHex, option: "Hex" },
{ string: normalizedIv, option: "Hex" }, { string: normalizedIv, option: "Hex" },
mode, mode,
"Hex", "Hex",
"Hex", "Hex",
{ string: "", option: "Hex" } { string: "", option: "Hex" },
"Off"
]).toUpperCase(); ]).toUpperCase();
} else { } else {
const tdes = new TripleDESEncrypt(); const tdes = new TripleDESEncrypt();
@ -140,14 +142,18 @@ function decryptPaymentData(inputHex, profile, keyHex, ivHex, ksn, dukptVariant)
if (profile.startsWith("AES ")) { if (profile.startsWith("AES ")) {
const aes = new AESDecrypt(); const aes = new AESDecrypt();
const mode = profile.substring(4); const mode = profile.substring(4);
// AESDecrypt args: [key, iv, ivLength, mode, inputType, outputType, GCM tag, AAD, ivFromInput].
// ivLength is unused here because the IV is supplied explicitly (ivFromInput "Off").
plaintextHex = aes.run(ciphertextHex, [ plaintextHex = aes.run(ciphertextHex, [
{ string: effectiveKeyHex, option: "Hex" }, { string: effectiveKeyHex, option: "Hex" },
{ string: normalizedIv, option: "Hex" }, { string: normalizedIv, option: "Hex" },
16,
mode, mode,
"Hex", "Hex",
"Hex", "Hex",
{ string: "", option: "Hex" }, { string: "", option: "Hex" },
{ string: "", option: "Hex" } { string: "", option: "Hex" },
"Off"
]).toUpperCase(); ]).toUpperCase();
} else { } else {
const tdes = new TripleDESDecrypt(); const tdes = new TripleDESDecrypt();