Package javax.crypto

Examples of javax.crypto.Cipher.doFinal()


    // First test it with JCA.
    if (TEST_JCA) {
      SecretKeySpec k = new SecretKeySpec(key, "AES");
      Cipher c = Cipher.getInstance("AES/CTR/NOPADDING", Rijndael.AesCtrProvider);
      c.init(Cipher.ENCRYPT_MODE, k, new IvParameterSpec(iv));
      byte[] output = c.doFinal(plaintext);
      assertTrue(Arrays.equals(output, ciphertext));
    }

    Rijndael cipher = new Rijndael(bits, 128);
    cipher.initialize(key);
View Full Code Here


          int moved = c.update(plaintext, inputPtr, count, output,
              outputPtr);
          outputPtr += moved;
          inputPtr += count;
        }
        c.doFinal(plaintext, 0, plaintext.length - inputPtr, output,
            outputPtr);
        assertTrue(Arrays.equals(output, ciphertext));
      }

      Rijndael cipher = new Rijndael(bits, 128);
View Full Code Here

      mt.nextBytes(key);
      mt.nextBytes(iv);
      SecretKeySpec k = new SecretKeySpec(key, "AES");
      Cipher c = Cipher.getInstance("AES/CTR/NOPADDING", Rijndael.AesCtrProvider);
      c.init(Cipher.ENCRYPT_MODE, k, new IvParameterSpec(iv));
      byte[] output = c.doFinal(plaintext);
      c = Cipher.getInstance("AES/CTR/NOPADDING", Rijndael.AesCtrProvider);
      c.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(iv));
      byte[] decrypted = c.doFinal(output);
      assertTrue(Arrays.equals(decrypted, plaintext));
    }
View Full Code Here

      Cipher c = Cipher.getInstance("AES/CTR/NOPADDING", Rijndael.AesCtrProvider);
      c.init(Cipher.ENCRYPT_MODE, k, new IvParameterSpec(iv));
      byte[] output = c.doFinal(plaintext);
      c = Cipher.getInstance("AES/CTR/NOPADDING", Rijndael.AesCtrProvider);
      c.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(iv));
      byte[] decrypted = c.doFinal(output);
      assertTrue(Arrays.equals(decrypted, plaintext));
    }
  }
 
  public void testRandom() throws UnsupportedCipherException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
View Full Code Here

      assertTrue(Arrays.equals(finalPlaintext, plaintext));
      if(TEST_JCA) {
        SecretKeySpec k = new SecretKeySpec(key, "AES");
        Cipher c = Cipher.getInstance("AES/CTR/NOPADDING", Rijndael.AesCtrProvider);
        c.init(Cipher.ENCRYPT_MODE, k, new IvParameterSpec(iv));
        byte[] output = c.doFinal(plaintext);
        assertTrue(Arrays.equals(output, ciphertext));
        c = Cipher.getInstance("AES/CTR/NOPADDING", Rijndael.AesCtrProvider);
        c.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(iv));
        byte[] decrypted = c.doFinal(output);
        assertTrue(Arrays.equals(decrypted, plaintext));
View Full Code Here

        c.init(Cipher.ENCRYPT_MODE, k, new IvParameterSpec(iv));
        byte[] output = c.doFinal(plaintext);
        assertTrue(Arrays.equals(output, ciphertext));
        c = Cipher.getInstance("AES/CTR/NOPADDING", Rijndael.AesCtrProvider);
        c.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(iv));
        byte[] decrypted = c.doFinal(output);
        assertTrue(Arrays.equals(decrypted, plaintext));
      }
      // Now encrypt again, in random pieces.
      cipher.initialize(key);
      ctr = new CTRBlockCipher(cipher);
View Full Code Here

      SecretKeySpec k =
        new SecretKeySpec(TEST_VK128[i][0], "AES");
      Cipher c = Cipher.getInstance("AES/ECB/NOPADDING");
      c.init(Cipher.ENCRYPT_MODE, k);
     
      byte[] output = c.doFinal(TEST_VK_PT);
      assertTrue(Arrays.equals(output, TEST_VK128[i][1]));
    }

    // KEYSIZE=192
    for (int i = 0; i < TEST_VK192.length; i++) {
View Full Code Here

      SecretKeySpec k =
        new SecretKeySpec(TEST_VK192[i][0], "AES");
      Cipher c = Cipher.getInstance("AES/ECB/NOPADDING");
      c.init(Cipher.ENCRYPT_MODE, k);
     
      byte[] output = c.doFinal(TEST_VK_PT);
      assertTrue("ECB_VK KEYSIZE=192 I=" + (i + 1), Arrays.equals(output, TEST_VK192[i][1]));
    }
  }

  public void testRandom() throws UnsupportedCipherException {
View Full Code Here

                  // Encrypt.
                  SecretKeySpec k =
                    new SecretKeySpec(key, "AES");
                  Cipher c = Cipher.getInstance("AES/ECB/NOPADDING");
                  c.init(Cipher.ENCRYPT_MODE, k);
                  output = c.doFinal(plaintext);
                  assertTrue(Arrays.equals(output, ciphertext));
                 
                  // Decrypt.
                  c.init(Cipher.DECRYPT_MODE, k);
                  output = c.doFinal(ciphertext);
View Full Code Here

    try {
        Cipher cipher = Cipher.getInstance("AES/CTR/NOPADDING", Rijndael.AesCtrProvider);
        cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(cryptoKey, "AES"), new IvParameterSpec(hash, 0, 16));
        byte[] plaintext = new byte[data.length + 2];
    int moved = cipher.update(data, 0, data.length, plaintext);
    cipher.doFinal(headers, hash.length+2, 2, plaintext, moved);
        int size = ((plaintext[data.length] & 0xff) << 8) + (plaintext[data.length + 1] & 0xff);
        if((size > 32768) || (size < 0)) {
            throw new CHKDecodeException("Invalid size: "+size);
        }
        // Check the hash.
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.