@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 testExtractDESKeyMaterialThrowsJCEHandlerException() throws Throwable { JCEHandler jCEHandler2 = new JCEHandler((Provider) null); byte[] clearKeyBytes = new byte[1]; Key clearDESKey = jCEHandler.formDESKey((short) 192, clearKeyBytes); try { jCEHandler2.extractDESKeyMaterial((short) 100, 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 testExtractDESKeyMaterialThrowsNullPointerException() throws Throwable { try { jCEHandler.extractDESKeyMaterial((short) 100, null); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { assertNull("ex.getMessage()", ex.getMessage()); } }
@Test public void testGetBytesLengthThrowsJCEHandlerException() throws Throwable { try { jCEHandler.getBytesLength((short) 100); fail("Expected JCEHandlerException to be thrown"); } catch (JCEHandlerException ex) { assertEquals("ex.getMessage()", "Unsupported key length: 100 bits", ex.getMessage()); assertNull("ex.getNested()", ex.getNested()); } }
@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 testDoCryptStuffThrowsNullPointerException() throws Throwable { byte[] data = new byte[4]; try { jCEHandler.doCryptStuff(data, null, 100); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException 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 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( "ex.getMessage()", "Unsupported key algorithm: testJCEHandlerParam2", ex.getMessage()); assertNull("ex.getNested()", ex.getNested()); assertEquals( "(SecretKeySpec) clearDESKey.getAlgorithm()", "testJCEHandlerParam2", ((SecretKeySpec) clearDESKey).getAlgorithm()); } }
@Test public void testDoCryptStuffThrowsJCEHandlerException() throws Throwable { jCEHandler = new JCEHandler((Provider) null); byte[] bytes = new byte[1]; Key key = new SecretKeySpec(bytes, "testJCEHandlerParam2"); byte[] data = new byte[3]; try { jCEHandler.doCryptStuff(data, key, 100); 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()", "testJCEHandlerParam2", ((SecretKeySpec) key).getAlgorithm()); } }
@Test public void testGetBytesLength2() throws Throwable { int result = jCEHandler.getBytesLength((short) 64); assertEquals("result", 8, result); }
@Test public void testGetBytesLength1() throws Throwable { jCEHandler.getBytesLength((short) 192); assertTrue("Test completed without Exception", true); }
@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()); }