@Test public void testGenerateDESKeyThrowsJCEHandlerException2() throws Throwable { try { new JCEHandler((Provider) null).generateDESKey((short) 65); fail("Expected JCEHandlerException to be thrown"); } catch (JCEHandlerException ex) { if (isJavaVersionAtMost(JAVA_14)) { assertEquals("java.lang.NullPointerException", ex.getMessage(), "ex.getMessage()"); assertNull(ex.getNested().getMessage(), "ex.getNested().getMessage()"); } else { assertEquals("java.lang.NullPointerException: Cannot invoke \"java.security.Provider.getName()\" because \"this.provider\" is null", ex.getMessage(), "ex.getMessage()"); assertEquals("Cannot invoke \"java.security.Provider.getName()\" because \"this.provider\" is null", ex.getNested().getMessage(), "ex.getNested().getMessage()"); } } }
public Key generateDESKey(short keyLength) throws JCEHandlerException { Key generatedClearKey = null; try { KeyGenerator k1; if (keyLength > SMAdapter.LENGTH_DES) { k1 = KeyGenerator.getInstance(ALG_TRIPLE_DES, provider.getName()); } else { k1 = KeyGenerator.getInstance(ALG_DES, provider.getName()); } generatedClearKey = k1.generateKey(); byte[] clearKeyBytes = extractDESKeyMaterial(keyLength, generatedClearKey); Util.adjustDESParity(clearKeyBytes); generatedClearKey = formDESKey(keyLength, clearKeyBytes); } catch (Exception e) { if (e instanceof JCEHandlerException) throw (JCEHandlerException) e; else throw new JCEHandlerException(e); } return generatedClearKey; }
JCEHandler { public Key generateDESKey(short keyLength) throws JCEHandlerException { Key generatedClearKey = null; try { KeyGenerator k1; if (keyLength > SMAdapter.LENGTH_DES) { k1 = KeyGenerator.getInstance(ALG_TRIPLE_DES, provider.getName()); } else { k1 = KeyGenerator.getInstance(ALG_DES, provider.getName()); } generatedClearKey = k1.generateKey(); byte[] clearKeyBytes = extractDESKeyMaterial(keyLength, generatedClearKey); Util.adjustDESParity(clearKeyBytes); generatedClearKey = formDESKey(keyLength, clearKeyBytes); } catch (Exception e) { if (e instanceof JCEHandlerException) throw (JCEHandlerException) e; else throw new JCEHandlerException(e); } return generatedClearKey; } }
JCEHandler { public Key generateDESKey(short keyLength) throws JCEHandlerException { Key generatedClearKey = null; try { KeyGenerator k1; if (keyLength > SMAdapter.LENGTH_DES) { k1 = KeyGenerator.getInstance(ALG_TRIPLE_DES, provider.getName()); } else { k1 = KeyGenerator.getInstance(ALG_DES, provider.getName()); } generatedClearKey = k1.generateKey(); byte[] clearKeyBytes = extractDESKeyMaterial(keyLength, generatedClearKey); Util.adjustDESParity(clearKeyBytes); generatedClearKey = formDESKey(keyLength, clearKeyBytes); } catch (Exception e) { if (e instanceof JCEHandlerException) throw (JCEHandlerException) e; else throw new JCEHandlerException(e); } return generatedClearKey; } JCEHandler(String jceProviderClassName);  JCEHandler(Provider provider); }
JCEHandler { public Key generateDESKey(short keyLength) throws JCEHandlerException { Key generatedClearKey = null; try { KeyGenerator k1; if (keyLength > SMAdapter.LENGTH_DES) { k1 = KeyGenerator.getInstance(ALG_TRIPLE_DES, provider.getName()); } else { k1 = KeyGenerator.getInstance(ALG_DES, provider.getName()); } generatedClearKey = k1.generateKey(); byte[] clearKeyBytes = extractDESKeyMaterial(keyLength, generatedClearKey); Util.adjustDESParity(clearKeyBytes); generatedClearKey = formDESKey(keyLength, clearKeyBytes); } catch (Exception e) { if (e instanceof JCEHandlerException) throw (JCEHandlerException) e; else throw new JCEHandlerException(e); } return generatedClearKey; } 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 Key generateDESKey(short keyLength) throws JCEHandlerException { Key generatedClearKey = null; try { KeyGenerator k1; if (keyLength > SMAdapter.LENGTH_DES) { k1 = KeyGenerator.getInstance(ALG_TRIPLE_DES, provider.getName()); } else { k1 = KeyGenerator.getInstance(ALG_DES, provider.getName()); } generatedClearKey = k1.generateKey(); byte[] clearKeyBytes = extractDESKeyMaterial(keyLength, generatedClearKey); Util.adjustDESParity(clearKeyBytes); generatedClearKey = formDESKey(keyLength, clearKeyBytes); } catch (Exception e) { if (e instanceof JCEHandlerException) throw (JCEHandlerException) e; else throw new JCEHandlerException(e); } return generatedClearKey; } 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);  }