Esempio n. 1
0
 @Test
 public void testEncryptDecrypt256_HugeData() {
   System.out.println("encrypt and decrypt huge Data");
   byte[] plainInput = new byte[1000000];
   KeyGenSHA3 keyGen = new KeyGenSHA3();
   String hexKey = keyGen.generateKey(256, "password");
   byte[] bKey = CryptobyHelper.hexStringToBytes(hexKey);
   CryptAES instance = new CryptAES();
   byte[] expResult = plainInput;
   byte[] result = instance.encrypt(plainInput, bKey);
   result = instance.decrypt(result, bKey);
   assertArrayEquals(expResult, result);
 }
Esempio n. 2
0
 @Test
 public void testEncryptDecrypt256() {
   System.out.println("encrypt and decrypt testphrase");
   byte[] plainInput = "Text to Test for Testing from Tester by Testcase".getBytes();
   KeyGenSHA3 keyGen = new KeyGenSHA3();
   String hexKey = keyGen.generateKey(256, "password");
   byte[] bKey = CryptobyHelper.hexStringToBytes(hexKey);
   CryptAES instance = new CryptAES();
   byte[] expResult = plainInput;
   byte[] result = instance.encrypt(plainInput, bKey);
   result = instance.decrypt(result, bKey);
   assertArrayEquals(expResult, result);
 }
Esempio n. 3
0
 @Test
 public void testEncryptDecrypt256_false() {
   System.out.println("crypt almost false key");
   byte[] plainInput = "Text to Test for Testing from Tester by Testcase".getBytes();
   String hexKey = "13A9489AF957FF7B5E8E712737D0B4A0C92AE8EBAE9DD11E9C11B8CB79707017";
   byte[] bKey = CryptobyHelper.hexStringToBytes(hexKey);
   CryptAES instance = new CryptAES();
   byte[] expResult = plainInput;
   byte[] result = instance.encrypt(plainInput, bKey);
   hexKey = "13A9489AF957FF7B5E8E712737D0B4A0C92AE8EBAE9DD11E9C11B8CB79707011";
   bKey = CryptobyHelper.hexStringToBytes(hexKey);
   result = instance.decrypt(result, bKey);
   assertFalse(new String(expResult).equals(new String(result)));
 }
Esempio n. 4
0
 @Test
 public void testEncryptDecrypt256_CBC() {
   System.out.println("encrypt and decrypt recurring words");
   byte[] plainInput =
       "TestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTest".getBytes();
   KeyGenSHA3 keyGen = new KeyGenSHA3();
   String hexKey = keyGen.generateKey(256, "password");
   byte[] bKey = CryptobyHelper.hexStringToBytes(hexKey);
   CryptAES instance = new CryptAES();
   byte[] expResult = plainInput;
   byte[] result = instance.encrypt(plainInput, bKey);
   String resString = CryptobyHelper.bytesToHexStringUpper(result);
   for (int i = 0; i < resString.length() - 32; i += 32) {
     assertFalse(resString.substring(i, i + 32).equals(resString.substring(i + 32, i + 64)));
   }
   result = instance.decrypt(result, bKey);
   assertArrayEquals(expResult, result);
 }