@Test public void testFormDESKeyThrowsIllegalArgumentException1() throws Throwable { byte[] clearKeyBytes = new byte[0]; try { jCEHandler.formDESKey((short) 64, clearKeyBytes); fail("Expected IllegalArgumentException to be thrown"); } catch (IllegalArgumentException ex) { assertEquals("ex.getMessage()", "Empty key", ex.getMessage()); } }
@Test public void testFormDESKeyThrowsArrayIndexOutOfBoundsException() throws Throwable { byte[] clearKeyBytes = new byte[1]; try { jCEHandler.formDESKey((short) 128, clearKeyBytes); fail("Expected ArrayIndexOutOfBoundsException to be thrown"); } catch (ArrayIndexOutOfBoundsException ex) { assertNull("ex.getMessage()", ex.getMessage()); } }
@Test public void testFormDESKeyThrowsJCEHandlerException() throws Throwable { byte[] clearKeyBytes = new byte[1]; try { jCEHandler.formDESKey((short) 100, clearKeyBytes); fail("Expected JCEHandlerException to be thrown"); } catch (JCEHandlerException ex) { assertEquals("ex.getMessage()", "Unsupported DES key length: 100 bits", ex.getMessage()); assertNull("ex.getNested()", ex.getNested()); } }
@Test public void testDecryptDataThrowsJCEHandlerException() throws Throwable { jCEHandler = new JCEHandler((Provider) null); byte[] clearKeyBytes = new byte[1]; Key key = jCEHandler.formDESKey((short) 192, clearKeyBytes); byte[] encryptedData = new byte[0]; try { jCEHandler.decryptData(encryptedData, key); fail("Expected JCEHandlerException to be thrown"); } catch (JCEHandlerException ex) { assertEquals("ex.getMessage()", "java.lang.NullPointerException", ex.getMessage()); assertNull("ex.getNested().getMessage()", ex.getNested().getMessage()); assertEquals( "(SecretKeySpec) key.getAlgorithm()", "DESede", ((SecretKeySpec) key).getAlgorithm()); } }
@Test public void testExtractDESKeyMaterialThrowsArrayIndexOutOfBoundsException() throws Throwable { byte[] clearKeyBytes = new byte[1]; Key clearDESKey = jCEHandler.formDESKey((short) 192, clearKeyBytes); JCEHandler jCEHandler2 = new JCEHandler((Provider) null); try { jCEHandler2.extractDESKeyMaterial((short) 128, clearDESKey); fail("Expected ArrayIndexOutOfBoundsException to be thrown"); } catch (ArrayIndexOutOfBoundsException ex) { assertNull("ex.getMessage()", ex.getMessage()); assertEquals( "(SecretKeySpec) clearDESKey.getAlgorithm()", "DESede", ((SecretKeySpec) clearDESKey).getAlgorithm()); } }
@Test public void testEncryptDESKeyThrowsJCEHandlerException() throws Throwable { byte[] clearKeyBytes = new byte[1]; Key clearDESKey = jCEHandler.formDESKey((short) 192, clearKeyBytes); try { new JCEHandler((Provider) null).encryptDESKey((short) 100, clearDESKey, clearDESKey); fail("Expected JCEHandlerException to be thrown"); } catch (JCEHandlerException ex) { assertEquals("ex.getMessage()", "Unsupported key length: 100 bits", ex.getMessage()); assertNull("ex.getNested()", ex.getNested()); assertEquals( "(SecretKeySpec) clearDESKey.getAlgorithm()", "DESede", ((SecretKeySpec) clearDESKey).getAlgorithm()); } }
@Test public void testFormDESKey1() throws Throwable { byte[] clearKeyBytes = new byte[1]; SecretKeySpec result = (SecretKeySpec) jCEHandler.formDESKey((short) 192, clearKeyBytes); assertEquals("result.getAlgorithm()", "DESede", result.getAlgorithm()); }