@Test public void translateKeySchemeImpl_NullKey() throws Throwable { assertThrows(SMException.class, () -> { jcesecmod.translateKeySchemeImpl(null, KeyScheme.U); }); }
@Override public SecureDESKey translateKeySchemeImpl (SecureDESKey key, KeyScheme keyScheme) throws SMException { if (key == null) throw new SMException("Missing key to change"); if (keyScheme == null) throw new SMException("Missing desired key schame"); if (keyScheme == key.getScheme()) return key; switch (key.getScheme()) { case Z: throw new SMException("Single length DES key using the variant method" + " can not be converted to any other key"); case U: case T: throw new SMException("DES key using the variant method can not " + "be converted to less secure key using X9.17 method"); case X: if (keyScheme != KeyScheme.U) throw new SMException("Double length key using X9.17 method may be " + "converted only to double length key using variant method"); break; case Y: if (keyScheme != KeyScheme.T) throw new SMException("Triple length key using X9.17 method may be " + "converted only to triple length key using variant method"); break; default: throw new SMException("Change key scheme allowed only for keys" + "using variant method"); } Key clearKey = decryptFromLMK(key); String keyType = getMajorType(key.getKeyType()) + ":" + key.getVariant() + keyScheme; return encryptToLMK(key.getKeyLength(), keyType, clearKey); }
JCESecurityModule extends BaseSMAdapter<SecureDESKey> { @Override public SecureDESKey translateKeySchemeImpl (SecureDESKey key, KeyScheme keyScheme) throws SMException { if (key == null) throw new SMException("Missing key to change"); if (keyScheme == null) throw new SMException("Missing desired key schame"); if (keyScheme == key.getScheme()) return key; switch (key.getScheme()) { case Z: throw new SMException("Single length DES key using the variant method" + " can not be converted to any other key"); case U: case T: throw new SMException("DES key using the variant method can not " + "be converted to less secure key using X9.17 method"); case X: if (keyScheme != KeyScheme.U) throw new SMException("Double length key using X9.17 method may be " + "converted only to double length key using variant method"); break; case Y: if (keyScheme != KeyScheme.T) throw new SMException("Triple length key using X9.17 method may be " + "converted only to triple length key using variant method"); break; default: throw new SMException("Change key scheme allowed only for keys" + "using variant method"); } Key clearKey = decryptFromLMK(key); String keyType = getMajorType(key.getKeyType()) + ":" + key.getVariant() + keyScheme; return encryptToLMK(key.getKeyLength(), keyType, clearKey); } }
JCESecurityModule extends BaseSMAdapter<SecureDESKey> { @Override public SecureDESKey translateKeySchemeImpl (SecureDESKey key, KeyScheme keyScheme) throws SMException { if (key == null) throw new SMException("Missing key to change"); if (keyScheme == null) throw new SMException("Missing desired key schame"); if (keyScheme == key.getScheme()) return key; switch (key.getScheme()) { case Z: throw new SMException("Single length DES key using the variant method" + " can not be converted to any other key"); case U: case T: throw new SMException("DES key using the variant method can not " + "be converted to less secure key using X9.17 method"); case X: if (keyScheme != KeyScheme.U) throw new SMException("Double length key using X9.17 method may be " + "converted only to double length key using variant method"); break; case Y: if (keyScheme != KeyScheme.T) throw new SMException("Triple length key using X9.17 method may be " + "converted only to triple length key using variant method"); break; default: throw new SMException("Change key scheme allowed only for keys" + "using variant method"); } Key clearKey = decryptFromLMK(key); String keyType = getMajorType(key.getKeyType()) + ":" + key.getVariant() + keyScheme; return encryptToLMK(key.getKeyLength(), keyType, clearKey); } JCESecurityModule();  JCESecurityModule(String lmkFile);  JCESecurityModule(String lmkFile, String jceProviderClassName);  JCESecurityModule(Configuration cfg, Logger logger, String realm); }
JCESecurityModule extends BaseSMAdapter<SecureDESKey> { @Override public SecureDESKey translateKeySchemeImpl (SecureDESKey key, KeyScheme keyScheme) throws SMException { if (key == null) throw new SMException("Missing key to change"); if (keyScheme == null) throw new SMException("Missing desired key schame"); if (keyScheme == key.getScheme()) return key; switch (key.getScheme()) { case Z: throw new SMException("Single length DES key using the variant method" + " can not be converted to any other key"); case U: case T: throw new SMException("DES key using the variant method can not " + "be converted to less secure key using X9.17 method"); case X: if (keyScheme != KeyScheme.U) throw new SMException("Double length key using X9.17 method may be " + "converted only to double length key using variant method"); break; case Y: if (keyScheme != KeyScheme.T) throw new SMException("Triple length key using X9.17 method may be " + "converted only to triple length key using variant method"); break; default: throw new SMException("Change key scheme allowed only for keys" + "using variant method"); } Key clearKey = decryptFromLMK(key); String keyType = getMajorType(key.getKeyType()) + ":" + key.getVariant() + keyScheme; return encryptToLMK(key.getKeyLength(), keyType, clearKey); } JCESecurityModule();  JCESecurityModule(String lmkFile);  JCESecurityModule(String lmkFile, String jceProviderClassName);  JCESecurityModule(Configuration cfg, Logger logger, String realm); @Override void setConfiguration(Configuration cfg); @Override SecureDESKey generateKeyImpl(short keyLength, String keyType); @Override SecureDESKey importKeyImpl(short keyLength, String keyType, byte[] encryptedKey,
            SecureDESKey kek, boolean checkParity); @Override byte[] exportKeyImpl(SecureDESKey key, SecureDESKey kek); @Override EncryptedPIN encryptPINImpl(String pin, String accountNumber); @Override String decryptPINImpl(EncryptedPIN pinUnderLmk); @Override EncryptedPIN importPINImpl(EncryptedPIN pinUnderKd1, SecureDESKey kd1); @Override EncryptedPIN exportPINImpl(EncryptedPIN pinUnderLmk, SecureDESKey kd2,
            byte destinationPINBlockFormat); @Override EncryptedPIN generatePINImpl(String accountNumber, int pinLen, List<String> excludes); @Override boolean verifyPVVImpl(EncryptedPIN pinUnderKd1, SecureDESKey kd1, SecureDESKey pvkA,
                             SecureDESKey pvkB, int pvki, String pvv); @Override EncryptedPIN translatePINImpl(EncryptedPIN pinUnderKd1, SecureDESKey kd1,
            SecureDESKey kd2, byte destinationPINBlockFormat); @Override byte[] generateARPCImpl(MKDMethod mkdm, SKDMethod skdm, SecureDESKey imkac
            ,String accountNo, String accntSeqNo, byte[] arqc, byte[] atc, byte[] upn
            ,ARPCMethod arpcMethod, byte[] arc, byte[] propAuthData); @Override 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); @Override byte[] encryptDataImpl(CipherMode cipherMode, SecureDESKey kd
            ,byte[] data, byte[] iv); @Override byte[] decryptDataImpl(CipherMode cipherMode, SecureDESKey kd
            ,byte[] data, byte[] iv); String generateClearKeyComponent(short keyLength); @Override SecureDESKey translateKeySchemeImpl(SecureDESKey key, KeyScheme keyScheme); SecureDESKey formKEYfromThreeClearComponents(
            short keyLength,
            String keyType,
            String clearComponent1HexString,
            String clearComponent2HexString,
            String clearComponent3HexString); @Override SecureDESKey formKEYfromClearComponents(short keyLength, String keyType, String... components); @Override byte[] dataEncrypt(SecureDESKey bdk, byte[] clearText); @Override byte[] dataDecrypt(SecureDESKey bdk, byte[] cypherText); SecureDESKey importBDK(String clearComponent1HexString,
                                  String clearComponent2HexString,
                                  String clearComponent3HexString); EncryptedPIN exportPIN(EncryptedPIN pinUnderLmk, KeySerialNumber ksn, SecureDESKey bdk, boolean tdes,
             byte destinationPINBlockFormat); }
