@Test public void testEncryptDESKeyThrowsArrayIndexOutOfBoundsException() throws Throwable { byte[] bytes = new byte[3]; Key clearDESKey = new SecretKeySpec(bytes, 0, 1, "DESde"); byte[] bytes2 = new byte[1]; Key encryptingKey = new SecretKeySpec(bytes2, "testJCEHandlerParam2"); try { new JCEHandler((Provider) null).encryptDESKey((short) 64, clearDESKey, encryptingKey); fail("Expected ArrayIndexOutOfBoundsException to be thrown"); } catch (ArrayIndexOutOfBoundsException ex) { if (isJavaVersionAtMost(JAVA_10)) { assertNull(ex.getMessage(), "ex.getMessage()"); } else { assertEquals("arraycopy: last source index 8 out of bounds for byte[1]", ex.getMessage(), "ex.getMessage()"); } assertEquals("DESde", clearDESKey.getAlgorithm(), "(SecretKeySpec) clearDESKey.getAlgorithm()"); 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);  }