BlowfishCipherService

{@code CipherService} using the {@code Blowfish} cipher algorithm for all encryption, decryption, and key operations. <p/> The Blowfish algorithm can support key sizes between {@code 32} and {@code 448} bits<b>*</b>, inclusive. However, modern cryptanalysis techniques render keys of 80 bits or less mostly worthless - use {@code 128} or more whenever possible. <p/> Note that this class retains the parent class's default {@link OperationMode#CBC CBC} mode of operation instead of the typical JDK default of {@link OperationMode#ECB ECB}. {@code ECB} should not be used in security-sensitive environments because {@code ECB} does not allow for initialization vectors, which are considered necessary for strong encryption. See the {@link DefaultBlockCipherService parent class}'s JavaDoc and the {@link JcaCipherService JcaCipherService} JavaDoc for more on why the JDK default should not be used and is not used in this implementation. <p/> <b>*</b> Generating and using Blowfish key sizes greater than 128 require installation of the <a href="http://java.sun.com/javase/downloads/index.jsp">Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy files</a>.

@since 1.0

class BlowfishCipherService : DefaultBlockCipherService {}

Constructors

this
this()

Creates a new {@link CipherService} instance using the {@code Blowfish} cipher algorithm with the following important cipher default attributes: <table> <tr> <th>Attribute</th> <th>Value</th> </tr> <tr> <td>{@link #setKeySize keySize}</td> <td>{@code 128} bits</td> </tr> <tr> <td>{@link #setBlockSize blockSize}</td> <td>{@code 64} bits (required for {@code Blowfish})</td> </tr> <tr> <td>{@link #setMode mode}</td> <td>{@link OperationMode#CBC CBC}<b>*</b></td> </tr> <tr> <td>{@link #setPaddingScheme paddingScheme}</td> <td>{@link PaddingScheme#PKCS5 PKCS5}</td> </tr> <tr> <td>{@link #setInitializationVectorSize(int) initializationVectorSize}</td> <td>{@code 64} bits</td> </tr> <tr> <td>{@link #setGenerateInitializationVectors(boolean) generateInitializationVectors}</td> <td>{@code true}<b>**</b></td> </tr> </table> <p/> <b>*</b> The {@link OperationMode#CBC CBC} operation mode is used instead of the JDK default {@code ECB} to ensure strong encryption. {@code ECB} should not be used in security-sensitive environments - see the {@link DefaultBlockCipherService DefaultBlockCipherService} class JavaDoc's &quot;Operation Mode&quot; section for more. <p/> <b>**</b>In conjunction with the default {@code CBC} operation mode, initialization vectors are generated by default to ensure strong encryption. See the {@link JcaCipherService JcaCipherService} class JavaDoc for more.

Inherited Members

From DefaultBlockCipherService

getModeName
string getModeName()

Returns the cipher operation mode name (as a string) 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. <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 #getStreamingModeName() streamingModeName} attribute is used when the block cipher is used for streaming operations. <p/> The default value is {@code null} to retain the JCA Provider default.

setModeName
void setModeName(string modeName)

Sets the cipher operation mode name 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 #getStreamingModeName() streamingModeName} attribute is used when the block cipher is used for streaming operations. <p/> The default value is {@code null} to retain the JCA Provider default. <p/> <b>NOTE:</b> most standard mode names are represented by the {@link OperationMode OperationMode} enum. That enum should be used with the {@link #setMode mode} attribute when possible to retain type-safety and reduce the possibility of errors. This method is better used if the {@link OperationMode} enum does not represent the necessary mode.

setMode
void setMode(OperationMode mode)

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.

getPaddingSchemeName
string getPaddingSchemeName()

Returns the cipher algorithm padding scheme name (as a string) 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. <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 #getStreamingPaddingSchemeName() streamingPaddingSchemeName} attribute is used when the block cipher is used for streaming operations. <p/> The default value is {@code null} to retain the JCA Provider default.

setPaddingSchemeName
void setPaddingSchemeName(string paddingSchemeName)

Sets the padding scheme name to be used when constructing the {@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. <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 #getStreamingPaddingSchemeName() streamingPaddingSchemeName} attribute is used when the block cipher is used for streaming operations. <p/> The default value is {@code null} to retain the JCA Provider default. <p/> <b>NOTE:</b> most standard padding schemes are represented by the {@link PaddingScheme PaddingScheme} enum. That enum should be used with the {@link #setPaddingScheme paddingScheme} attribute when possible to retain type-safety and reduce the possibility of errors. Calling this method however is suitable if the {@code PaddingScheme} enum does not represent the desired scheme.

setPaddingScheme
void setPaddingScheme(PaddingScheme paddingScheme)

Sets the padding scheme to be used when constructing the {@link javax.crypto.Cipher Cipher} transformation string. A {@code null} value indicates that the JCA Provider default padding scheme 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 #setStreamingPaddingScheme streamingPaddingScheme} attribute is used when the block cipher is used for streaming operations. <p/> If the {@link PaddingScheme PaddingScheme} enum does represent your desired scheme, you can set the name explicitly via the {@link #setPaddingSchemeName paddingSchemeName} attribute directly. However, because {@code PaddingScheme} represents all standard JDK scheme names already, ensure that your underlying JCA Provider supports the non-standard name first.

getBlockSize
int getBlockSize()

Returns the block cipher's block size to be used when constructing {@link javax.crypto.Cipher Cipher} transformation string or {@code 0} if the JCA Provider default block size 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 #getStreamingBlockSize() streamingBlockSize} attribute is used when the block cipher is used for streaming operations. <p/> The default value is {@code 0} which retains the JCA Provider default.

setBlockSize
void setBlockSize(int blockSize)

Sets the block cipher's block size to be used when constructing {@link javax.crypto.Cipher Cipher} transformation string. {@code 0} indicates that the JCA Provider default block size 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 #getStreamingBlockSize() streamingBlockSize} attribute is used when the block cipher is used for streaming operations. <p/> The default value is {@code 0} which retains the JCA Provider default. <p/> <b>NOTE:</b> block cipher block sizes are very algorithm-specific. If you change this value, ensure that it will work with the specified {@link #getAlgorithmName() algorithm}.

getStreamingModeName
string getStreamingModeName()

Same purpose as the {@link #getModeName modeName} attribute, but is used instead only for for streaming operations ({@link #encrypt(java.io.InputStream, java.io.OutputStream, byte[])} and {@link #decrypt(java.io.InputStream, java.io.OutputStream, byte[])}). <p/> Note that unlike the {@link #getModeName modeName} attribute, the default value of this attribute is not {@code null} - it is {@link OperationMode#CBC CBC} for reasons described in the class-level JavaDoc in the {@code Streaming} section.

setStreamingModeName
void setStreamingModeName(string streamingModeName)

Sets the transformation string mode name 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.

setStreamingMode
void setStreamingMode(OperationMode mode)

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.

getStreamingPaddingSchemeName
string getStreamingPaddingSchemeName()
Undocumented in source. Be warned that the author may not have intended to support it.
setStreamingPaddingSchemeName
void setStreamingPaddingSchemeName(string streamingPaddingSchemeName)
Undocumented in source. Be warned that the author may not have intended to support it.
setStreamingPaddingScheme
void setStreamingPaddingScheme(PaddingScheme scheme)
Undocumented in source. Be warned that the author may not have intended to support it.
getStreamingBlockSize
int getStreamingBlockSize()
Undocumented in source. Be warned that the author may not have intended to support it.
setStreamingBlockSize
void setStreamingBlockSize(int streamingBlockSize)
Undocumented in source. Be warned that the author may not have intended to support it.
getTransformationString
string getTransformationString(bool streaming)

Returns the transformation string to use with the {@link javax.crypto.Cipher#getInstance} call. If {@code streaming} is {@code true}, a block-cipher transformation string compatible with streaming operations will be constructed and cached for re-use later (see the class-level JavaDoc for more on using block ciphers for streaming). If {@code streaming} is {@code false} a normal block-cipher transformation string will be constructed and cached for later re-use.

isGenerateInitializationVectors
bool isGenerateInitializationVectors(bool streaming)

Overrides the parent implementation to ensure initialization vectors are always generated if streaming is enabled (block ciphers <em>must</em> use initialization vectors if they are to be used as a stream cipher). If not being used as a stream cipher, then the value is computed based on whether or not the currently configured {@link #getModeName modeName} is compatible with initialization vectors as well as the result of the configured {@link #setGenerateInitializationVectors(bool) generateInitializationVectors} value.

generateInitializationVector
byte[] generateInitializationVector(bool streaming)
Undocumented in source. Be warned that the author may not have intended to support it.

Meta