@Test public void testExtractDESKeyMaterialThrowsJCEHandlerException1() throws Throwable { byte[] bytes = new byte[1]; Key clearDESKey = new SecretKeySpec(bytes, "testJCEHandlerParam2"); try { jCEHandler.extractDESKeyMaterial((short) 100, clearDESKey); fail("Expected JCEHandlerException to be thrown"); } catch (JCEHandlerException ex) { assertEquals("Unsupported key algorithm: testJCEHandlerParam2", ex.getMessage(), "ex.getMessage()"); assertNull(ex.getNested(), "ex.getNested()"); assertEquals("testJCEHandlerParam2", clearDESKey.getAlgorithm(), "(SecretKeySpec) clearDESKey.getAlgorithm()"); } }
protected byte[] extractDESKeyMaterial(short keyLength, Key clearDESKey) throws JCEHandlerException { String keyAlg = clearDESKey.getAlgorithm(); String keyFormat = clearDESKey.getFormat(); if (keyFormat.compareTo("RAW") != 0) { throw new JCEHandlerException("Unsupported DES key encoding format: " + keyFormat); } if (!keyAlg.startsWith(ALG_DES)) { throw new JCEHandlerException("Unsupported key algorithm: " + keyAlg); } byte[] clearKeyBytes = clearDESKey.getEncoded(); clearKeyBytes = ISOUtil.trim(clearKeyBytes, getBytesLength(keyLength)); return clearKeyBytes; }
JCEHandler { protected byte[] extractDESKeyMaterial(short keyLength, Key clearDESKey) throws JCEHandlerException { String keyAlg = clearDESKey.getAlgorithm(); String keyFormat = clearDESKey.getFormat(); if (keyFormat.compareTo("RAW") != 0) { throw new JCEHandlerException("Unsupported DES key encoding format: " + keyFormat); } if (!keyAlg.startsWith(ALG_DES)) { throw new JCEHandlerException("Unsupported key algorithm: " + keyAlg); } byte[] clearKeyBytes = clearDESKey.getEncoded(); clearKeyBytes = ISOUtil.trim(clearKeyBytes, getBytesLength(keyLength)); return clearKeyBytes; } }
JCEHandler { protected byte[] extractDESKeyMaterial(short keyLength, Key clearDESKey) throws JCEHandlerException { String keyAlg = clearDESKey.getAlgorithm(); String keyFormat = clearDESKey.getFormat(); if (keyFormat.compareTo("RAW") != 0) { throw new JCEHandlerException("Unsupported DES key encoding format: " + keyFormat); } if (!keyAlg.startsWith(ALG_DES)) { throw new JCEHandlerException("Unsupported key algorithm: " + keyAlg); } byte[] clearKeyBytes = clearDESKey.getEncoded(); clearKeyBytes = ISOUtil.trim(clearKeyBytes, getBytesLength(keyLength)); return clearKeyBytes; } JCEHandler(String jceProviderClassName);  JCEHandler(Provider provider); }
JCEHandler { protected byte[] extractDESKeyMaterial(short keyLength, Key clearDESKey) throws JCEHandlerException { String keyAlg = clearDESKey.getAlgorithm(); String keyFormat = clearDESKey.getFormat(); if (keyFormat.compareTo("RAW") != 0) { throw new JCEHandlerException("Unsupported DES key encoding format: " + keyFormat); } if (!keyAlg.startsWith(ALG_DES)) { throw new JCEHandlerException("Unsupported key algorithm: " + keyAlg); } byte[] clearKeyBytes = clearDESKey.getEncoded(); clearKeyBytes = ISOUtil.trim(clearKeyBytes, getBytesLength(keyLength)); return clearKeyBytes; } 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 { protected byte[] extractDESKeyMaterial(short keyLength, Key clearDESKey) throws JCEHandlerException { String keyAlg = clearDESKey.getAlgorithm(); String keyFormat = clearDESKey.getFormat(); if (keyFormat.compareTo("RAW") != 0) { throw new JCEHandlerException("Unsupported DES key encoding format: " + keyFormat); } if (!keyAlg.startsWith(ALG_DES)) { throw new JCEHandlerException("Unsupported key algorithm: " + keyAlg); } byte[] clearKeyBytes = clearDESKey.getEncoded(); clearKeyBytes = ISOUtil.trim(clearKeyBytes, getBytesLength(keyLength)); return clearKeyBytes; } 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);  }