/** * Returns {@code true} if the specified cipher operation mode name supports initialization vectors, * {@code false} otherwise. * * @param modeName the raw text name of the mode of operation * @return {@code true} if the specified cipher operation mode name supports initialization vectors, * {@code false} otherwise. */ private boolean isModeInitializationVectorCompatible(String modeName) { return modeName != null && !modeName.equalsIgnoreCase(OperationMode.ECB.name()) && !modeName.equalsIgnoreCase(OperationMode.NONE.name()); }
/** * Sets the transformation string mode to be used for streaming operations only. The default value is * {@link OperationMode#CBC CBC} for reasons described in the class-level JavaDoc in the {@code Streaming} section. * * @param mode the transformation string mode to be used for streaming operations only */ public void setStreamingMode(OperationMode mode) { setStreamingModeName(mode.name()); }
/** * Creates a new {@link DefaultBlockCipherService} using the specified block cipher {@code algorithmName}. Per this * class's JavaDoc, this constructor also sets the following defaults: * <ul> * <li>{@code streamingMode} = {@link OperationMode#CBC CBC}</li> * <li>{@code streamingPaddingScheme} = {@link PaddingScheme#NONE none}</li> * <li>{@code streamingBlockSize} = 8</li> * </ul> * All other attributes are null/unset, indicating the JCA Provider defaults will be used. * * @param algorithmName the block cipher algorithm to use when encrypting and decrypting */ public DefaultBlockCipherService(String algorithmName) { super(algorithmName); this.modeName = OperationMode.CBC.name(); this.paddingSchemeName = PaddingScheme.PKCS5.getTransformationName(); this.blockSize = DEFAULT_BLOCK_SIZE; //0 = use the JCA provider's default this.streamingModeName = OperationMode.CBC.name(); this.streamingPaddingSchemeName = PaddingScheme.PKCS5.getTransformationName(); this.streamingBlockSize = DEFAULT_STREAMING_BLOCK_SIZE; }
/** * Sets the cipher operation mode of operation to be used when constructing the * {@link javax.crypto.Cipher Cipher} transformation string. A {@code null} value indicates that the JCA Provider * default mode for the specified {@link #getAlgorithmName() algorithm} should be used. * <p/> * This attribute is used <em>only</em> when constructing the transformation string for block (byte array) * operations ({@link #encrypt(byte[], byte[])} and {@link #decrypt(byte[], byte[])}). The * {@link #setStreamingMode streamingMode} attribute is used when the block cipher is used for * streaming operations. * <p/> * If the {@link OperationMode} enum cannot represent your desired mode, you can set the name explicitly * via the {@link #setModeName modeName} attribute directly. However, because {@link OperationMode} represents all * standard JDK mode names already, ensure that your underlying JCA Provider supports the non-standard name first. * * @param mode the cipher operation mode to be used when constructing * {@link javax.crypto.Cipher Cipher} transformation string, or {@code null} if the JCA Provider * default mode for the specified {@link #getAlgorithmName() algorithm} should be used. */ public void setMode(OperationMode mode) { setModeName(mode.name()); }
/** * Returns {@code true} if the specified cipher operation mode name supports initialization vectors, * {@code false} otherwise. * * @param modeName the raw text name of the mode of operation * @return {@code true} if the specified cipher operation mode name supports initialization vectors, * {@code false} otherwise. */ private boolean isModeInitializationVectorCompatible(String modeName) { return modeName != null && !modeName.equalsIgnoreCase(OperationMode.ECB.name()) && !modeName.equalsIgnoreCase(OperationMode.NONE.name()); }
/** * Sets the transformation string mode to be used for streaming operations only. The default value is * {@link OperationMode#CFB CFB} for reasons described in the class-level JavaDoc in the {@code Streaming} section. * * @param mode the transformation string mode to be used for streaming operations only */ public void setStreamingMode(OperationMode mode) { setStreamingModeName(mode.name()); }
/** * Creates a new {@link DefaultBlockCipherService} using the specified block cipher {@code algorithmName}. Per this * class's JavaDoc, this constructor also sets the following defaults: * <ul> * <li>{@code streamingMode} = {@link OperationMode#CFB CFB}</li> * <li>{@code streamingPaddingScheme} = {@link PaddingScheme#NONE none}</li> * <li>{@code streamingBlockSize} = 8</li> * </ul> * All other attributes are null/unset, indicating the JCA Provider defaults will be used. * * @param algorithmName the block cipher algorithm to use when encrypting and decrypting */ public DefaultBlockCipherService(String algorithmName) { super(algorithmName); this.modeName = OperationMode.CFB.name(); this.paddingSchemeName = PaddingScheme.PKCS5.getTransformationName(); this.blockSize = DEFAULT_BLOCK_SIZE; //0 = use the JCA provider's default this.streamingModeName = OperationMode.CFB.name(); this.streamingPaddingSchemeName = PaddingScheme.NONE.getTransformationName(); this.streamingBlockSize = DEFAULT_STREAMING_BLOCK_SIZE; }
/** * Sets the cipher operation mode of operation to be used when constructing the * {@link javax.crypto.Cipher Cipher} transformation string. A {@code null} value indicates that the JCA Provider * default mode for the specified {@link #getAlgorithmName() algorithm} should be used. * <p/> * This attribute is used <em>only</em> when constructing the transformation string for block (byte array) * operations ({@link #encrypt(byte[], byte[])} and {@link #decrypt(byte[], byte[])}). The * {@link #setStreamingMode streamingMode} attribute is used when the block cipher is used for * streaming operations. * <p/> * If the {@link OperationMode} enum cannot represent your desired mode, you can set the name explicitly * via the {@link #setModeName modeName} attribute directly. However, because {@link OperationMode} represents all * standard JDK mode names already, ensure that your underlying JCA Provider supports the non-standard name first. * * @param mode the cipher operation mode to be used when constructing * {@link javax.crypto.Cipher Cipher} transformation string, or {@code null} if the JCA Provider * default mode for the specified {@link #getAlgorithmName() algorithm} should be used. */ public void setMode(OperationMode mode) { setModeName(mode.name()); }