Exemplo n.º 1
0
 @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());
   }
 }
Exemplo n.º 2
0
 @Test
 public void testGenerateDESKeyThrowsJCEHandlerException2() throws Throwable {
   try {
     new JCEHandler((Provider) null).generateDESKey((short) 65);
     fail("Expected JCEHandlerException to be thrown");
   } catch (JCEHandlerException ex) {
     assertEquals("ex.getMessage()", "java.lang.NullPointerException", ex.getMessage());
     assertNull("ex.getNested().getMessage()", ex.getNested().getMessage());
   }
 }
Exemplo n.º 3
0
 @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());
   }
 }
Exemplo n.º 4
0
 @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());
   }
 }
Exemplo n.º 5
0
 @Test
 public void testConstructorThrowsJCEHandlerException() throws Throwable {
   try {
     new JCEHandler("testJCEHandlerJceProviderClassName");
     fail("Expected JCEHandlerException to be thrown");
   } catch (JCEHandlerException ex) {
     assertEquals(
         "ex.getMessage()",
         "java.lang.ClassNotFoundException: testJCEHandlerJceProviderClassName",
         ex.getMessage());
     assertEquals(
         "ex.getNested().getMessage()",
         "testJCEHandlerJceProviderClassName",
         ex.getNested().getMessage());
   }
 }
Exemplo n.º 6
0
 @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());
   }
 }
Exemplo n.º 7
0
 @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());
   }
 }
Exemplo n.º 8
0
 @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());
   }
 }