Examples of IvParameterSpec


Examples of javax.crypto.spec.IvParameterSpec

    @Test (expected = UnsupportedTypeException.class)
    public void testSetIVIvParameterSpecUnsupportedTypeException() throws GeneralSecurityException {
        int i = 0;
        CryptByteBuffer crypt = new CryptByteBuffer(cipherTypes[i], keys[i]);
        crypt.setIV(new IvParameterSpec(ivs[4]));
        fail("Expected UnsupportedTypeException");
    }
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

     * Generates a random iv of a specified length
     * @param length How long the iv should be in bytes
     * @return The randomly generated iv
     */
    public static IvParameterSpec genIV(int length){
        return new IvParameterSpec(genRandomBytes(length));
    }
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

     * @param offset Where the iv begins
     * @param length How long the iv is
     * @return Returns an IvParameterSpec containing the iv.
     */
    public static IvParameterSpec getIvParameterSpec(byte[] iv, int offset, int length){
        return new IvParameterSpec(iv, offset, length);
    }
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

     * Converts an iv in a ByteBuffer and places it in a IvParameterSpec.
     * @param iv The ByteBuffer containing the iv
     * @return Returns an IvParameterSpec containing the iv.
     */
    public static IvParameterSpec getIvParameterSpec(ByteBuffer iv){
        return new IvParameterSpec(Fields.copyToArray(iv));
    }
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

     * @throws InvalidKeyException
     * @throws InvalidAlgorithmParameterException
     */
    public CryptByteBuffer(CryptByteBufferType type, SecretKey key, byte[] iv, int offset)
            throws InvalidKeyException, InvalidAlgorithmParameterException{
        this(type, key, new IvParameterSpec(iv, offset, type.ivSize));
    }
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

    }

    @Test
    public void testDeriveIvParameterSpec() throws InvalidKeyException{
        SecretKey kdfKey = KeyGenUtils.getSecretKey(KeyType.HMACSHA512, trueLengthSecretKeys[6]);
        IvParameterSpec buf1 =
                KeyGenUtils.deriveIvParameterSpec(kdfKey, KeyGenUtils.class, kdfInput,
                        KeyType.ChaCha128);
        IvParameterSpec buf2 =
                KeyGenUtils.deriveIvParameterSpec(kdfKey, KeyGenUtils.class, kdfInput,
                        KeyType.ChaCha128);
        assertNotNull(buf1);
        assertArrayEquals(buf1.getIV(), buf2.getIV());
    }
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

   
    @Test
    public void testDeriveIvParameterSpecLength() throws InvalidKeyException{
        for(KeyType type: keyTypes){
            SecretKey kdfKey = KeyGenUtils.getSecretKey(KeyType.HMACSHA512, trueLengthSecretKeys[6]);
            IvParameterSpec buf1 = KeyGenUtils.deriveIvParameterSpec(kdfKey, KeyGenUtils.class,
                    kdfInput, type);

            assertEquals(buf1.getIV().length, type.ivSize >> 3);
        }
    }
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

      IllegalBlockSizeException, BadPaddingException {
    // 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);
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

      // First test it with JCA.
      long seed = mt.nextLong();
      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));
        MersenneTwister random = new MersenneTwister(seed);
        byte[] output = new byte[plaintext.length];
        int inputPtr = 0;
        int outputPtr = 0;
        // Odd API designed for block ciphers etc.
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

      mt.nextBytes(plaintext);
      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
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.