Class JCESecurityModule
- All Implemented Interfaces:
Configurable, SMAdapter<SecureDESKey>, LogSource
It doesn't require any hardware device to work.
JCESecurityModule also implements the SMAdapter, so you can view it: either
as a self contained security module adapter that doesn't need a security module
or a security module that plugs directly to jpos, so doesn't need
a separate adapter.
It relies on Java(tm) Cryptography Extension (JCE), hence its name.
JCESecurityModule relies on the JCEHandler class to do the low level JCE work.
WARNING: This version of JCESecurityModule is meant for testing purposes and NOT for life operation, since the Local Master Keys are stored in CLEAR on the system's disk. Comming versions of JCESecurity Module will rely on java.security.KeyStore for a better protection of the Local Master Keys.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected JCEHandlerHelper used for raw JCE cipher and key operations.Fields inherited from class BaseSMAdapter
cfg, logger, realmFields inherited from interface SMAdapter
FORMAT00, FORMAT01, FORMAT02, FORMAT03, FORMAT04, FORMAT05, FORMAT34, FORMAT35, FORMAT41, FORMAT42, LENGTH_DES, LENGTH_DES3_2KEY, LENGTH_DES3_3KEY, TYPE_BDK, TYPE_CVK, TYPE_DEK, TYPE_HMAC, TYPE_MK_AC, TYPE_MK_CVC3, TYPE_MK_DAC, TYPE_MK_DN, TYPE_MK_SMC, TYPE_MK_SMI, TYPE_PVK, TYPE_RSA_PK, TYPE_RSA_SK, TYPE_TAK, TYPE_TMK, TYPE_TPK, TYPE_ZAK, TYPE_ZEK, TYPE_ZMK, TYPE_ZPKModifier and TypeFieldDescriptionstatic final byteProprietary PIN Block format.static final bytePIN Block Format adopted by ANSI (ANSI X9.8) and is one of two formats supported by the ISO (ISO 95641 - format 0).static final bytePIN Block Format 02 supports Douctel ATMs.static final bytePIN Block Format 03 is the Diabold Pin Block format.static final bytePIN Block Format 04 is the PIN block format adopted by the PLUS network.static final bytePIN Block Format 05 is the ISO 9564-1 Format 1 PIN Block.static final bytePIN Block Format 34 is the standard EMV PIN block format.static final bytePIN Block Format 35 is the required by Europay/MasterCard for their Pay Now & Pay Later products.static final bytePIN Block Format 41 is the Visa format for PIN change without using the current PIN.static final bytePIN Block Format 42 is the Visa format for PIN change using the current (old) PIN.static final shortDES Key LengthLENGTH_DES= 64.static final shortTriple DES (2 keys)LENGTH_DES3_2KEY= 128.static final shortTriple DES (3 keys)LENGTH_DES3_3KEY= 192.static final StringBDK: Base Derivation Key.static final StringCVK: Card Verification Key.static final StringDEK: Data Encryption Key.static final StringHMAC: Hash Message Authentication Code (with key usage).static final StringMK-AC: Issuer Master Key for generating and verifying Application Cryptograms.static final StringMK-CVC3: Issuer Master Key for generating and verifying Card Verification Code 3 (CVC3).static final StringMK-DAC Issuer Master Key for generating and verifying Data Authentication Codes.static final StringMK-DN: Issuer Master Key for generating and verifying Dynamic Numbers.static final StringMK-SMC: Issuer Master Key for Secure Messaging Confidentiality.static final StringMK-SMI: Issuer Master Key for Secure Messaging Integrity.static final StringPVK: PIN Verification Key.static final StringRSA: Public Key.static final StringRSA: Private Key.static final StringTAK: Terminal Authentication Key.static final StringTMK: Terminal Master Key.static final StringTPK: Terminal PIN Key.static final StringZAK: Zone Authentication Key.static final StringZEK: Zone Encryption Key.static final StringZMK: Zone Master Key is a DES (or Triple-DES) key-encryption key which is distributed manually in order that further keys can be exchanged automatically.static final StringZPK: Zone PIN Key. -
Constructor Summary
ConstructorsConstructorDescriptionCreates an uninitialized JCE Security Module, you need to setConfiguration to initialize itJCESecurityModule(String lmkFile) Creates a JCE Security Module initialised with the given LMK file.JCESecurityModule(String lmkFile, String jceProviderClassName) Constructs a JCE security module backed by the given LMK file and JCE provider.JCESecurityModule(Configuration cfg, Logger logger, String realm) Constructs a JCE security module from aConfiguration, logger, and realm. -
Method Summary
Modifier and TypeMethodDescriptionprotected byte[]calculateARPC(Key skarpc, byte[] arqc, ARPCMethod arpcMethod, byte[] arc, byte[] propAuthData) Calculate ARPC (Application Response Cryptogram).protected byte[]calculateARQC(MKDMethod mkdm, SKDMethod skdm, SecureDESKey imkac, String accountNo, String accntSeqNo, byte[] atc, byte[] upn, byte[] transData) Calculate ARQC (Application Request Cryptogram).protected StringcalculateCAVVImpl(String accountNo, SecureDESKey cvk, String upn, String authrc, String sfarc) Your SMAdapter should override this method if it has this functionalityprotected StringcalculateCVC3(SecureDESKey imkcvc3, String accountNo, String acctSeqNo, byte[] atc, byte[] upn, byte[] data, MKDMethod mkdm) Computes the contactless CVC3 from the issuer master key, ATC, UPN, and track data.protected StringcalculateCVD(String accountNo, Key cvk, String expDate, String serviceCode) Calculates a CVD/CVV from the supplied clear CVK using the Visa algorithm.protected StringcalculateCVDImpl(String accountNo, SecureDESKey cvkA, SecureDESKey cvkB, String expDate, String serviceCode) Your SMAdapter should override this method if it has this functionalityprotected StringcalculateCVV(String accountNo, Key cvk, Date expDate, String serviceCode) Calculates a CVV using the supplied clear CVK and an expiryDateformatted asyyMM.protected StringcalculateCVVImpl(String accountNo, SecureDESKey cvkA, SecureDESKey cvkB, Date expDate, String serviceCode) Your SMAdapter should override this method if it has this functionalityprotected StringcalculatedCVV(String accountNo, SecureDESKey imkac, String expDate, String serviceCode, byte[] atc, MKDMethod mkdm) Computes a dynamic CVV (dCVV) using ATC and an issuer master key.protected byte[]calculateDerivedKey(KeySerialNumber ksn, SecureDESKey bdk, boolean tdes, boolean dataEncryption) Computes the DUKPT-derived working key for the given KSN and BDK.protected byte[]Calculates a key check value over a clear key.protected StringcalculatePIN(byte[] pinBlock, byte pinBlockFormat, String accountNumber) Calculates the clear pin (as entered by card holder on the pin entry device) givin the clear PIN blockprotected byte[]calculatePINBlock(String pin, byte pinBlockFormat, String accountNumber) Calculates the clear PIN Blockprotected StringcalculatePVV(EncryptedPIN pinUnderLmk, Key key, int keyIdx, List<String> excludes) Calculates a 4-digit PVV using the IBM 3624 algorithm.protected StringcalculatePVVImpl(EncryptedPIN pinUnderLmk, SecureDESKey pvkA, SecureDESKey pvkB, int pvkIdx, List<String> excludes) Your SMAdapter should override this method if it has this functionalityprotected StringcalculatePVVImpl(EncryptedPIN pinUnderKd1, SecureDESKey kd1, SecureDESKey pvkA, SecureDESKey pvkB, int pvkIdx, List<String> excludes) Your SMAdapter should override this method if it has this functionalityprotected voidcheckCAVVArgs(String upn, String authrc, String sfarc) Validates the lengths of the CAVV inputs, throwingSMExceptionwith a descriptive message when any value isnullor wrong-sized.protected KeyconcatKeys(SecureDESKey keyA, SecureDESKey keyB) Concatenates two single-length DES keys into a double-length DESede key, decrypting them from the LMK first.byte[]dataDecrypt(SecureDESKey bdk, byte[] cypherText) Decrypt Databyte[]dataEncrypt(SecureDESKey bdk, byte[] clearText) Encrypt Databyte[]decryptDataImpl(CipherMode cipherMode, SecureDESKey kd, byte[] data, byte[] iv) Your SMAdapter should override this method if it has this functionalityprotected KeydecryptFromLMK(SecureDESKey secureDESKey) Decrypts a secure DES key from encryption under LMK.decryptPINImpl(EncryptedPIN pinUnderLmk) Your SMAdapter should override this method if it has this functionalityprotected KeyderiveICCMasterKey(Key imk, byte[] panpsn) Derive ICC Master Key from Issuer Master Key and preformated PAN/PANSeqNo Compute two 8-byte numbers: left part is a result of Triple-DES encryption ofpanpsnwithimkas the key right part is a result of Triple-DES encryption of binary-invertedpanpsnwithimkas the key concatenate left and right parts
Described in EMV v4.2 Book 2, Annex A1.4.1 Master Key Derivation point 2byte[]encryptDataImpl(CipherMode cipherMode, SecureDESKey kd, byte[] data, byte[] iv) Your SMAdapter should override this method if it has this functionalityencryptPINImpl(String pin, String accountNumber) Your SMAdapter should override this method if it has this functionalityprotected EncryptedPINencryptPINImpl(String pin, String accountNumber, SecureDESKey pek) Your SMAdapter should override this method if it has this functionality.protected SecureDESKeyencryptToLMK(short keyLength, String keyType, Key clearDESKey) Encrypts a clear DES Key under LMK to form a SecureKey.byte[]exportKeyImpl(SecureDESKey key, SecureDESKey kek) Your SMAdapter should override this method if it has this functionalityexportPIN(EncryptedPIN pinUnderLmk, KeySerialNumber ksn, SecureDESKey bdk, boolean tdes, byte destinationPINBlockFormat) Exports PIN to DUKPT Encryption.exportPINImpl(EncryptedPIN pinUnderLmk, SecureDESKey kd2, byte destinationPINBlockFormat) Your SMAdapter should override this method if it has this functionalityformKEYfromClearComponents(short keyLength, String keyType, String... components) Forms a key from 3 clear components and returns it encrypted under its corresponding LMK The corresponding LMK is determined from the keyTypeformKEYfromThreeClearComponents(short keyLength, String keyType, String clearComponent1HexString, String clearComponent2HexString, String clearComponent3HexString) Forms a key from 3 clear components and returns it encrypted under its corresponding LMK The corresponding LMK is determined from the keyTypebyte[]generateARPCImpl(MKDMethod mkdm, SKDMethod skdm, SecureDESKey imkac, String accountNo, String accntSeqNo, byte[] arqc, byte[] atc, byte[] upn, ARPCMethod arpcMethod, byte[] arc, byte[] propAuthData) Your SMAdapter should override this method if it has this functionalityprotected byte[]generateCBC_MACImpl(byte[] data, SecureDESKey kd) Generates CBC-MAC (Cipher Block Chaining Message Authentication Code) for some data.generateClearKeyComponent(short keyLength) Generates a random clear key component.protected byte[]generateEDE_MACImpl(byte[] data, SecureDESKey kd) Generates EDE-MAC (Encrypt Decrypt Encrypt Message Authentication Code) for some data.protected byte[]generateKeyCheckValueImpl(SecureDESKey secureDESKey) Generates key check value.generateKeyImpl(short keyLength, String keyType) Your SMAdapter should override this method if it has this functionalitygeneratePINImpl(String accountNumber, int pinLen, List<String> excludes) Your SMAdapter should override this method if it has this functionalityprotected byte[]generateSM_MACImpl(MKDMethod mkdm, SKDMethod skdm, SecureDESKey imksmi, String accountNo, String accntSeqNo, byte[] atc, byte[] arqc, byte[] data) Your SMAdapter should override this method if it has this functionalityimportBDK(String clearComponent1HexString, String clearComponent2HexString, String clearComponent3HexString) Imports a 128-bit BDK assembled from three clear hex-encoded components.importKeyImpl(short keyLength, String keyType, byte[] encryptedKey, SecureDESKey kek, boolean checkParity) Your SMAdapter should override this method if it has this functionalityprotected EncryptedPINimportPINImpl(EncryptedPIN pinUnderDuk, KeySerialNumber ksn, SecureDESKey bdk, boolean tdes) Your SMAdapter should override this method if it has this functionalityimportPINImpl(EncryptedPIN pinUnderKd1, SecureDESKey kd1) Your SMAdapter should override this method if it has this functionalityvoidConfigures a JCESecurityModuleprotected byte[]specialDecrypt(byte[] data, byte[] key) Inverse ofspecialEncrypt(byte[], byte[]).protected byte[]specialEncrypt(byte[] data, byte[] key) DUKPT helper that applies a single- or triple-DES "X9.24" style transform over an 8-byte block.translateKeySchemeImpl(SecureDESKey key, KeyScheme keyScheme) Your SMAdapter should override this method if it has this functionalityprotected org.javatuples.Pair<EncryptedPIN, byte[]> translatePINGenerateSM_MACImpl(MKDMethod mkdm, SKDMethod skdm, PaddingMethod padm, SecureDESKey imksmi, String accountNo, String accntSeqNo, byte[] atc, byte[] arqc, byte[] data, EncryptedPIN currentPIN, EncryptedPIN newPIN, SecureDESKey kd1, SecureDESKey imksmc, SecureDESKey imkac, byte destinationPINBlockFormat) Your SMAdapter should override this method if it has this functionalityprotected EncryptedPINtranslatePINImpl(EncryptedPIN pinUnderDuk, KeySerialNumber ksn, SecureDESKey bdk, SecureDESKey kd2, byte destinationPINBlockFormat, boolean tdes) Translates a DUKPT-encrypted PIN block to a target encryption key, optionally re-formatting the PIN block.translatePINImpl(EncryptedPIN pinUnderKd1, SecureDESKey kd1, SecureDESKey kd2, byte destinationPINBlockFormat) Your SMAdapter should override this method if it has this functionalitybyte[]verifyARQCGenerateARPCImpl(MKDMethod mkdm, SKDMethod skdm, SecureDESKey imkac, String accountNo, String accntSeqNo, byte[] arqc, byte[] atc, byte[] upn, byte[] transData, ARPCMethod arpcMethod, byte[] arc, byte[] propAuthData) Your SMAdapter should override this method if it has this functionalityprotected booleanverifyARQCImpl(MKDMethod mkdm, SKDMethod skdm, SecureDESKey imkac, String accountNo, String accntSeqNo, byte[] arqc, byte[] atc, byte[] upn, byte[] transData) Your SMAdapter should override this method if it has this functionalityprotected booleanverifyCAVVImpl(String accountNo, SecureDESKey cvk, String cavv, String upn, String authrc, String sfarc) Your SMAdapter should override this method if it has this functionalityprotected booleanverifyCVC3Impl(SecureDESKey imkcvc3, String accountNo, String acctSeqNo, byte[] atc, byte[] upn, byte[] data, MKDMethod mkdm, String cvc3) Your SMAdapter should override this method if it has this functionalityprotected booleanverifyCVVImpl(String accountNo, SecureDESKey cvkA, SecureDESKey cvkB, String cvv, String expDate, String serviceCode) Your SMAdapter should override this method if it has this functionalityprotected booleanverifyCVVImpl(String accountNo, SecureDESKey cvkA, SecureDESKey cvkB, String cvv, Date expDate, String serviceCode) Your SMAdapter should override this method if it has this functionalityprotected booleanverifydCVVImpl(String accountNo, SecureDESKey imkac, String dcvv, String expDate, String serviceCode, byte[] atc, MKDMethod mkdm) Your SMAdapter should override this method if it has this functionalityprotected booleanverifydCVVImpl(String accountNo, SecureDESKey imkac, String dcvv, Date expDate, String serviceCode, byte[] atc, MKDMethod mkdm) Your SMAdapter should override this method if it has this functionalitybooleanverifyPVVImpl(EncryptedPIN pinUnderKd1, SecureDESKey kd1, SecureDESKey pvkA, SecureDESKey pvkB, int pvki, String pvv) Your SMAdapter should override this method if it has this functionalityMethods inherited from class BaseSMAdapter
calculateCAVV, calculateCVD, calculateCVV, calculateIBMPINOffset, calculateIBMPINOffset, calculateIBMPINOffset, calculateIBMPINOffset, calculateIBMPINOffsetImpl, calculateIBMPINOffsetImpl, calculatePVV, calculatePVV, calculatePVV, calculatePVV, calculateSignature, calculateSignatureImpl, decryptData, decryptData, decryptDataImpl, decryptPIN, deriveIBMPIN, deriveIBMPINImpl, encryptData, encryptData, encryptDataImpl, encryptPIN, encryptPIN, encryptPIN, eraseOldLMK, eraseOldLMKImpl, exportKey, exportKey, exportKeyImpl, exportPIN, generateARPC, generateCBC_MAC, generateEDE_MAC, generateKey, generateKey, generateKeyCheckValue, generateKeyImpl, generateKeyPair, generateKeyPair, generateKeyPairImpl, generateKeyPairImpl, generatePIN, generatePIN, generateSM_MAC, getLogger, getName, getRealm, getSMAdapter, importKey, importKey, importKeyImpl, importPIN, importPIN, importPIN, importPINImpl, printPIN, printPINImpl, setLogger, setName, translateKeyFromOldLMK, translateKeyFromOldLMK, translateKeyFromOldLMKImpl, translateKeyFromOldLMKImpl, translateKeyScheme, translatePIN, translatePIN, translatePIN, translatePINGenerateSM_MAC, translatePINImpl, verifyARQC, verifyARQCGenerateARPC, verifyCAVV, verifyCVC3, verifyCVD, verifyCVV, verifydCVV, verifydCVV, verifyIBMPINOffset, verifyIBMPINOffsetImpl, verifyPVVModifier and TypeMethodDescriptioncalculateCAVV(String accountNo, SecureDESKey cvk, String upn, String authrc, String sfarc) Calaculate a 3-D Secure CAVV/AAV.calculateCVD(String accountNo, SecureDESKey cvkA, SecureDESKey cvkB, String expDate, String serviceCode) Calaculate a Card Verification Digit (Code/Value).calculateCVV(String accountNo, SecureDESKey cvkA, SecureDESKey cvkB, Date expDate, String serviceCode) Calaculate a Card Verification Code/Value.calculateIBMPINOffset(EncryptedPIN pinUnderLmk, SecureDESKey pvk, String decTab, String pinValData, int minPinLen) Calculate an PIN Offset using the IBM 3624 methodcalculateIBMPINOffset(EncryptedPIN pinUnderLmk, SecureDESKey pvk, String decTab, String pinValData, int minPinLen, List<String> excludes) Calculate an PIN Offset using the IBM 3624 methodcalculateIBMPINOffset(EncryptedPIN pinUnderKd1, SecureDESKey kd1, SecureDESKey pvk, String decTab, String pinValData, int minPinLen) Calculate an PIN Offset using the IBM 3624 method of customer selected PINcalculateIBMPINOffset(EncryptedPIN pinUnderKd1, SecureDESKey kd1, SecureDESKey pvk, String decTab, String pinValData, int minPinLen, List<String> excludes) Calculate an PIN Offset using the IBM 3624 method of customer selected PINprotected StringcalculateIBMPINOffsetImpl(EncryptedPIN pinUnderLmk, SecureDESKey pvk, String decTab, String pinValData, int minPinLen, List<String> excludes) Your SMAdapter should override this method if it has this functionalityprotected StringcalculateIBMPINOffsetImpl(EncryptedPIN pinUnderKd1, SecureDESKey kd1, SecureDESKey pvk, String decTab, String pinValData, int minPinLen, List<String> excludes) Your SMAdapter should override this method if it has this functionalitycalculatePVV(EncryptedPIN pinUnderLMK, SecureDESKey pvkA, SecureDESKey pvkB, int pvkIdx) Calculate PVV (VISA PIN Verification Value of PIN under LMK) with exclude listcalculatePVV(EncryptedPIN pinUnderLMK, SecureDESKey pvkA, SecureDESKey pvkB, int pvkIdx, List<String> excludes) Calculate PVV (VISA PIN Verification Value of PIN under LMK)calculatePVV(EncryptedPIN pinUnderKd1, SecureDESKey kd1, SecureDESKey pvkA, SecureDESKey pvkB, int pvkIdx) Calculate PVV (VISA PIN Verification Value of customer selected PIN)calculatePVV(EncryptedPIN pinUnderKd1, SecureDESKey kd1, SecureDESKey pvkA, SecureDESKey pvkB, int pvkIdx, List<String> excludes) Calculate PVV (VISA PIN Verification Value of customer selected PIN)byte[]calculateSignature(MessageDigest hash, SecureKey privateKey, byte[] data) Calculate signature of Data Block.protected byte[]calculateSignatureImpl(MessageDigest hash, SecureKey privateKey, byte[] data) Your SMAdapter should override this method if it has this functionalitybyte[]decryptData(CipherMode cipherMode, SecureDESKey kd, byte[] data, byte[] iv) Decrypt Data Block.byte[]decryptData(SecureKey privKey, byte[] data, AlgorithmParameterSpec algspec, byte[] iv) Decrypts encrypted Data Block with specified cipher.protected byte[]decryptDataImpl(SecureKey decKey, byte[] data, AlgorithmParameterSpec algspec, byte[] iv) Decrypts Data Block encrypted with assymetric cipher.decryptPIN(EncryptedPIN pinUnderLmk) Decrypts an Encrypted PIN (under LMK).deriveIBMPIN(String accountNo, SecureDESKey pvk, String decTab, String pinValData, int minPinLen, String offset) Derive a PIN Using the IBM 3624 methodprotected EncryptedPINderiveIBMPINImpl(String accountNo, SecureDESKey pvk, String decTab, String pinValData, int minPinLen, String offset) Your SMAdapter should override this method if it has this functionalitybyte[]encryptData(CipherMode cipherMode, SecureDESKey kd, byte[] data, byte[] iv) Encrypt Data Block.byte[]encryptData(SecureKey encKey, byte[] data, AlgorithmParameterSpec algspec, byte[] iv) Encrypts clear Data Block with specified cipher.protected byte[]encryptDataImpl(SecureKey encKey, byte[] data, AlgorithmParameterSpec algspec, byte[] iv) Encrypts clear Data Block with specified cipher.encryptPIN(String pin, String accountNumber) Encrypts a clear pin under LMK.encryptPIN(String pin, String accountNumber, boolean extract) Encrypts a clear pin under LMK.encryptPIN(String pin, String accountNumber, SecureDESKey pek) Encrypts a clear PIN under PEK.voidErase the key change storage area of memory It is recommended that this command is used after keys stored by the Host have been translated from old to new LMKs.protected voidErase the key change storage area of memory It is recommended that this command is used after keys stored by the Host have been translated from old to new LMKs.byte[]exportKey(SecureDESKey key, SecureDESKey kek) Exports secure key to encryption under a KEK (Key-Encrypting Key).exportKey(SecureKey kek, SecureKey key, SecureKeySpec keySpec) Exports secure key to encryption under a KEK (Key-Encrypting Key).protected SecureKeyexportKeyImpl(SecureKey kek, SecureKey key, SecureKeySpec keySpec) Your SMAdapter should override this method if it has this functionality.exportPIN(EncryptedPIN pinUnderLmk, SecureDESKey kd2, byte destinationPINBlockFormat) Exports a PIN from encryption under LMK to encryption under a KD (Data Key).byte[]generateARPC(MKDMethod mkdm, SKDMethod skdm, SecureDESKey imkac, String accoutNo, String acctSeqNo, byte[] arqc, byte[] atc, byte[] upn, ARPCMethod arpcMethod, byte[] arc, byte[] propAuthData) Genarate Authorisation Response Cryptogram (ARPC)byte[]generateCBC_MAC(byte[] data, SecureDESKey kd) Generates CBC-MAC (Cipher Block Chaining Message Authentication Code) for some data.byte[]generateEDE_MAC(byte[] data, SecureDESKey kd) Generates EDE-MAC (Encrypt Decrypt Encrypt Message Message Authentication Code) for some data.generateKey(short keyLength, String keyType) Generates a random DES Key.generateKey(SecureKeySpec keySpec) Generates a random Key.byte[]Generates key check value.protected SecureKeygenerateKeyImpl(SecureKeySpec keySpec) Your SMAdapter should override this method if it has this functionality.org.javatuples.Pair<PublicKey, SecurePrivateKey> Generate a public/private key pair.generateKeyPair(SecureKeySpec keySpec) Generate a public/private key pair.protected org.javatuples.Pair<PublicKey, SecurePrivateKey> Your SMAdapter should override this method if it has this functionalitygenerateKeyPairImpl(SecureKeySpec keySpec) Your SMAdapter should override this method if it has this functionality.generatePIN(String accountNumber, int pinLen) Generate random pin under LMKgeneratePIN(String accountNumber, int pinLen, List<String> excludes) Generate random pin under LMK with exclude listbyte[]generateSM_MAC(MKDMethod mkdm, SKDMethod skdm, SecureDESKey imksmi, String accountNo, String acctSeqNo, byte[] atc, byte[] arqc, byte[] data) Generate Secure Message MAC over suppiled message dataReturns the Logger associated with this source.getName()Returns the registered name of this SMAdapter.getRealm()Returns the log realm associated with this source.static SMAdaptergetSMAdapter(String name) Looks up a registered SMAdapter by name from the NameRegistrar.importKey(short keyLength, String keyType, byte[] encryptedKey, SecureDESKey kek, boolean checkParity) Imports a key from encryption under a KEK (Key-Encrypting Key) to protection under the security module.importKey(SecureKey kek, SecureKey key, SecureKeySpec keySpec, boolean checkParity) Imports a key from encryption under a KEK (Key-Encrypting Key) to protection under the security module.protected SecureKeyimportKeyImpl(SecureKey kek, SecureKey key, SecureKeySpec keySpec, boolean checkParity) Your SMAdapter should override this method if it has this functionality.importPIN(EncryptedPIN pinUnderDuk, KeySerialNumber ksn, SecureDESKey bdk) Imports a PIN from encryption under a transaction key to encryption under LMK.importPIN(EncryptedPIN pinUnderDuk, KeySerialNumber ksn, SecureDESKey bdk, boolean tdes) Imports a PIN from encryption under a transaction key to encryption under LMK.importPIN(EncryptedPIN pinUnderKd1, SecureDESKey kd1) Imports a PIN from encryption under KD (Data Key) to encryption under LMK.protected EncryptedPINimportPINImpl(EncryptedPIN pinUnderDuk, KeySerialNumber ksn, SecureDESKey bdk) Deprecated.voidprintPIN(String accountNo, EncryptedPIN pinUnderKd1, SecureDESKey kd1, String template, Map<String, String> fields) Print PIN or PIN and solicitation data to the HSM configured printer.protected voidprintPINImpl(String accountNo, EncryptedPIN pinUnderKd1, SecureDESKey kd1, String template, Map<String, String> fields) Your SMAdapter should override this method if it has this functionalityvoidAttaches aLoggerand realm to this log source.voidassociates this SMAdapter with a name using NameRegistrarTranslate key from encryption under the LMK held in key change storage to encryption under a new LMK.translateKeyFromOldLMK(SecureKey key, SecureKeySpec keySpec) Translate key from encryption under the LMK held in key change storage to encryption under a new LMK.protected SecureDESKeyTranslate key from encryption under the LMK held in key change storage to encryption under a new LMK.protected SecureKeytranslateKeyFromOldLMKImpl(SecureKey key, SecureKeySpec keySpec) Your SMAdapter should override this method if it has this functionality.translateKeyScheme(SecureDESKey key, KeyScheme destKeyScheme) Translate Key Scheme to more secure encription.translatePIN(EncryptedPIN pinUnderDuk, KeySerialNumber ksn, SecureDESKey bdk, SecureDESKey kd2, byte destinationPINBlockFormat) Translates a PIN from encryption under a transaction key to encryption under a KD (Data Key).translatePIN(EncryptedPIN pinUnderDuk, KeySerialNumber ksn, SecureDESKey bdk, SecureDESKey kd2, byte destinationPINBlockFormat, boolean tdes) Translates a PIN from encryption under a transaction key to encryption under a KD (Data Key).translatePIN(EncryptedPIN pinUnderKd1, SecureDESKey kd1, SecureDESKey kd2, byte destinationPINBlockFormat) Translates a PIN from encrytion under KD1 to encryption under KD2.org.javatuples.Pair<EncryptedPIN, byte[]> translatePINGenerateSM_MAC(MKDMethod mkdm, SKDMethod skdm, PaddingMethod padm, SecureDESKey imksmi, String accountNo, String acctSeqNo, byte[] atc, byte[] arqc, byte[] data, EncryptedPIN currentPIN, EncryptedPIN newPIN, SecureDESKey kd1, SecureDESKey imksmc, SecureDESKey imkac, byte destinationPINBlockFormat) Translate PIN and generate MAC over suppiled message dataprotected EncryptedPINtranslatePINImpl(EncryptedPIN pinUnderDuk, KeySerialNumber ksn, SecureDESKey bdk, SecureDESKey kd2, byte destinationPINBlockFormat) Deprecated.booleanverifyARQC(MKDMethod mkdm, SKDMethod skdm, SecureDESKey imkac, String accoutNo, String acctSeqNo, byte[] arqc, byte[] atc, byte[] upn, byte[] txnData) Verify Application Cryptogram (ARQC or TC/AAC) Authorization Request Cryptogram (ARQC) - Online authorization Transaction certificate (TC) - Offline approval Application Authentication Cryptogram (AAC) - Offline declinebyte[]verifyARQCGenerateARPC(MKDMethod mkdm, SKDMethod skdm, SecureDESKey imkac, String accoutNo, String acctSeqNo, byte[] arqc, byte[] atc, byte[] upn, byte[] txnData, ARPCMethod arpcMethod, byte[] arc, byte[] propAuthData) Verify Application Cryptogram (ARQC or TC/AAC) and Genarate Authorisation Response Cryptogram (ARPC) Authorization Request Cryptogram (ARQC) - Online authorization Transaction certificate (TC) - Offline approval Application Authentication Cryptogram (AAC) - Offline declinebooleanverifyCAVV(String accountNo, SecureDESKey cvk, String cavv, String upn, String authrc, String sfarc) Verify a 3-D Secure CAVV/AAV.booleanverifyCVC3(SecureDESKey imkcvc3, String accountNo, String acctSeqNo, byte[] atc, byte[] upn, byte[] data, MKDMethod mkdm, String cvc3) Verify a Dynamic Card Verification Code 3 (CVC3)booleanverifyCVD(String accountNo, SecureDESKey cvkA, SecureDESKey cvkB, String cvv, String expDate, String serviceCode) Verify a Card Verification Digit (Code/Value).booleanverifyCVV(String accountNo, SecureDESKey cvkA, SecureDESKey cvkB, String cvv, Date expDate, String serviceCode) Verify a Card Verification Code/Value.booleanverifydCVV(String accountNo, SecureDESKey imkac, String dcvv, String expDate, String serviceCode, byte[] atc, MKDMethod mkdm) Verify a Dynamic Card Verification Value (dCVV).booleanverifydCVV(String accountNo, SecureDESKey imkac, String dcvv, Date expDate, String serviceCode, byte[] atc, MKDMethod mkdm) Verify a Dynamic Card Verification Value (dCVV).booleanverifyIBMPINOffset(EncryptedPIN pinUnderKd1, SecureDESKey kd1, SecureDESKey pvk, String offset, String decTab, String pinValData, int minPinLen) Verify an PIN Offset using the IBM 3624 methodprotected booleanverifyIBMPINOffsetImpl(EncryptedPIN pinUnderKd, SecureDESKey kd, SecureDESKey pvk, String offset, String decTab, String pinValData, int minPinLen) Your SMAdapter should override this method if it has this functionalitybooleanverifyPVV(EncryptedPIN pinUnderKd1, SecureDESKey kd1, SecureDESKey pvkA, SecureDESKey pvkB, int pvki, String pvv) Verify PVV (VISA PIN Verification Value of an LMK encrypted PIN)
-
Field Details
-
jceHandler
Helper used for raw JCE cipher and key operations.
-
-
Constructor Details
-
JCESecurityModule
public JCESecurityModule()Creates an uninitialized JCE Security Module, you need to setConfiguration to initialize it -
JCESecurityModule
Creates a JCE Security Module initialised with the given LMK file.- Parameters:
lmkFile- Local Master Keys filename of the JCE Security Module- Throws:
SMException- on initialisation failure
-
JCESecurityModule
Constructs a JCE security module backed by the given LMK file and JCE provider.- Parameters:
lmkFile- path to the Local Master Keys filejceProviderClassName- fully qualified JCE provider class name- Throws:
SMException- if initialization fails
-
JCESecurityModule
public JCESecurityModule(Configuration cfg, Logger logger, String realm) throws ConfigurationException Constructs a JCE security module from aConfiguration, logger, and realm.- Parameters:
cfg- configuration to apply (seesetConfiguration(Configuration))logger- logger to bindrealm- logger realm- Throws:
ConfigurationException- if the configuration is invalid
-
-
Method Details
-
setConfiguration
Configures a JCESecurityModule- Specified by:
setConfigurationin interfaceConfigurable- Overrides:
setConfigurationin classBaseSMAdapter<SecureDESKey>- Parameters:
cfg- The following properties are read:
lmk: Local Master Keys file (The only required parameter)
jce: JCE Provider Class Name, if not provided, it defaults to: com.sun.crypto.provider.SunJCE
rebuildlmk: (true/false), rebuilds the Local Master Keys file with new keys (WARNING: old keys will be erased)
cbc-mac: Cipher Block Chaining MAC algorithm name for given JCE Provider.
Default is ISO9797ALG3MACWITHISO7816-4PADDING from BouncyCastle provider (known as Retail-MAC)
that is suitable for most of interfaces with double length MAC key
ANSI X9.19 aka ISO/IEC 9797-1 MAC algorithm 3 padding method 2 - ISO7816
ede-mac: Encrypt Decrypt Encrypt MAC algorithm name for given JCE Provider.
Default is DESEDEMAC from BouncyCastle provider
that is suitable for BASE24 with double length MAC key
ANSI X9.19- Throws:
ConfigurationException- if configuration is invalid
-
generateKeyImpl
Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
generateKeyImplin classBaseSMAdapter<SecureDESKey>- Parameters:
keyLength- requested key lengthkeyType- requested key type- Returns:
- generated key
- Throws:
SMException- on security module error
-
importKeyImpl
public SecureDESKey importKeyImpl(short keyLength, String keyType, byte[] encryptedKey, SecureDESKey kek, boolean checkParity) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
importKeyImplin classBaseSMAdapter<SecureDESKey>- Parameters:
keyLength- requested key lengthkeyType- requested key typeencryptedKey- encrypted key byteskek- key-encrypting keycheckParity- whether to check DES key parity- Returns:
- imported key
- Throws:
SMException- on security module error
-
exportKeyImpl
Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
exportKeyImplin classBaseSMAdapter<SecureDESKey>- Parameters:
key- secure keykek- key-encrypting key- Returns:
- exported key
- Throws:
SMException- on security module error
-
encryptPINImpl
Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
encryptPINImplin classBaseSMAdapter<SecureDESKey>- Parameters:
pin- clear PIN valueaccountNumber- account number associated with the PIN block- Returns:
- encrypted PIN under LMK
- Throws:
SMException- on security module error
-
encryptPINImpl
protected EncryptedPIN encryptPINImpl(String pin, String accountNumber, SecureDESKey pek) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality.- Overrides:
encryptPINImplin classBaseSMAdapter<SecureDESKey>- Parameters:
pin- clear PIN valueaccountNumber- account number associated with the PIN blockpek- PIN-encrypting key- Returns:
- encrypted PIN under PEK.
- Throws:
SMException- on security module error
-
decryptPINImpl
Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
decryptPINImplin classBaseSMAdapter<SecureDESKey>- Parameters:
pinUnderLmk- PIN block encrypted under the LMK- Returns:
- clear pin as entered by card holder
- Throws:
SMException- on security module error
-
importPINImpl
Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
importPINImplin classBaseSMAdapter<SecureDESKey>- Parameters:
pinUnderKd1- PIN block encrypted under the source keykd1- source key- Returns:
- imported pin
- Throws:
SMException- on security module error
-
exportPINImpl
public EncryptedPIN exportPINImpl(EncryptedPIN pinUnderLmk, SecureDESKey kd2, byte destinationPINBlockFormat) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
exportPINImplin classBaseSMAdapter<SecureDESKey>- Parameters:
pinUnderLmk- PIN block encrypted under the LMKkd2- destination keydestinationPINBlockFormat- destination PIN block format- Returns:
- exported pin
- Throws:
SMException- on security module error
-
generatePINImpl
public EncryptedPIN generatePINImpl(String accountNumber, int pinLen, List<String> excludes) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
generatePINImplin classBaseSMAdapter<SecureDESKey>- Parameters:
accountNumber- account number associated with the PIN blockpinLen- requested PIN lengthexcludes- PIN values to reject- Returns:
- generated PIN under LMK
- Throws:
SMException- on security module error
-
concatKeys
Concatenates two single-length DES keys into a double-length DESede key, decrypting them from the LMK first. If either non-null input is already longer than single-length, decrypts and returns that key.- Parameters:
keyA- first secured key, may benullkeyB- second secured key, may benull- Returns:
- a clear-text DES/DESede key, or
nullif both inputs arenull - Throws:
SMException- if key decryption or assembly fails
-
calculateCVV
protected String calculateCVV(String accountNo, Key cvk, Date expDate, String serviceCode) throws SMException Calculates a CVV using the supplied clear CVK and an expiryDateformatted asyyMM.- Parameters:
accountNo- cardholder primary account numbercvk- clear CVKexpDate- expiry dateserviceCode- 3-digit service code- Returns:
- the 3-digit CVV
- Throws:
SMException- if the cipher operation fails
-
calculateCVD
protected String calculateCVD(String accountNo, Key cvk, String expDate, String serviceCode) throws SMException Calculates a CVD/CVV from the supplied clear CVK using the Visa algorithm.- Parameters:
accountNo- cardholder primary account numbercvk- clear CVKexpDate- expiry date asyyMMserviceCode- 3-digit service code- Returns:
- the 3-digit CVD/CVV
- Throws:
SMException- if the cipher operation fails
-
calculateCVVImpl
protected String calculateCVVImpl(String accountNo, SecureDESKey cvkA, SecureDESKey cvkB, Date expDate, String serviceCode) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
calculateCVVImplin classBaseSMAdapter<SecureDESKey>- Parameters:
accountNo- card account numbercvkA- first card verification keycvkB- second card verification keyexpDate- card expiration dateserviceCode- card service code- Returns:
- Card Verification Code/Value
- Throws:
SMException- on security module error
-
calculateCVDImpl
protected String calculateCVDImpl(String accountNo, SecureDESKey cvkA, SecureDESKey cvkB, String expDate, String serviceCode) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
calculateCVDImplin classBaseSMAdapter<SecureDESKey>- Parameters:
accountNo- card account numbercvkA- first card verification keycvkB- second card verification keyexpDate- card expiration dateserviceCode- card service code- Returns:
- Card Verification Digit (Code/Value)
- Throws:
SMException- on security module error
-
checkCAVVArgs
Validates the lengths of the CAVV inputs, throwingSMExceptionwith a descriptive message when any value isnullor wrong-sized.- Parameters:
upn- 4-digit unpredictable numberauthrc- 1-character authorization result codesfarc- 2-character second-factor authorization result code- Throws:
SMException- if any argument isnullor has the wrong length
-
calculateCAVVImpl
protected String calculateCAVVImpl(String accountNo, SecureDESKey cvk, String upn, String authrc, String sfarc) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
calculateCAVVImplin classBaseSMAdapter<SecureDESKey>- Parameters:
accountNo- card account numbercvk- card verification keyupn- unpredictable numberauthrc- authorization response codesfarc- second-factor authorization response code- Returns:
- Cardholder Authentication Verification Value
- Throws:
SMException- on security module error
-
verifyCVVImpl
protected boolean verifyCVVImpl(String accountNo, SecureDESKey cvkA, SecureDESKey cvkB, String cvv, Date expDate, String serviceCode) throws SMException Your SMAdapter should override this method if it has this functionality- Overrides:
verifyCVVImplin classBaseSMAdapter<SecureDESKey>- Parameters:
accountNo- card account numbercvkA- first card verification keycvkB- second card verification keycvv- card verification valueexpDate- card expiration dateserviceCode- card service code- Returns:
- true if CVV/CVC is falid or false if not
- Throws:
SMException- on security module error
-
verifyCVVImpl
protected boolean verifyCVVImpl(String accountNo, SecureDESKey cvkA, SecureDESKey cvkB, String cvv, String expDate, String serviceCode) throws SMException Your SMAdapter should override this method if it has this functionality- Overrides:
verifyCVVImplin classBaseSMAdapter<SecureDESKey>- Parameters:
accountNo- card account numbercvkA- first card verification keycvkB- second card verification keycvv- card verification valueexpDate- card expiration dateserviceCode- card service code- Returns:
trueif CVV/CVC is valid orfalseotherwise- Throws:
SMException- on security module error
-
verifyCAVVImpl
protected boolean verifyCAVVImpl(String accountNo, SecureDESKey cvk, String cavv, String upn, String authrc, String sfarc) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
verifyCAVVImplin classBaseSMAdapter<SecureDESKey>- Parameters:
accountNo- card account numbercvk- card verification keycavv- cardholder authentication verification valueupn- unpredictable numberauthrc- authorization response codesfarc- second-factor authorization response code- Returns:
- Cardholder Authentication Verification Value
- Throws:
SMException- on security module error
-
calculatedCVV
protected String calculatedCVV(String accountNo, SecureDESKey imkac, String expDate, String serviceCode, byte[] atc, MKDMethod mkdm) throws SMException Computes a dynamic CVV (dCVV) using ATC and an issuer master key.- Parameters:
accountNo- cardholder primary account numberimkac- issuer master key for AC, encrypted under the LMKexpDate- expiry date asyyMMserviceCode- 3-digit service codeatc- application transaction countermkdm- master-key derivation method (defaults toMKDMethod.OPTION_A)- Returns:
- the calculated dCVV
- Throws:
SMException- if key derivation or computation fails
-
verifydCVVImpl
protected boolean verifydCVVImpl(String accountNo, SecureDESKey imkac, String dcvv, Date expDate, String serviceCode, byte[] atc, MKDMethod mkdm) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
verifydCVVImplin classBaseSMAdapter<SecureDESKey>- Parameters:
accountNo- card account numberimkac- issuer master key for application cryptogramsdcvv- dynamic card verification valueexpDate- card expiration dateserviceCode- card service codeatc- application transaction countermkdm- master-key derivation method- Returns:
- true if dcvv is valid false if not
- Throws:
SMException- on security module error
-
verifydCVVImpl
protected boolean verifydCVVImpl(String accountNo, SecureDESKey imkac, String dcvv, String expDate, String serviceCode, byte[] atc, MKDMethod mkdm) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
verifydCVVImplin classBaseSMAdapter<SecureDESKey>- Parameters:
accountNo- card account numberimkac- issuer master key for application cryptogramsdcvv- dynamic card verification valueexpDate- card expiration dateserviceCode- card service codeatc- application transaction countermkdm- master-key derivation method- Returns:
- true if dcvv is valid false if not
- Throws:
SMException- on security module error
-
calculateCVC3
protected String calculateCVC3(SecureDESKey imkcvc3, String accountNo, String acctSeqNo, byte[] atc, byte[] upn, byte[] data, MKDMethod mkdm) throws SMException Computes the contactless CVC3 from the issuer master key, ATC, UPN, and track data.- Parameters:
imkcvc3- issuer master key for CVC3, encrypted under the LMKaccountNo- cardholder primary account numberacctSeqNo- PAN sequence number, ornullatc- application transaction counterupn- unpredictable numberdata- IVCVC3 seed (or 2 bytes pre-computed IVCVC3)mkdm- master-key derivation method (defaults toMKDMethod.OPTION_A)- Returns:
- the 5-digit CVC3
- Throws:
SMException- if key derivation or computation fails
-
verifyCVC3Impl
protected boolean verifyCVC3Impl(SecureDESKey imkcvc3, String accountNo, String acctSeqNo, byte[] atc, byte[] upn, byte[] data, MKDMethod mkdm, String cvc3) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
verifyCVC3Implin classBaseSMAdapter<SecureDESKey>- Parameters:
imkcvc3- issuer master key for CVC3accountNo- card account numberacctSeqNo- PAN sequence numberatc- application transaction counterupn- unpredictable numberdata- input datamkdm- master-key derivation methodcvc3- card validation code 3- Returns:
- true if cvc3 is valid false if not
- Throws:
SMException- on security module error
-
deriveICCMasterKey
Derive ICC Master Key from Issuer Master Key and preformated PAN/PANSeqNo Compute two 8-byte numbers:- left part is a result of Triple-DES encryption of
panpsnwithimkas the key - right part is a result of Triple-DES encryption of binary-inverted
panpsnwithimkas the key - concatenate left and right parts
Described in EMV v4.2 Book 2, Annex A1.4.1 Master Key Derivation point 2- Parameters:
imk- 16-bytes Issuer Master Keypanpsn- preformated PAN and PAN Sequence Number- Returns:
- derived 16-bytes ICC Master Key with adjusted DES parity
- Throws:
JCEHandlerException- on cryptographic failure
- left part is a result of Triple-DES encryption of
-
calculatePVV
protected String calculatePVV(EncryptedPIN pinUnderLmk, Key key, int keyIdx, List<String> excludes) throws SMException Calculates a 4-digit PVV using the IBM 3624 algorithm.- Parameters:
pinUnderLmk- PIN block encrypted under the LMKkey- clear PVV keykeyIdx- PVV key index (only the low decimal digit is used)excludes- optional list of PINs to reject before computing the PVV- Returns:
- the 4-digit PVV
- Throws:
SMException- if the PIN is on the excludes list or computation fails
-
calculatePVVImpl
protected String calculatePVVImpl(EncryptedPIN pinUnderLmk, SecureDESKey pvkA, SecureDESKey pvkB, int pvkIdx, List<String> excludes) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
calculatePVVImplin classBaseSMAdapter<SecureDESKey>- Parameters:
pinUnderLmk- PIN block encrypted under the LMKpvkA- first PIN verification keypvkB- second PIN verification keypvkIdx- PIN verification key indexexcludes- PIN values to reject- Returns:
- PVV (VISA PIN Verification Value)
- Throws:
SMException- on security module error
-
calculatePVVImpl
protected String calculatePVVImpl(EncryptedPIN pinUnderKd1, SecureDESKey kd1, SecureDESKey pvkA, SecureDESKey pvkB, int pvkIdx, List<String> excludes) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
calculatePVVImplin classBaseSMAdapter<SecureDESKey>- Parameters:
pinUnderKd1- PIN block encrypted under the source keykd1- source keypvkA- first PIN verification keypvkB- second PIN verification keypvkIdx- PIN verification key indexexcludes- PIN values to reject- Returns:
- PVV (VISA PIN Verification Value)
- Throws:
SMException- on security module error
-
verifyPVVImpl
public boolean verifyPVVImpl(EncryptedPIN pinUnderKd1, SecureDESKey kd1, SecureDESKey pvkA, SecureDESKey pvkB, int pvki, String pvv) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
verifyPVVImplin classBaseSMAdapter<SecureDESKey>- Parameters:
pinUnderKd1- PIN block encrypted under the keykd1- secure keypvkA- first PIN verification keypvkB- second PIN verification keypvki- PIN verification key indexpvv- PIN verification value- Returns:
- true if pin is valid false if not
- Throws:
SMException- on security module error
-
translatePINImpl
public EncryptedPIN translatePINImpl(EncryptedPIN pinUnderKd1, SecureDESKey kd1, SecureDESKey kd2, byte destinationPINBlockFormat) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
translatePINImplin classBaseSMAdapter<SecureDESKey>- Parameters:
pinUnderKd1- PIN block encrypted under the source keykd1- source keykd2- destination keydestinationPINBlockFormat- destination PIN block format- Returns:
- translated pin
- Throws:
SMException- on security module error
-
calculateARQC
protected byte[] calculateARQC(MKDMethod mkdm, SKDMethod skdm, SecureDESKey imkac, String accountNo, String accntSeqNo, byte[] atc, byte[] upn, byte[] transData) throws SMException Calculate ARQC (Application Request Cryptogram).Entry point e.g. for simulator systems.
- Parameters:
mkdm- Master Key Derivation Methodskdm- Session Key Derivation Methodimkac- Issuer Master Key for Application CryptogramaccountNo- account numberaccntSeqNo- account sequence numberatc- Application Transaction Counterupn- Unpredictable NumbertransData- transaction data- Returns:
- computed ARQC bytes
- Throws:
SMException- on cryptographic failure
-
verifyARQCImpl
protected boolean verifyARQCImpl(MKDMethod mkdm, SKDMethod skdm, SecureDESKey imkac, String accountNo, String accntSeqNo, byte[] arqc, byte[] atc, byte[] upn, byte[] transData) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
verifyARQCImplin classBaseSMAdapter<SecureDESKey>- Parameters:
mkdm- master-key derivation methodskdm- session-key derivation methodimkac- issuer master key for application cryptogramsaccountNo- card account numberaccntSeqNo- PAN sequence numberarqc- application request cryptogramatc- application transaction counterupn- unpredictable numbertransData- transaction data- Returns:
- true if ARQC/TC/AAC is valid or false if not
- Throws:
SMException- on security module error
-
generateARPCImpl
public byte[] generateARPCImpl(MKDMethod mkdm, SKDMethod skdm, SecureDESKey imkac, String accountNo, String accntSeqNo, byte[] arqc, byte[] atc, byte[] upn, ARPCMethod arpcMethod, byte[] arc, byte[] propAuthData) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
generateARPCImplin classBaseSMAdapter<SecureDESKey>- Parameters:
mkdm- master-key derivation methodskdm- session-key derivation methodimkac- issuer master key for application cryptogramsaccountNo- card account numberaccntSeqNo- PAN sequence numberarqc- application request cryptogramatc- application transaction counterupn- unpredictable numberarpcMethod- ARPC generation methodarc- authorization response codepropAuthData- proprietary authentication data- Returns:
- calculated ARPC
- Throws:
SMException- on security module error
-
verifyARQCGenerateARPCImpl
public byte[] verifyARQCGenerateARPCImpl(MKDMethod mkdm, SKDMethod skdm, SecureDESKey imkac, String accountNo, String accntSeqNo, byte[] arqc, byte[] atc, byte[] upn, byte[] transData, ARPCMethod arpcMethod, byte[] arc, byte[] propAuthData) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
verifyARQCGenerateARPCImplin classBaseSMAdapter<SecureDESKey>- Parameters:
mkdm- master-key derivation methodskdm- session-key derivation methodimkac- issuer master key for application cryptogramsaccountNo- card account numberaccntSeqNo- PAN sequence numberarqc- application request cryptogramatc- application transaction counterupn- unpredictable numbertransData- transaction dataarpcMethod- ARPC generation methodarc- authorization response codepropAuthData- proprietary authentication data- Returns:
- calculated ARPC
- Throws:
SMException- on security module error
-
calculateARPC
protected byte[] calculateARPC(Key skarpc, byte[] arqc, ARPCMethod arpcMethod, byte[] arc, byte[] propAuthData) throws SMException Calculate ARPC (Application Response Cryptogram).Entry point e.g. for simulator systems.
- Parameters:
skarpc- Session Key for ARPC computationarqc- Application Request CryptogramarpcMethod- ARPC generation methodarc- Authorization Response CodepropAuthData- proprietary authentication data (may benull)- Returns:
- computed ARPC bytes
- Throws:
SMException- on cryptographic failure
-
generateSM_MACImpl
protected byte[] generateSM_MACImpl(MKDMethod mkdm, SKDMethod skdm, SecureDESKey imksmi, String accountNo, String accntSeqNo, byte[] atc, byte[] arqc, byte[] data) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
generateSM_MACImplin classBaseSMAdapter<SecureDESKey>- Parameters:
mkdm- master-key derivation methodskdm- session-key derivation methodimksmi- issuer master key for secure messaging integrityaccountNo- card account numberaccntSeqNo- PAN sequence numberatc- application transaction counterarqc- application request cryptogramdata- input data- Returns:
- generated 8 bytes MAC
- Throws:
SMException- on security module error
-
translatePINGenerateSM_MACImpl
protected org.javatuples.Pair<EncryptedPIN, byte[]> translatePINGenerateSM_MACImpl(MKDMethod mkdm, SKDMethod skdm, PaddingMethod padm, SecureDESKey imksmi, String accountNo, String accntSeqNo, byte[] atc, byte[] arqc, byte[] data, EncryptedPIN currentPIN, EncryptedPIN newPIN, SecureDESKey kd1, SecureDESKey imksmc, SecureDESKey imkac, byte destinationPINBlockFormat) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
translatePINGenerateSM_MACImplin classBaseSMAdapter<SecureDESKey>- Parameters:
mkdm- master-key derivation methodskdm- session-key derivation methodpadm- proprietary authentication data methodimksmi- issuer master key for secure messaging integrityaccountNo- card account numberaccntSeqNo- PAN sequence numberatc- application transaction counterarqc- application request cryptogramdata- input datacurrentPIN- current PIN valuenewPIN- replacement PIN valuekd1- source keyimksmc- issuer master key for secure messaging confidentialityimkac- issuer master key for application cryptogramsdestinationPINBlockFormat- destination PIN block format- Returns:
- Pair of values, encrypted PIN and 8 bytes MAC
- Throws:
SMException- on security module error
-
encryptDataImpl
public byte[] encryptDataImpl(CipherMode cipherMode, SecureDESKey kd, byte[] data, byte[] iv) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
encryptDataImplin classBaseSMAdapter<SecureDESKey>- Parameters:
cipherMode- cipher modekd- secure keydata- input dataiv- initialization vector- Returns:
- encrypted data
- Throws:
SMException- on security module error
-
decryptDataImpl
public byte[] decryptDataImpl(CipherMode cipherMode, SecureDESKey kd, byte[] data, byte[] iv) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
decryptDataImplin classBaseSMAdapter<SecureDESKey>- Parameters:
cipherMode- cipher modekd- secure keydata- input dataiv- initialization vector- Returns:
- decrypted data
- Throws:
SMException- on security module error
-
generateCBC_MACImpl
Generates CBC-MAC (Cipher Block Chaining Message Authentication Code) for some data.- Overrides:
generateCBC_MACImplin classBaseSMAdapter<SecureDESKey>- Parameters:
data- the data to be MACedkd- the key used for MACing- Returns:
- generated CBC-MAC bytes
- Throws:
SMException- on MAC computation failure
-
generateEDE_MACImpl
Generates EDE-MAC (Encrypt Decrypt Encrypt Message Authentication Code) for some data.- Overrides:
generateEDE_MACImplin classBaseSMAdapter<SecureDESKey>- Parameters:
data- the data to be MACedkd- the key used for MACing- Returns:
- generated EDE-MAC bytes
- Throws:
SMException- on MAC computation failure
-
generateClearKeyComponent
Generates a random clear key component.- Parameters:
keyLength- the desired key length (e.g. LENGTH_DES, LENGTH_DES3_2KEY)- Returns:
- clear key component as a hex string
- Throws:
SMException- on key generation failure
-
generateKeyCheckValueImpl
Generates key check value.- Overrides:
generateKeyCheckValueImplin classBaseSMAdapter<SecureDESKey>- Parameters:
secureDESKey- SecureDESKey with untrusted or fake Key Check Value- Returns:
- generated Key Check Value
- Throws:
SMException- on cryptographic failure
-
translateKeySchemeImpl
public SecureDESKey translateKeySchemeImpl(SecureDESKey key, KeyScheme keyScheme) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
translateKeySchemeImplin classBaseSMAdapter<SecureDESKey>- Parameters:
key- secure keykeyScheme- destination key scheme- Returns:
- translated key with
destKeySchemescheme - Throws:
SMException- on security module error
-
formKEYfromThreeClearComponents
public SecureDESKey formKEYfromThreeClearComponents(short keyLength, String keyType, String clearComponent1HexString, String clearComponent2HexString, String clearComponent3HexString) throws SMException Forms a key from 3 clear components and returns it encrypted under its corresponding LMK The corresponding LMK is determined from the keyType- Parameters:
keyLength- e.g. LENGTH_DES, LENGTH_DES3_2, LENGTH_DES3_3, ..keyType- possible values are those defined in the SecurityModule interface, e.g. ZMK, TMKclearComponent1HexString- HexString containing the first componentclearComponent2HexString- HexString containing the second componentclearComponent3HexString- HexString containing the third component- Returns:
- SecureDESKey formed from the three clear components
- Throws:
SMException- on key formation failure
-
formKEYfromClearComponents
public SecureDESKey formKEYfromClearComponents(short keyLength, String keyType, String... components) throws SMException Description copied from interface:SMAdapterForms a key from 3 clear components and returns it encrypted under its corresponding LMK The corresponding LMK is determined from the keyType- Specified by:
formKEYfromClearComponentsin interfaceSMAdapter<SecureDESKey>- Overrides:
formKEYfromClearComponentsin classBaseSMAdapter<SecureDESKey>- Parameters:
keyLength- e.g. LENGTH_DES, LENGTH_DES3_2, LENGTH_DES3_3, ..keyType- possible values are those defined in the SecurityModule inteface. e.g., ZMK, TMK,...components- up to three HexStrings containing key components- Returns:
- forms an SecureDESKey from two clear components
- Throws:
SMException- on security module error
-
calculateKeyCheckValue
Calculates a key check value over a clear key.- Parameters:
key- the clear key- Returns:
- the key check value
- Throws:
SMException- on error
-
encryptToLMK
protected SecureDESKey encryptToLMK(short keyLength, String keyType, Key clearDESKey) throws SMException Encrypts a clear DES Key under LMK to form a SecureKey.- Parameters:
keyLength- the key length (e.g. LENGTH_DES, LENGTH_DES3_2KEY)keyType- the key type as defined in SMAdapter (e.g. ZMK, TMK)clearDESKey- the clear DES key to encrypt- Returns:
- secureDESKey the key encrypted under LMK
- Throws:
SMException- on encryption failure
-
decryptFromLMK
Decrypts a secure DES key from encryption under LMK.- Parameters:
secureDESKey- key encrypted under LMK- Returns:
- clear key
- Throws:
SMException- on decryption failure
-
calculatePINBlock
protected byte[] calculatePINBlock(String pin, byte pinBlockFormat, String accountNumber) throws SMException Calculates the clear PIN Block- Parameters:
pin- as entered by the card holder on the PIN entry devicepinBlockFormat- the PIN block format identifieraccountNumber- (the 12 right-most digits of the account number excluding the check digit)- Returns:
- The clear PIN Block
- Throws:
SMException- on invalid PIN or format error
-
calculatePIN
protected String calculatePIN(byte[] pinBlock, byte pinBlockFormat, String accountNumber) throws SMException Calculates the clear pin (as entered by card holder on the pin entry device) givin the clear PIN block- Parameters:
pinBlock- clear PIN BlockpinBlockFormat- the PIN block format identifieraccountNumber- the 12 right-most digits of the account number- Returns:
- the pin
- Throws:
SMException- on invalid PIN block or format error
-
specialEncrypt
DUKPT helper that applies a single- or triple-DES "X9.24" style transform over an 8-byte block. For an 8-byte key the operation isdata = (data XOR key) | encrypt | XOR key; for a 16-byte key it is the standard EDE3 transform.- Parameters:
data- 8-byte input blockkey- single- or double-length DES key- Returns:
- the transformed 8-byte block
- Throws:
JCEHandlerException- on cipher failure
-
specialDecrypt
Inverse ofspecialEncrypt(byte[], byte[]).- Parameters:
data- 8-byte input blockkey- single- or double-length DES key- Returns:
- the transformed 8-byte block
- Throws:
JCEHandlerException- on cipher failure
-
dataEncrypt
Description copied from interface:SMAdapterEncrypt Data- Specified by:
dataEncryptin interfaceSMAdapter<SecureDESKey>- Overrides:
dataEncryptin classBaseSMAdapter<SecureDESKey>- Parameters:
bdk- base derivation keyclearText- clear Text- Returns:
- cyphertext
- Throws:
SMException- on security module error
-
dataDecrypt
Description copied from interface:SMAdapterDecrypt Data- Specified by:
dataDecryptin interfaceSMAdapter<SecureDESKey>- Overrides:
dataDecryptin classBaseSMAdapter<SecureDESKey>- Parameters:
bdk- base derivation keycypherText- clear Text- Returns:
- cleartext
- Throws:
SMException- on security module error
-
calculateDerivedKey
protected byte[] calculateDerivedKey(KeySerialNumber ksn, SecureDESKey bdk, boolean tdes, boolean dataEncryption) throws SMException Computes the DUKPT-derived working key for the given KSN and BDK.- Parameters:
ksn- key serial numberbdk- base derivation key, encrypted under the LMKtdes- iftrue, use the triple-DES variant; otherwise single-DESdataEncryption-truewhen deriving a data-encryption variant key- Returns:
- the derived working key bytes
- Throws:
SMException- if derivation fails
-
importBDK
public SecureDESKey importBDK(String clearComponent1HexString, String clearComponent2HexString, String clearComponent3HexString) throws SMException Imports a 128-bit BDK assembled from three clear hex-encoded components.- Parameters:
clearComponent1HexString- first hex componentclearComponent2HexString- second hex componentclearComponent3HexString- third hex component- Returns:
- the secured BDK encrypted under the LMK
- Throws:
SMException- if any component is malformed or assembly fails
-
translatePINImpl
protected EncryptedPIN translatePINImpl(EncryptedPIN pinUnderDuk, KeySerialNumber ksn, SecureDESKey bdk, SecureDESKey kd2, byte destinationPINBlockFormat, boolean tdes) throws SMException Translates a DUKPT-encrypted PIN block to a target encryption key, optionally re-formatting the PIN block.- Overrides:
translatePINImplin classBaseSMAdapter<SecureDESKey>- Parameters:
pinUnderDuk- PIN block encrypted under a derived DUKPT keyksn- key serial number used to derive the source keybdk- base derivation key, encrypted under the LMKkd2- destination key, encrypted under the LMKdestinationPINBlockFormat- target PIN block formattdes- iftrue, derive using triple-DES- Returns:
- the PIN re-encrypted under
kd2 - Throws:
SMException- if derivation, decryption, or re-encryption fails
-
importPINImpl
protected EncryptedPIN importPINImpl(EncryptedPIN pinUnderDuk, KeySerialNumber ksn, SecureDESKey bdk, boolean tdes) throws SMException Description copied from class:BaseSMAdapterYour SMAdapter should override this method if it has this functionality- Overrides:
importPINImplin classBaseSMAdapter<SecureDESKey>- Parameters:
pinUnderDuk- PIN block encrypted under a DUKPT-derived keyksn- key serial numberbdk- base derivation keytdes- whether to use triple-DES DUKPT derivation- Returns:
- imported pin
- Throws:
SMException- on security module error
-
exportPIN
public EncryptedPIN exportPIN(EncryptedPIN pinUnderLmk, KeySerialNumber ksn, SecureDESKey bdk, boolean tdes, byte destinationPINBlockFormat) throws SMException Exports PIN to DUKPT Encryption.- Parameters:
pinUnderLmk- PIN block encrypted under the LMKksn- key serial number used to derive the working keybdk- base derivation key, encrypted under the LMKtdes- iftrue, derive using triple-DESdestinationPINBlockFormat- target PIN block format- Returns:
- The encrypted pin
- Throws:
SMException- if derivation, decryption, or re-encryption fails
-