Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * Copyright 2013-2015, Inc. or its affiliates. All Rights Reserved.
  * Licensed under the Apache License, Version 2.0 (the "License").
  * You may not use this file except in compliance with the License.
  * A copy of the License is located at
 * or in the "license" file accompanying this file. This file is distributed
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.

this class is no longer used and will be removed in the future

Factory for creating Ciphers based on the crypto key and configuration specified in the constructor. Each invocation of createCipher() will produce a new, identical Cipher object. Each returned Cipher will encrypt data with <bold>exactly</bold> the same output as any other Cipher returned by this instance of CipherFactory.

public class CipherFactory {
    private final SecretKey symmetricKey;
    private final int cipherMode;
    private byte[] initVectorBytes;
    private final Provider cryptoProvider;

Creates a new CipherFactory that will produce ciphers using the specified key, mode, IV and provider.

symmetricKey The symmetric key used in the ciphers created by this factory.
cipherMode The mode indicating whether the created ciphers are for encrypting or decrypting.
initVectorBytes The optional crypto IV used to initialize the ciphers.
cryptoProvider The optional Java crypto provider implementation, if an alternate crypto provider is to be used.
    public CipherFactory(SecretKey symmetricKeyint cipherModebyte[] initVectorBytesProvider cryptoProvider) {
        this. = symmetricKey;
        this. = cipherMode;
        this. = initVectorBytes;
        this. = cryptoProvider;

Creates a new Cipher instance based on the crypto parameters specified in the constructor. Each Cipher instance is identical to any other Cipher produced by this CipherFactory.

A new Cipher instance, identical to each Cipher produced by this factory instance.
    public Cipher createCipher() {
        Cipher cipher = EncryptionUtils.createSymmetricCipher();
        // If we weren't given an IV to use, make sure we store the one the first Cipher
        // used so we can use it for all future Ciphers created by this instance.
        if ( == null = cipher.getIV();
        return cipher;
    public Provider getCryptoProvider() {
        return ;
    public int getCipherMode() {
        return ;
    public byte[] getIV() {
        return  == null ? null : .clone();
New to GrepCode? Check out our FAQ X