/** * Returns the transformation string to use with the {@link javax.crypto.Cipher#getInstance} invocation when * creating a new {@code Cipher} instance. This default implementation always returns * {@link #getAlgorithmName() getAlgorithmName()}. Block cipher implementations will want to override this method * to support appending cipher operation modes and padding schemes. * * @param streaming if the transformation string is going to be used for a Cipher for stream-based encryption or not. * @return the transformation string to use with the {@link javax.crypto.Cipher#getInstance} invocation when * creating a new {@code Cipher} instance. */ protected String getTransformationString(boolean streaming) { return getAlgorithmName(); }
private javax.crypto.Cipher initNewCipher(int jcaCipherMode, byte[] key, byte[] iv, boolean streaming) throws CryptoException { javax.crypto.Cipher cipher = newCipherInstance(streaming); java.security.Key jdkKey = new SecretKeySpec(key, getAlgorithmName()); IvParameterSpec ivSpec = null; if (iv != null && iv.length > 0) { ivSpec = new IvParameterSpec(iv); } init(cipher, jcaCipherMode, jdkKey, ivSpec, getSecureRandom()); return cipher; } }
/** * Returns a new {@link javax.crypto.Cipher Cipher} instance to use for encryption/decryption operations. The * Cipher's {@code transformationString} for the {@code Cipher}.{@link javax.crypto.Cipher#getInstance getInstance} * call is obtaind via the {@link #getTransformationString(boolean) getTransformationString} method. * * @param streaming {@code true} if the cipher instance will be used as a stream cipher, {@code false} if it will be * used as a block cipher. * @return a new JDK {@code Cipher} instance. * @throws CryptoException if a new Cipher instance cannot be constructed based on the * {@link #getTransformationString(boolean) getTransformationString} value. */ private javax.crypto.Cipher newCipherInstance(boolean streaming) throws CryptoException { String transformationString = getTransformationString(streaming); try { return javax.crypto.Cipher.getInstance(transformationString); } catch (Exception e) { String msg = "Unable to acquire a Java JCA Cipher instance using " + javax.crypto.Cipher.class.getName() + ".getInstance( \"" + transformationString + "\" ). " + getAlgorithmName() + " under this configuration is required for the " + getClass().getName() + " instance to function."; throw new CryptoException(msg, e); } }
/** * Returns the transformation string to use with the {@link javax.crypto.Cipher#getInstance} invocation when * creating a new {@code Cipher} instance. This default implementation always returns * {@link #getAlgorithmName() getAlgorithmName()}. Block cipher implementations will want to override this method * to support appending cipher operation modes and padding schemes. * * @param streaming if the transformation string is going to be used for a Cipher for stream-based encryption or not. * @return the transformation string to use with the {@link javax.crypto.Cipher#getInstance} invocation when * creating a new {@code Cipher} instance. */ protected String getTransformationString(boolean streaming) { return getAlgorithmName(); }
private javax.crypto.Cipher initNewCipher(int jcaCipherMode, byte[] key, byte[] iv, boolean streaming) throws CryptoException { javax.crypto.Cipher cipher = newCipherInstance(streaming); java.security.Key jdkKey = new SecretKeySpec(key, getAlgorithmName()); IvParameterSpec ivSpec = null; if (iv != null && iv.length > 0) { ivSpec = new IvParameterSpec(iv); } init(cipher, jcaCipherMode, jdkKey, ivSpec, getSecureRandom()); return cipher; } }
/** * Returns a new {@link javax.crypto.Cipher Cipher} instance to use for encryption/decryption operations. The * Cipher's {@code transformationString} for the {@code Cipher}.{@link javax.crypto.Cipher#getInstance getInstance} * call is obtaind via the {@link #getTransformationString(boolean) getTransformationString} method. * * @param streaming {@code true} if the cipher instance will be used as a stream cipher, {@code false} if it will be * used as a block cipher. * @return a new JDK {@code Cipher} instance. * @throws CryptoException if a new Cipher instance cannot be constructed based on the * {@link #getTransformationString(boolean) getTransformationString} value. */ private javax.crypto.Cipher newCipherInstance(boolean streaming) throws CryptoException { String transformationString = getTransformationString(streaming); try { return javax.crypto.Cipher.getInstance(transformationString); } catch (Exception e) { String msg = "Unable to acquire a Java JCA Cipher instance using " + javax.crypto.Cipher.class.getName() + ".getInstance( \"" + transformationString + "\" ). " + getAlgorithmName() + " under this configuration is required for the " + getClass().getName() + " instance to function."; throw new CryptoException(msg, e); } }