Examples of IvParameterSpec


Examples of javax.crypto.spec.IvParameterSpec

   * @return
   */
  public static byte[] AESDecrypt(byte[] encrypted, byte[] key, byte[] iv) {
    try {
          SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
          IvParameterSpec ivSpec = new IvParameterSpec(iv);
          Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
          cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivSpec);
          return cipher.doFinal(encrypted);
    } catch(InvalidKeyException e) {
      throw new IllegalArgumentException(
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

                Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
                KeySpec keyspec = new DESedeKeySpec(keydata);
                Key key = SecretKeyFactory.getInstance("DESede").generateSecret(keyspec);
                cipher.init(Cipher.DECRYPT_MODE, key,
                    new IvParameterSpec(iv, 0, cipher.getBlockSize()));

                ByteArrayReader data = new ByteArrayReader(cipher.doFinal(
                            keyblob));

                if (data.readInt() == cookie) {
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

                            "DESede/CBC/PKCS5Padding");
                    KeySpec keyspec = new DESedeKeySpec(keydata);
                    Key key = SecretKeyFactory.getInstance("DESede")
                                              .generateSecret(keyspec);
                    cipher.init(Cipher.ENCRYPT_MODE, key,
                        new IvParameterSpec(iv, 0, cipher.getBlockSize()));

                    ByteArrayWriter data = new ByteArrayWriter();
                    baw.writeString(type);
                    baw.write(iv);
                    data.writeInt(cookie);
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

            if (gcmUseIvParameterSpec) {
                // This override allows to support Java 1.7+ with (usually older versions of) third-party security
                // providers which support or even require GCM via IvParameterSpec rather than GCMParameterSpec,
                // e.g. BouncyCastle <= 1.49 (really <= 1.50 due to a semi-related bug).
                log.debug("Saw AES-GCM block cipher, using IvParameterSpec due to system property override: {}", algorithm);
                return new IvParameterSpec(iv);
            }
           
            log.debug("Saw AES-GCM block cipher, attempting to create GCMParameterSpec: {}", algorithm);
           
            try {
                // This class only added in Java 1.7. So load reflectively until Santuario starts targeting a minimum of Java 1.7.
                Class<?> gcmSpecClass = ClassLoaderUtils.loadClass("javax.crypto.spec.GCMParameterSpec", this.getClass());
               
                // XML Encryption 1.1 mandates a 128-bit Authentication Tag for AES GCM modes.
                AlgorithmParameterSpec gcmSpec = (AlgorithmParameterSpec) gcmSpecClass.getConstructor(int.class, byte[].class)
                        .newInstance(128, iv);
                log.debug("Successfully created GCMParameterSpec");
                return gcmSpec;
            } catch (Exception e) {
                // This handles the case of Java < 1.7 with a third-party security provider that
                // supports GCM mode using only an IvParameterSpec, such as BouncyCastle.
                log.debug("Failed to create GCMParameterSpec, falling back to returning IvParameterSpec", e);
                return new IvParameterSpec(iv);
            }
        } else {
            log.debug("Saw non-AES-GCM mode block cipher, returning IvParameterSpec: {}", algorithm);
            return new IvParameterSpec(iv);
        }
    }
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

            int index = (int)(_pos >> 12);
            byte[] blockKey = new byte[4];
            LittleEndian.putInt(blockKey, index);
            byte[] iv = generateIv(_info.getHeader().getAlgorithm(),
                                   _info.getHeader().getKeySalt(), blockKey);
            _cipher.init(Cipher.DECRYPT_MODE, _secretKey, new IvParameterSpec(iv));
            if (_lastIndex != index)
                _stream.skip((index - _lastIndex) << 12);

            byte[] block = new byte[Math.min(_stream.available(), 4096)];
            _stream.readFully(block);
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

   
    public Cipher getDecryptor() {
        Cipher deccipher = null;
        try {
            deccipher = Cipher.getInstance(transformation);
            deccipher.init(Cipher.DECRYPT_MODE, key, ivp == null ? null : new IvParameterSpec(ivp));
        } catch (GeneralSecurityException e) {
            // ignore
        }
        return deccipher;
    }
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

     */
    private String decrypt(JSONArray jsonArray) throws IllegalBlockSizeException,
            BadPaddingException, UnsupportedEncodingException, InvalidKeyException,
            NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException, JSONException {
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        cipher.init(Cipher.DECRYPT_MODE, getCiperKey(Base64.decodeBase64(jsonArray.getString(0).getBytes("UTF-8"))), new IvParameterSpec(Base64.decodeBase64(jsonArray.getString(1).getBytes("UTF-8"))));
        return new String(cipher.doFinal(Base64.decodeBase64(jsonArray.getString(2).getBytes("UTF-8"))));
    }
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

      (byte)0x3f, (byte)0x63, (byte)0x0d, (byte)0x93
    };
   
    /* Initialize cipher with key and iv in encrypt mode. */
    try {
      this.cipher.init(Cipher.ENCRYPT_MODE, this.key, new IvParameterSpec(this.iv));
    }
    catch (InvalidKeyException e){
      System.out.println("Invalid key!");
    }
    catch (InvalidAlgorithmParameterException e){
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

          }
        }
       
        /* Set new IV. */
        try{
          this.cipher.init(Cipher.ENCRYPT_MODE, this.key, new IvParameterSpec(this.iv));
        }
        catch(InvalidKeyException e){
          e.printStackTrace();
        }
        catch(InvalidAlgorithmParameterException e){
View Full Code Here

Examples of javax.crypto.spec.IvParameterSpec

  }

  private static Cipher getCipher(Key key, int mode, byte[] parameters) {
    try {
      Cipher cipher = Cipher.getInstance(TYPE);
      cipher.init(mode, key, new IvParameterSpec(parameters));
      return cipher;
    } catch (Exception e) {
      String msg = "Unable to load key using transformation: " + TYPE;
      if (e instanceof InvalidKeyException) {
        try {
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.