Example usage for javax.crypto.spec SecretKeySpec SecretKeySpec

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

Introduction

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

Prototype

public SecretKeySpec(byte[] key, String algorithm) 

Source Link

Document

Constructs a secret key from the given byte array.

Usage

From source file:cl.niclabs.tscrypto.common.messages.EncryptedData.java

/**
 * Returns a decrypted version of the included data
 * @return/*from   w  w  w.  j a  va2s.  co m*/
 * @throws NoSuchAlgorithmException
 * @throws NoSuchPaddingException
 * @throws InvalidKeyException
 * @throws IllegalBlockSizeException
 * @throws BadPaddingException
 */
public byte[] decrypt() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
        IllegalBlockSizeException, BadPaddingException {

    byte[] plainAESKey = KeyChain.getInstance().decrypt(rsaKeyAlias, encryptedKey);
    SecretKeySpec skeySpec = new SecretKeySpec(plainAESKey, "AES");
    Cipher cipher = Cipher.getInstance("AES");
    cipher.init(Cipher.DECRYPT_MODE, skeySpec);
    return cipher.doFinal(Base64.decodeBase64(encryptedData));
}