Examples of IvParameterSpec


Examples of javax.crypto.spec.IvParameterSpec

      ctr.processBytes(ciphertext, 0, ciphertext.length, finalPlaintext, 0);
      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));
      }
      // Now encrypt again, in random pieces.
      cipher.initialize(key);
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

    }

    @Test (expected = IllegalArgumentException.class)
    public void testSetIVIvParameterSpecNullInput()
            throws InvalidKeyException, InvalidAlgorithmParameterException {
        IvParameterSpec nullInput = null;
        MessageAuthCode mac = new MessageAuthCode(types[3], keys[3], IVs[3]);
        mac.setIV(nullInput);
    }
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

        byte[] cryptoKey = key.cryptoKey;
        if(cryptoKey.length < Node.SYMMETRIC_KEY_LENGTH)
            throw new CHKDecodeException("Crypto key too short");
    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)) {
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

        System.arraycopy(hash, 0, header, 2, hash.length);
        SecretKey ckey = new SecretKeySpec(encKey, "AES");
        // CTR mode IV is only 16 bytes.
        // That's still plenty though. It will still be unique.
        Cipher cipher = Cipher.getInstance("AES/CTR/NOPADDING", Rijndael.AesCtrProvider);
        cipher.init(Cipher.ENCRYPT_MODE, ckey, new IvParameterSpec(hash, 0, 16));
        byte[] cdata = new byte[data.length];
    int moved = cipher.update(data, 0, data.length, cdata);
    if (moved == data.length) {
      cipher.doFinal(tmpLen, 0, 2, header, hash.length+2);
    } else {
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

      byte[] key = new byte[32]; // Test for whether 256-bit works.
      byte[] iv = new byte[16];
      byte[] plaintext = new byte[16];
      SecretKeySpec k = new SecretKeySpec(key, "AES");
      IvParameterSpec IV = new IvParameterSpec(iv);

      Cipher c = Cipher.getInstance(algo);
      c.init(Cipher.ENCRYPT_MODE, k, IV);
      // ^^^ resolve provider
      Provider provider = c.getProvider();
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

                {
                    try
                    {
                        byte[]  nIv = new byte[iv.length - 1];

                        in.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(nIv));
                        fail("failed to pick up short IV");
                    }
                    catch (InvalidAlgorithmParameterException e)
                    {
                        // ignore - this is what we want...
                    }

                    IvParameterSpec    spec;

                    spec = new IvParameterSpec(iv);

                    in.init(Cipher.DECRYPT_MODE, key, spec);
                }
                else
                {
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

        try
        {
            AlgorithmParameters algParams = AlgorithmParameters.getInstance("DES", "BC");
           
            algParams.init(new IvParameterSpec(new byte[8]));

            // According specification engineGetEncoded() returns
            // the parameters in their primary encoding format. The primary
            // encoding
            // format for parameters is ASN.1, if an ASN.1 specification for
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

    {
        try
        {
            Cipher wrapper = Cipher.getInstance(alg + "Wrap", "BC");

            wrapper.init(Cipher.WRAP_MODE, new SecretKeySpec(kek, alg), new IvParameterSpec(iv));

            try
            {
                byte[]  cText = wrapper.wrap(new SecretKeySpec(in, alg));
                if (!equalArray(cText, out))
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

        Class paramSpec)
        throws InvalidParameterSpecException
    {
        if (paramSpec == IvParameterSpec.class)
        {
            return new IvParameterSpec(iv);
        }

        throw new InvalidParameterSpecException("unknown parameter spec passed to IV parameters object.");
    }
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

            AlgorithmParameters params;

            try
            {
                params = AlgorithmParameters.getInstance("RC6", BouncyCastleProvider.PROVIDER_NAME);
                params.init(new IvParameterSpec(iv));
            }
            catch (Exception e)
            {
                throw new RuntimeException(e.getMessage());
            }
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.