我需要将我们的IVR与ATM交换机集成。在这种情况下,IVR需要发送以ISO格式9594-1格式0形成的引脚块(区域引脚密钥-引脚加密)。我们有清除组件-1、2,
下面是一些javascript,它将一个pin加密为Format-0(无PAN)pin块。在本例中,它创建了一个随机DES ZPK(区域引脚键),但如果您愿意,可以使用固定的区域引脚键。它还使用CryptoJS。
(如果你需要,我有一个C#的例子)
_createPinblockFromPin: function(pin) {
var pinBlockString = "1" + pin.length.toString() + pin;
while (pinBlockString.length < 16) {
var r = encoding.b2h((Math.random() * 0x100) & 255);
pinBlockString += r.toString(8).toUpperCase();
}
return pinBlockString;
}
_createZpk: function() {
var key = CryptoJS.enc.Hex.stringify(CryptoJS.lib.WordArray.random(16));
return key.toUpperCase();
}
_encryptPinBlock: function(clearPinBlockHex, zpkHex) {
var clearPinBlock = CryptoJS.enc.Hex.parse(clearPinBlockHex);
var key = CryptoJS.enc.Hex.parse(zpkHex);
key.words[4] = key.words[0];
key.words[5] = key.words[1];
var iv = CryptoJS.lib.WordArray.create(64 / 8);
var options = { iv: iv, mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.NoPadding };
var encrypted = CryptoJS.TripleDES.encrypt(clearPinBlock, key, options);
var encryptedHex = encrypted.toString().toUpperCase();
return encryptedHex;
}
用法是:
var clearPinBlock = this._createPinblockFromPin(pin);
var clearZpk = this._createZpk();
var ePinBlock = this._encryptPinBlock(clearPinBlock, clearZpk);
这是一个使用BouncyCastle.net的c#示例
// create zpk
var keyGenParams = new KeyGenerationParameters(new SecureRandom(), 128);
var keyGen = new DesEdeKeyGenerator();
keyGen.Init(keyGenParams);
var zpk = keyGen.GenerateKey();
System.Diagnostics.Debug.WriteLine($"zpk->{DataFormatter.ToHexString(zpk)}");
// create pinblock
var random = new Random();
var pinString = $"1{pin.Length}{pin}";
while (pinString.Length < 16) pinString += random.Next(0, 9).ToString();
var pinBlock = DataFormatter.HexStringToByteArray(pinString);
System.Diagnostics.Debug.WriteLine($"clearPinBlock->{DataFormatter.ToHexString(pinBlock)}");
// encrypt pinblock
var pinBlockZpk = new byte[8];
var keyParam = new DesEdeParameters(zpk);
var desEngine1 = new DesEdeEngine();
desEngine1.Init(true, keyParam);
desEngine1.ProcessBlock(pinBlock, 0, pinBlockZpk, 0);
System.Diagnostics.Debug.WriteLine($"pinBlockZpk-> {DataFormatter.ToHexString(pinBlockZpk)}");
请注意数据格式。ToHexString()只是一个实用程序,用于将byte[]转换为十六进制字符串以进行诊断。