@Test public void testEncryptDESKeyThrowsNullPointerException() throws Throwable { byte[] bytes = new byte[1]; Key encryptingKey = new SecretKeySpec(bytes, "testJCEHandlerParam2"); try { new JCEHandler((Provider) null).encryptDESKey((short) 100, null, encryptingKey); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { if (isJavaVersionAtMost(JAVA_14)) { assertNull(ex.getMessage(), "ex.getMessage()"); } else { assertEquals("Cannot invoke \"java.security.Key.getAlgorithm()\" because \"clearDESKey\" is null", ex.getMessage(), "ex.getMessage()"); } assertEquals("testJCEHandlerParam2", encryptingKey.getAlgorithm(), "(SecretKeySpec) encryptingKey.getAlgorithm()"); } }
public byte[] encryptDESKey(short keyLength, Key clearDESKey, Key encryptingKey) throws JCEHandlerException { byte[] clearKeyBytes = extractDESKeyMaterial(keyLength, clearDESKey); Util.adjustDESParity(clearKeyBytes); return doCryptStuff(clearKeyBytes, encryptingKey, Cipher.ENCRYPT_MODE); }
JCEHandler { public byte[] encryptDESKey(short keyLength, Key clearDESKey, Key encryptingKey) throws JCEHandlerException { byte[] clearKeyBytes = extractDESKeyMaterial(keyLength, clearDESKey); Util.adjustDESParity(clearKeyBytes); return doCryptStuff(clearKeyBytes, encryptingKey, Cipher.ENCRYPT_MODE); } }
JCEHandler { public byte[] encryptDESKey(short keyLength, Key clearDESKey, Key encryptingKey) throws JCEHandlerException { byte[] clearKeyBytes = extractDESKeyMaterial(keyLength, clearDESKey); Util.adjustDESParity(clearKeyBytes); return doCryptStuff(clearKeyBytes, encryptingKey, Cipher.ENCRYPT_MODE); } JCEHandler(String jceProviderClassName);  JCEHandler(Provider provider); }
JCEHandler { public byte[] encryptDESKey(short keyLength, Key clearDESKey, Key encryptingKey) throws JCEHandlerException { byte[] clearKeyBytes = extractDESKeyMaterial(keyLength, clearDESKey); Util.adjustDESParity(clearKeyBytes); return doCryptStuff(clearKeyBytes, encryptingKey, Cipher.ENCRYPT_MODE); } JCEHandler(String jceProviderClassName);  JCEHandler(Provider provider); Key generateDESKey(short keyLength); byte[] encryptDESKey(short keyLength, Key clearDESKey, Key encryptingKey); Key decryptDESKey(short keyLength, byte[] encryptedDESKey, Key encryptingKey, boolean checkParity); byte[] encryptData(byte[] data, Key key); byte[] decryptData(byte[] encryptedData, Key key); byte[] encryptDataCBC(byte[] data, Key key, byte[] iv); byte[] decryptDataCBC(byte[] encryptedData, Key key, byte[] iv); byte[] generateMAC(byte[] data, Key kd, String macAlgorithm); }
JCEHandler { public byte[] encryptDESKey(short keyLength, Key clearDESKey, Key encryptingKey) throws JCEHandlerException { byte[] clearKeyBytes = extractDESKeyMaterial(keyLength, clearDESKey); Util.adjustDESParity(clearKeyBytes); return doCryptStuff(clearKeyBytes, encryptingKey, Cipher.ENCRYPT_MODE); } JCEHandler(String jceProviderClassName);  JCEHandler(Provider provider); Key generateDESKey(short keyLength); byte[] encryptDESKey(short keyLength, Key clearDESKey, Key encryptingKey); Key decryptDESKey(short keyLength, byte[] encryptedDESKey, Key encryptingKey, boolean checkParity); byte[] encryptData(byte[] data, Key key); byte[] decryptData(byte[] encryptedData, Key key); byte[] encryptDataCBC(byte[] data, Key key, byte[] iv); byte[] decryptDataCBC(byte[] encryptedData, Key key, byte[] iv); byte[] generateMAC(byte[] data, Key kd, String macAlgorithm);  }