public IPinGenerationResponse TranslatePinFromBdkToZpkEncryption(string bdk, string zpk, string keySerialNumber, string pinBlock, string accountNumber) { if (string.IsNullOrEmpty(bdk)) { throw new ArgumentNullException("bdk"); } if (string.IsNullOrEmpty(zpk)) { throw new ArgumentNullException("zpk"); } if (string.IsNullOrEmpty(keySerialNumber)) { throw new ArgumentNullException("keySerialNumber"); } if (string.IsNullOrEmpty(accountNumber)) { throw new ArgumentNullException("accountNumber"); } if (accountNumber.Length > 18) { throw new ArgumentException("accountNumber is longer than 12-digits"); } string keyDescriptor = "605"; //"002"; //configure Parameters var parameters = new List <string>() { bdk, zpk, keyDescriptor, keySerialNumber, pinBlock, ((int)PinBlockFormats.ANSI).ToString().PadLeft(2, '0'), ((int)PinBlockFormats.ANSI).ToString().PadLeft(2, '0'), accountNumber.PadLeft(12, '0') }; //configure Response Format var responseFormat = new MessageFields(); responseFormat.Fields.Add(new MessageField() { Name = "encryptedPin", Length = 18 }); // the first digit should not be used // _theHsm._encryptedPinLength }); var hsmResponse = _theHsm.Send("G0", parameters, responseFormat); IPinGenerationResponse response = new PinGeneratorResponse(); response.EncryptedPin = hsmResponse.Item("encryptedPin").Substring(2); return(response); }
public IPinGenerationResponse TranslatePinFromOneZPKEncryptionToAnother(string SourceZPK, string DestinationZPK, string SourcePinBlock, PinBlockFormats pinBlockFormat, string accountNumber) { if (string.IsNullOrEmpty(SourceZPK)) { throw new ArgumentNullException("pinEncryptionKey"); } if (string.IsNullOrEmpty(accountNumber)) { throw new ArgumentNullException("accountNumber"); } if (string.IsNullOrEmpty(DestinationZPK)) { throw new ArgumentNullException("zpk is empty"); } if (string.IsNullOrEmpty(SourcePinBlock)) { throw new ArgumentNullException("Source Pin Block is empty"); } if (accountNumber.Length > 12) { throw new ArgumentException("accountNumber is longer than 12-digits"); } //configure Parameters var parameters = new List <string>() { SourceZPK, DestinationZPK, "12", SourcePinBlock, ((int)pinBlockFormat).ToString().PadLeft(2, '0'), ((int)pinBlockFormat).ToString().PadLeft(2, '0'), accountNumber.PadLeft(12, '0'), }; //configure Response Format var responseFormat = new MessageFields(); responseFormat.Fields.Add(new MessageField() { Name = "encryptedPin", Length = 18 }); var hsmResponse = _theHsm.Send("CC", parameters, responseFormat); IPinGenerationResponse response = new PinGeneratorResponse(); response.EncryptedPin = hsmResponse.Item("encryptedPin").Substring(0, 16); return(response); }
public IPinGenerationResponse TranslatePinFromEncryptionUnderInterchangeKeyToLMKEncryption(string zpk, string EncryptedPin, PinBlockFormats pinBlockFormat, string accountNumber) { if (string.IsNullOrEmpty(EncryptedPin)) { throw new ArgumentNullException("pinEncryptionKey"); } if (string.IsNullOrEmpty(accountNumber)) { throw new ArgumentNullException("accountNumber"); } if (string.IsNullOrEmpty(zpk)) { throw new ArgumentNullException("zpk is empty"); } if (accountNumber.Length > 12) { throw new ArgumentException("accountNumber is longer than 12-digits"); } //configure Parameters var parameters = new List <string>() { zpk, EncryptedPin, ((int)pinBlockFormat).ToString().PadLeft(2, '0'), accountNumber.PadLeft(12, '0'), }; //configure Response Format var responseFormat = new MessageFields(); responseFormat.Fields.Add(new MessageField() { Name = "encryptedPin", Length = _theHsm._encryptedPinLength }); var hsmResponse = _theHsm.Send("JE", parameters, responseFormat); IPinGenerationResponse response = new PinGeneratorResponse(); response.EncryptedPin = hsmResponse.Item("encryptedPin"); return(response); }
public IPinGenerationResponse DeriveEncryptedPin(string pan) { if (string.IsNullOrEmpty(pan)) { throw new ArgumentNullException("accountNumber"); } if (pan.Length < 16) { throw new ArgumentException("accountNumber is longer than 12-digits"); } string accountNumber = pan.Substring(pan.Length - 13, 12); //configure Parameters var parameters = new List <string>() { PinConfigurationManager.HsmConfig.PinVerificationKeyPVV, "0000FFFFFFFF", //Default Pin offset "04", //minPinLength.ToString().PadLeft(2,'0'), accountNumber.PadLeft(12, '0'), PinConfigurationManager.HsmConfig.DecimalisationTable, "P", //PinConfigurationManager.HsmConfig.PinValidationData pan.Length == 19 ? pan.PadRight(20, 'F') : pan }; //configure Response Format var responseFormat = new MessageFields(); responseFormat.Fields.Add(new MessageField() { Name = "encryptedPin", Length = _theHsm._encryptedPinLength }); var hsmResponse = _theHsm.Send("EE", parameters, responseFormat); IPinGenerationResponse response = new PinGeneratorResponse(); response.EncryptedPin = hsmResponse.Item("encryptedPin"); return(response); }
public IPinGenerationResponse EncryptClearPin(string clearPin, string accountNumber) { if (string.IsNullOrEmpty(clearPin)) { throw new ArgumentNullException("clearPin"); } if (string.IsNullOrEmpty(accountNumber)) { throw new ArgumentNullException("accountNumber"); } if (accountNumber.Length > 12) { throw new ArgumentException("accountNumber is longer than 12-digits"); } //configure Parameters var parameters = new List <string>() { clearPin.PadRight(_theHsm._encryptedPinLength, 'F'), accountNumber.PadLeft(12, '0') }; //configure Response Format var responseFormat = new MessageFields(); responseFormat.Fields.Add(new MessageField() { Name = "encryptedPin", Length = _theHsm._encryptedPinLength }); var hsmResponse = _theHsm.Send("BA", parameters, responseFormat); IPinGenerationResponse response = new PinGeneratorResponse(); response.EncryptedPin = hsmResponse.Item("encryptedPin"); return(response); }
public IPinGenerationResponse GenerateRandomPin(string accountNumber, int?pinLength) { if (string.IsNullOrEmpty(accountNumber)) { throw new ArgumentNullException("accountNumber"); } if (accountNumber.Length > 12) { throw new ArgumentException("accountNumber is longer than 12-digits"); } //configure Parameters var parameters = new List <string>() { accountNumber.PadLeft(12, '0') }; if (pinLength.HasValue) { parameters.Add(pinLength.Value.ToString().PadLeft(2, '0')); } //configure Response Format var responseFormat = new MessageFields(); responseFormat.Fields.Add(new MessageField() { Name = "encryptedPin", Length = _theHsm._encryptedPinLength }); var hsmResponse = _theHsm.Send("JA", parameters, responseFormat); IPinGenerationResponse response = new PinGeneratorResponse(); response.EncryptedPin = hsmResponse.Item("encryptedPin"); return(response); }