@ThreadSafe @Immutable public class Crypt extends Object implements Serializable
| Modifier and Type | Field and Description |
|---|---|
static Crypt |
AES128
The encryption algorithm AES with 128 Bits key size.
|
static Crypt |
AES192
The encryption algorithm AES with 192 Bits key size.
|
static Crypt |
AES256
The encryption algorithm AES with 256 Bits key size.
|
static Crypt |
Blowfish128
Bruce Schneiers encryption algorithm Blowfish with 128 Bits key size.
|
static Crypt |
Blowfish192
Bruce Schneiers encryption algorithm Blowfish with 192 Bits key size.
|
static Crypt |
Blowfish256
Bruce Schneiers encryption algorithm Blowfish with 256 Bits key size.
|
static String |
DEFAULT_BLOCK_CHAIN_MODE
Deprecated.
use
BlockMode.DEFAULT_BLOCK_CHAIN_MODE instead |
static String |
DEFAULT_PADDING_ALGORITHM
Deprecated.
use
Padding.DEFAULT_PADDING_ALGORITHM instead |
static String |
DEFAULT_PASSWORD_HASHING_ALGORITHM
The default algorithm for password hashing
|
static Crypt |
DES192
The encryption algorithm Triple-DES with 192 Bits key size (effective key size 168 bits,
the effective key size for brute force is smaller than 168 bits).
|
static Crypt |
DES64
The encryption algorithm DES with 64 Bits key size (effective key size 56 bits!).
|
| Constructor and Description |
|---|
Crypt(String encryptionAlgorithm,
int keySize,
int blockSize)
Constructs a Crypt object with the specified parameters.
|
Crypt(String encryptionAlgorithm,
int keySize,
int blockSize,
BlockMode blockMode,
Padding padding)
Constructs a Crypt object with the specified parameters
|
Crypt(String encryptionAlgorithm,
int keySize,
int blockSize,
String passwordHashingAlgorithm)
Constructs a Crypt object with the specified parameters.
|
Crypt(String encryptionAlgorithm,
int keySize,
int blockSize,
String passwordHashingAlgorithm,
BlockMode blockMode,
Padding padding)
Constructs a Crypt object with the specified parameters
|
Crypt(String encryptionAlgorithm,
int keySize,
int blockSize,
String passwordHashingAlgorithm,
BlockMode blockMode,
Padding padding,
int bufferSize)
Constructs a Crypt object with the specified parameters
|
Crypt(String encryptionAlgorithm,
int keySize,
int blockSize,
String blockMode,
String padding)
Deprecated.
use
Crypt(String, int, int, BlockMode, Padding) instead |
Crypt(String encryptionAlgorithm,
int keySize,
int blockSize,
String passwordHashingAlgorithm,
String blockMode,
String padding)
Deprecated.
|
Crypt(String encryptionAlgorithm,
int keySize,
int blockSize,
String passwordHashingAlgorithm,
String blockMode,
String padding,
int bufferSize)
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
decrypt(byte[] input,
byte[] passwordBytes)
Decrypts the input data and returns the plain text
|
byte[] |
decrypt(byte[] input,
CharSequence password)
Decrypts the input data and returns the plain text
|
long |
decrypt(ByteBuffer input,
ByteBuffer output,
byte[] passwordBytes)
Decrypts all input from the given byte buffer to the given byte buffer
|
long |
decrypt(ByteBuffer input,
ByteBuffer output,
CharSequence password)
Decrypts all input from the given byte buffer to the given byte buffer
|
long |
decrypt(InputStream input,
OutputStream output,
byte[] passwordBytes)
Decrypts all input from the given input stream to the given output stream.
|
long |
decrypt(InputStream input,
OutputStream output,
CharSequence password)
Decrypts all input from the given input stream to the given outputs stream.
|
byte[] |
encrypt(byte[] input,
byte[] passwordBytes)
Encrypts the input data and returns the cipher text
|
byte[] |
encrypt(byte[] input,
CharSequence password)
Encrypts the input data and returns the cipher text
|
long |
encrypt(ByteBuffer input,
ByteBuffer output,
byte[] passwordBytes)
Encrypts all input from the given byte buffer to the given byte buffer
|
long |
encrypt(ByteBuffer input,
ByteBuffer output,
CharSequence password)
Encrypts all input from the given byte buffer to the given byte buffer
|
long |
encrypt(InputStream input,
OutputStream output,
byte[] passwordBytes)
Encrypts all input from the given input stream to the given output stream.
|
long |
encrypt(InputStream input,
OutputStream output,
CharSequence password)
Encrypts all input from the given input stream to the given output stream.
|
boolean |
equals(Object o)
Is this Crypt equal to the given object
|
BlockMode |
getBlockMode()
Returns the block mode
|
int |
getBlockSize()
Returns the block size in bits
|
int |
getBufferSize()
Returns the buffer size
|
String |
getEncryptionAlgorithm()
Returns the encryption algorithm
|
String |
getEncryptionMethod()
Returns the encryption method string
|
byte[] |
getHashedEncryptionKey(CharSequence password)
Hashes a password string
|
CryptInputStream |
getInputStream(InputStream input,
byte[] passwordBytes)
Creates an input stream for this Crypt
This is simply an extension to the standard
CipherInputStream, which
reads the initialization vector in this method. |
CryptInputStream |
getInputStream(InputStream input,
CharSequence password)
Creates an input stream for this Crypt
This is simply an extension to the standard
CipherInputStream, which
reads the initialization vector in this method. |
int |
getKeySize()
Returns the key size in bits
|
long |
getMaximumCipherTextLength(long plainTextLength)
Returns the maximum bytes needed for the cipher text for a given plain text length
|
long |
getMaximumPlainTextLength(long cipherTextLength)
Returns the maximum bytes needed for the plain text for a given cipher text length
|
CryptOutputStream |
getOutputStream(OutputStream output,
byte[] passwordBytes)
Creates an output stream for this Crypt.
|
CryptOutputStream |
getOutputStream(OutputStream output,
CharSequence password)
Creates an output stream for this Crypt.
|
Padding |
getPadding()
Returns the padding
|
String |
getPasswordHashingAlgorithm()
Returns the password hashing algorithm
|
int |
hashCode()
The hash code of this crypt
|
String |
toString()
String description of this Crypt
|
public static final Crypt AES256
public static final Crypt AES192
public static final Crypt AES128
public static final Crypt Blowfish256
public static final Crypt Blowfish192
public static final Crypt Blowfish128
public static final Crypt DES64
public static final Crypt DES192
public static final String DEFAULT_PASSWORD_HASHING_ALGORITHM
public static final String DEFAULT_BLOCK_CHAIN_MODE
BlockMode.DEFAULT_BLOCK_CHAIN_MODE insteadpublic static final String DEFAULT_PADDING_ALGORITHM
Padding.DEFAULT_PADDING_ALGORITHM insteadpublic Crypt(@Nonnull String encryptionAlgorithm, int keySize, int blockSize, @Nonnull String passwordHashingAlgorithm, @Nonnull String blockMode, @Nonnull String padding, int bufferSize)
Crypt(String, int, int, String, BlockMode, Padding, int) insteadencryptionAlgorithm - the encryption algorithm (see http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html)keySize - the key size in bits. Compatibility to the encryption algorithm is not checked, so a
CryptoInitializationProblem may be throw laterblockSize - the block size in bits. Compatibility to the encryption algorithm is not checked!passwordHashingAlgorithm - the password hashing algorithm for String passwordsblockMode - the block encoding mode. Modes other than CBC are not always supported. ECB is strongly discouragedpadding - the padding mode (see http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html)bufferSize - size of the buffer for io operationspublic Crypt(@Nonnull String encryptionAlgorithm, int keySize, int blockSize, @Nonnull String passwordHashingAlgorithm, @Nonnull BlockMode blockMode, @Nonnull Padding padding, int bufferSize)
encryptionAlgorithm - the encryption algorithm (see http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html)keySize - the key size in bits. Compatibility to the encryption algorithm is not checked, so a
CryptoInitializationProblem may be throw laterblockSize - the block size in bits. Compatibility to the encryption algorithm is not checked!passwordHashingAlgorithm - the password hashing algorithm for String passwordsblockMode - the block encoding mode. Modes other than CBC are not always supported. ECB is strongly discouragedpadding - the padding mode (see http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html)bufferSize - size of the buffer for io operationspublic Crypt(@Nonnull String encryptionAlgorithm, int keySize, int blockSize, @Nonnull String passwordHashingAlgorithm, @Nonnull String blockMode, @Nonnull String padding)
Crypt(String, int, int, String, BlockMode, Padding) insteadencryptionAlgorithm - the encryption algorithm (see http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html)keySize - the key size in bits. Compatibility to the encryption algorithm is not checked, so a
CryptoInitializationProblem may be throw laterblockSize - the block size in bits. Compatibility to the encryption algorithm is not checked!passwordHashingAlgorithm - the password hashing algorithm for String passwordsblockMode - the block encoding mode. Modes other than CBC are not always supported. ECB is strongly discouragedpadding - the padding mode (see http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html)public Crypt(@Nonnull String encryptionAlgorithm, int keySize, int blockSize, @Nonnull String passwordHashingAlgorithm, @Nonnull BlockMode blockMode, @Nonnull Padding padding)
encryptionAlgorithm - the encryption algorithm (see http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html)keySize - the key size in bits. Compatibility to the encryption algorithm is not checked, so a
CryptoInitializationProblem may be throw laterblockSize - the block size in bits. Compatibility to the encryption algorithm is not checked!passwordHashingAlgorithm - the password hashing algorithm for String passwordsblockMode - the block encoding mode. Modes other than CBC are not always supported. ECB is strongly discouragedpadding - the padding mode (see http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html)public Crypt(@Nonnull String encryptionAlgorithm, int keySize, int blockSize, @Nonnull String blockMode, @Nonnull String padding)
Crypt(String, int, int, BlockMode, Padding) insteadencryptionAlgorithm - the encryption algorithm (see http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html)keySize - the key size in bits. Compatibility to the encryption algorithm is not checked, so a
CryptoInitializationProblem may be throw laterblockSize - the block size in bits. Compatibility to the encryption algorithm is not checked!blockMode - the block encoding mode. Modes other than CBC are not always supported. ECB is unsupportedpadding - the padding mode (see http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html)public Crypt(@Nonnull String encryptionAlgorithm, int keySize, int blockSize, @Nonnull BlockMode blockMode, @Nonnull Padding padding)
encryptionAlgorithm - the encryption algorithm (see http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html)keySize - the key size in bits. Compatibility to the encryption algorithm is not checked, so a
CryptoInitializationProblem may be throw laterblockSize - the block size in bits. Compatibility to the encryption algorithm is not checked!blockMode - the block encoding mode. Modes other than CBC are not always supported. ECB is unsupportedpadding - the padding mode (see http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html)public Crypt(@Nonnull String encryptionAlgorithm, int keySize, int blockSize, @Nonnull String passwordHashingAlgorithm)
encryptionAlgorithm - the encryption algorithm (see http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html)keySize - the key size in bits. Compatibility to the encryption algorithm is not checked!blockSize - the block size in bits. Compatibility to the encryption algorithm is not checked!passwordHashingAlgorithm - the password hashing algorithm for String passwordspublic Crypt(@Nonnull String encryptionAlgorithm, int keySize, int blockSize)
encryptionAlgorithm - the encryption algorithm (see http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html)keySize - the key size in bits. Compatibility to the encryption algorithm is not checked!blockSize - the block size in bits. Compatibility to the encryption algorithm is not checked!public int getKeySize()
public int getBlockSize()
@Nonnull public String getEncryptionMethod()
public long encrypt(@Nonnull@WillClose InputStream input, @Nonnull@WillClose OutputStream output, @Nonnull CharSequence password) throws IOException
input - plain text input streamoutput - cipher text output streampassword - password for encryption. The password used actually used will be the hash of this String using
the specified password hashing algorithmIOException - in case of an underlying IOException of the streamsCryptoInitializationProblem - in case of a CryptoInitializationProblem problempublic long encrypt(@Nonnull@WillClose InputStream input, @Nonnull@WillClose OutputStream output, @Nonnull byte[] passwordBytes) throws IOException
input - plain text input streamoutput - cipher text output streampasswordBytes - the used password. The length must be compatible to the used encryption algorithmIOException - in case of an underlying IOException of the streamsCryptoInitializationProblem - in case of a CryptoInitializationProblem problem@Nonnull public byte[] encrypt(@Nonnull byte[] input, @Nonnull CharSequence password)
input - plain textpassword - password for encryption. The password used actually used will be the hash of this String using
the specified password hashing algorithmCryptoInitializationProblem - in case of a CryptoInitializationProblem problem@Nonnull public byte[] encrypt(@Nonnull byte[] input, @Nonnull byte[] passwordBytes)
input - plain textpasswordBytes - the used password. The length must be compatible to the used encryption algorithmCryptoInitializationProblem - in case of a CryptoInitializationProblem problempublic long encrypt(@Nonnull ByteBuffer input, @Nonnull ByteBuffer output, @Nonnull CharSequence password)
input - plain text byte bufferoutput - cipher text byte bufferpassword - password for encryption. The password used actually used will be the hash of this String using
the specified password hashing algorithmCryptoInitializationProblem - in case of a CryptoInitializationProblem problempublic long encrypt(@Nonnull ByteBuffer input, @Nonnull ByteBuffer output, @Nonnull byte[] passwordBytes)
input - plain text byte bufferoutput - cipher text byte bufferpasswordBytes - the used password. The length must be compatible to the used encryption algorithmCryptoInitializationProblem - in case of a CryptoInitializationProblem problempublic long decrypt(@Nonnull@WillClose InputStream input, @Nonnull@WillClose OutputStream output, @Nonnull CharSequence password) throws IOException
input - cipher text input streamoutput - plain text output streampassword - password for decryption. The password used actually used will be the hash of this String using
the specified password hashing algorithmIOException - in case of an underlying IOException of the streamsCryptoInitializationProblem - in case of a CryptoInitializationProblem problempublic long decrypt(@Nonnull@WillClose InputStream input, @Nonnull@WillClose OutputStream output, @Nonnull byte[] passwordBytes) throws IOException
input - cipher text input streamoutput - plain text output streampasswordBytes - the used password. The length must be compatible to the used encryption algorithmIOException - in case of an underlying IOException of the streamsCryptoInitializationProblem - in case of a CryptoInitializationProblem problem@Nonnull public byte[] decrypt(@Nonnull byte[] input, @Nonnull CharSequence password)
input - cipher textpassword - password for decryption. The password used actually used will be the hash of this String using
the specified password hashing algorithmCryptoInitializationProblem - in case of a CryptoInitializationProblem problem@Nonnull public byte[] decrypt(@Nonnull byte[] input, @Nonnull byte[] passwordBytes)
input - cipher textpasswordBytes - the used password. The length must be compatible to the used encryption algorithmCryptoInitializationProblem - in case of a CryptoInitializationProblem problempublic long decrypt(@Nonnull ByteBuffer input, @Nonnull ByteBuffer output, @Nonnull CharSequence password)
input - cipher text byte bufferoutput - test text byte bufferpassword - password for decryption. The password used actually used will be the hash of this String using
the specified password hashing algorithmCryptoInitializationProblem - in case of a CryptoInitializationProblem problemCryptoBufferOverflowException - not enough bytes in outputCryptoInvalidCipherTextException - invalid cipher textpublic long decrypt(@Nonnull ByteBuffer input, @Nonnull ByteBuffer output, @Nonnull byte[] passwordBytes)
input - cipher text byte bufferoutput - test text byte bufferpasswordBytes - the used password. The length must be compatible to the used encryption algorithmCryptoInitializationProblem - in case of a CryptoInitializationProblem problemCryptoBufferOverflowException - not enough bytes in outputCryptoInvalidCipherTextException - invalid cipher textpublic CryptInputStream getInputStream(@Nonnull InputStream input, @Nonnull CharSequence password) throws IOException
CipherInputStream, which
reads the initialization vector in this method.
Please ensure that close is always called explicitly for this stream object. Failing to do so will result in
missing plain text bytes.input - the cipher input streampassword - the passwordIOException - IOException if failing to read the initialization vectorCryptoInitializationProblem - in case of a CryptoInitializationProblem problempublic CryptInputStream getInputStream(@Nonnull InputStream input, @Nonnull byte[] passwordBytes) throws IOException
CipherInputStream, which
reads the initialization vector in this method.
to read the initialization vector.
Please ensure that close is always called explicitly for this stream object. Failing to do so will result in
missing plain text bytes.input - the cipher input streampasswordBytes - the password bytesIOException - IOException if failing to read the initialization vectorCryptoInitializationProblem - in case of a CryptoInitializationProblem problempublic CryptOutputStream getOutputStream(@Nonnull OutputStream output, @Nonnull CharSequence password) throws IOException
CipherOutputStream, which
writes the initialization vector in this method.
Please ensure that close is always called explicitly for this stream object. Failing to do so will result in
missing cipher text bytes.output - the cipher output streampassword - the passwordIOException - IOException if failing to write the initialization vectorCryptoInitializationProblem - in case of a CryptoInitializationProblem problempublic CryptOutputStream getOutputStream(@Nonnull OutputStream output, @Nonnull byte[] passwordBytes) throws IOException
CipherOutputStream, which
writes the initialization vector in this method.
Please ensure that close is always called explicitly for this stream object. Failing to do so will result in
missing cipher text bytes.output - the cipher output streampasswordBytes - the password bytesIOException - IOException if failing to write the initialization vectorCryptoInitializationProblem - in case of a CryptoInitializationProblem problempublic long getMaximumCipherTextLength(long plainTextLength)
plainTextLength - plain text lengthpublic long getMaximumPlainTextLength(long cipherTextLength)
cipherTextLength - cipher text length@Nonnull public byte[] getHashedEncryptionKey(@Nonnull CharSequence password)
password - the string passwordCryptoInitializationProblem - in case of a CryptoInitializationProblem problempublic String toString()
public boolean equals(@CheckForNull Object o)
public int hashCode()
@Nonnull public String getEncryptionAlgorithm()
@Nonnull public String getPasswordHashingAlgorithm()
@Nonnull public BlockMode getBlockMode()
public int getBufferSize()
Copyright © 2014 Michael Bock. All rights reserved.