Example usage for javax.crypto.spec IvParameterSpec IvParameterSpec

List of usage examples for javax.crypto.spec IvParameterSpec IvParameterSpec

Introduction

In this page you can find the example usage for javax.crypto.spec IvParameterSpec IvParameterSpec.

Prototype

public IvParameterSpec(byte[] iv) 

Source Link

Document

Creates an IvParameterSpec object using the bytes in iv as the IV.

Usage

From source file:eu.abc4trust.smartcard.HardwareSmartcard.java

public static Cipher getAESKey(String salt, String password, byte[] IV, boolean encrypt) {
    try {//from w  w w .  j a  v  a2 s  .  c o  m
        // Get the SecretKeySpec
        SecretKeySpec secretKeySpec = getSecretKeySpec(salt, password);

        // Instantiate the cipher
        Cipher cipher = Cipher.getInstance("AES/CBC/pkcs5padding");

        if (encrypt) {
            cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, new IvParameterSpec(IV));
        } else {
            cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, new IvParameterSpec(IV));
        }

        return cipher;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}