Creates a decryption stream. - Java Security

Java examples for Security:Stream

Description

Creates a decryption stream.

Demo Code


//package com.java2s;

import java.io.InputStream;

import java.security.GeneralSecurityException;

import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;

import javax.crypto.SecretKey;

public class Main {
    /**/*from  w w w  . jav a2  s.  co  m*/
     * Cipher algorithm to use. "AES"
     */
    private static final String CIPHER_ALGORITHM = "AES";

    /**
     * Creates a decryption stream. It is a compressed then encrypted stream.
     *
     * @param inputStream
     *            source stream
     * @param secret
     *            secret for the cipher
     * @return the stream
     * @throws GeneralSecurityException
     */
    public static InputStream buildDecryptStream(
            final InputStream inputStream, final SecretKey secret)
            throws GeneralSecurityException {

        final Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
        cipher.init(Cipher.DECRYPT_MODE, secret);
        return new InflaterInputStream(new CipherInputStream(inputStream,
                cipher), new Inflater(false));
    }
}

Related Tutorials