JCESecurityModule extends BaseSMAdapter<SecureDESKey> { @Override public SecureDESKey translateKeySchemeImpl (SecureDESKey key, KeyScheme keyScheme) throws SMException { if (key == null) throw new SMException("Missing key to change"); if (keyScheme == null) throw new SMException("Missing desired key schame"); if (keyScheme == key.getScheme()) return key; switch (key.getScheme()) { case Z: throw new SMException("Single length DES key using the variant method" + " can not be converted to any other key"); case U: case T: throw new SMException("DES key using the variant method can not " + "be converted to less secure key using X9.17 method"); case X: if (keyScheme != KeyScheme.U) throw new SMException("Double length key using X9.17 method may be " + "converted only to double length key using variant method"); break; case Y: if (keyScheme != KeyScheme.T) throw new SMException("Triple length key using X9.17 method may be " + "converted only to triple length key using variant method"); break; default: throw new SMException("Change key scheme allowed only for keys" + "using variant method"); } Key clearKey = decryptFromLMK(key); String keyType = getMajorType(key.getKeyType()) + ":" + key.getVariant() + keyScheme; return encryptToLMK(key.getKeyLength(), keyType, clearKey); } JCESecurityModule();  JCESecurityModule(String lmkFile);  JCESecurityModule(String lmkFile, String jceProviderClassName);  JCESecurityModule(Configuration cfg, Logger logger, String realm); @Override void setConfiguration(Configuration cfg); @Override SecureDESKey generateKeyImpl(short keyLength, String keyType); @Override SecureDESKey importKeyImpl(short keyLength, String keyType, byte[] encryptedKey,
            SecureDESKey kek, boolean checkParity); @Override byte[] exportKeyImpl(SecureDESKey key, SecureDESKey kek); @Override EncryptedPIN encryptPINImpl(String pin, String accountNumber); @Override String decryptPINImpl(EncryptedPIN pinUnderLmk); @Override EncryptedPIN importPINImpl(EncryptedPIN pinUnderKd1, SecureDESKey kd1); @Override EncryptedPIN exportPINImpl(EncryptedPIN pinUnderLmk, SecureDESKey kd2,
            byte destinationPINBlockFormat); @Override EncryptedPIN generatePINImpl(String accountNumber, int pinLen, List<String> excludes); @Override boolean verifyPVVImpl(EncryptedPIN pinUnderKd1, SecureDESKey kd1, SecureDESKey pvkA,
                             SecureDESKey pvkB, int pvki, String pvv); @Override EncryptedPIN translatePINImpl(EncryptedPIN pinUnderKd1, SecureDESKey kd1,
            SecureDESKey kd2, byte destinationPINBlockFormat); @Override byte[] generateARPCImpl(MKDMethod mkdm, SKDMethod skdm, SecureDESKey imkac
            ,String accountNo, String accntSeqNo, byte[] arqc, byte[] atc, byte[] upn
            ,ARPCMethod arpcMethod, byte[] arc, byte[] propAuthData); @Override 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); @Override byte[] encryptDataImpl(CipherMode cipherMode, SecureDESKey kd
            ,byte[] data, byte[] iv); @Override byte[] decryptDataImpl(CipherMode cipherMode, SecureDESKey kd
            ,byte[] data, byte[] iv); String generateClearKeyComponent(short keyLength); @Override SecureDESKey translateKeySchemeImpl(SecureDESKey key, KeyScheme keyScheme); SecureDESKey formKEYfromThreeClearComponents(
            short keyLength,
            String keyType,
            String clearComponent1HexString,
            String clearComponent2HexString,
            String clearComponent3HexString); @Override SecureDESKey formKEYfromClearComponents(short keyLength, String keyType, String... components); @Override byte[] dataEncrypt(SecureDESKey bdk, byte[] clearText); @Override byte[] dataDecrypt(SecureDESKey bdk, byte[] cypherText); SecureDESKey importBDK(String clearComponent1HexString,
                                  String clearComponent2HexString,
                                  String clearComponent3HexString); EncryptedPIN exportPIN(EncryptedPIN pinUnderLmk, KeySerialNumber ksn, SecureDESKey bdk, boolean tdes,
             byte destinationPINBlockFormat);  }