Package com.gengoai
Enum EncryptionMethod
- java.lang.Object
-
- java.lang.Enum<EncryptionMethod>
-
- com.gengoai.EncryptionMethod
-
- All Implemented Interfaces:
Serializable
,Comparable<EncryptionMethod>
public enum EncryptionMethod extends Enum<EncryptionMethod>
Convenience methods for encryption with common algorithms. Common usages is as follows:
String encryptedText = EncryptionMethod.AES.encrypt("This is my secret text", "MY SECURE PASSWORD"); String decryptedText = EncryptionMethod.AES.decryptToString(encryptedText, "MY SECURE PASSWORD");
- Author:
- David B. Bracewell
-
-
Enum Constant Summary
Enum Constants Enum Constant Description AES
128 bit AES Encryption.BLOWFISH
128 bit Blowfish encryption.DES
128 bit DES EncryptionTRIPLE_DES
192 bit Triple DES encryption
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Cipher
constructCipher(@lombok.NonNull byte[] key, int mode)
Constructs a cipher for the given key and mode.byte[]
decrypt(@NonNull String content, @lombok.NonNull byte[] key)
Decrypts encrypted content in a Base64 encoded byte array into a byte array.byte[]
decrypt(@NonNull String content, @NonNull String key)
Decrypts encrypted content in a Base64 encoded string into a byte array.String
decryptToString(@NonNull String content, @NonNull String key)
Decrypts encrypted content in a Base64 encoded string into a string.String
encrypt(@lombok.NonNull byte[] content, @lombok.NonNull byte[] key)
Encrypts content into a Base64 encoded string.String
encrypt(@NonNull String content, @NonNull String key)
Encrypts content into a Base64 encoded string.protected byte[]
ensureKeyLength(byte[] key)
Ensures the the key is needed length for the encryption method.static EncryptionMethod
fromName(String name)
Parses a String to find the correct EncryptionMethod.static EncryptionMethod
valueOf(String name)
Returns the enum constant of this type with the specified name.static EncryptionMethod[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
AES
public static final EncryptionMethod AES
128 bit AES Encryption.- See Also:
- Wikipedia's entry on AES
-
DES
public static final EncryptionMethod DES
128 bit DES Encryption- See Also:
- Wikipedia's entry on DES
-
TRIPLE_DES
public static final EncryptionMethod TRIPLE_DES
192 bit Triple DES encryption- See Also:
- Wikipedia's entry on Triple DES.
-
BLOWFISH
public static final EncryptionMethod BLOWFISH
128 bit Blowfish encryption.
-
-
Method Detail
-
values
public static EncryptionMethod[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (EncryptionMethod c : EncryptionMethod.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static EncryptionMethod valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
fromName
public static EncryptionMethod fromName(String name)
Parses a String to find the correct EncryptionMethod.- Parameters:
name
- The name;- Returns:
- An EncryptionMethod
-
constructCipher
protected Cipher constructCipher(@NonNull @lombok.NonNull byte[] key, int mode)
Constructs a cipher for the given key and mode.
- Parameters:
key
- The keymode
- The mode- Returns:
- The Cipher
-
decrypt
public final byte[] decrypt(@NonNull @NonNull String content, @NonNull @NonNull String key)
Decrypts encrypted content in a Base64 encoded string into a byte array.- Parameters:
content
- The encrypted contentkey
- The password- Returns:
- An unencrypted version of the content
-
decrypt
public byte[] decrypt(@NonNull @NonNull String content, @NonNull @lombok.NonNull byte[] key)
Decrypts encrypted content in a Base64 encoded byte array into a byte array.- Parameters:
content
- The encrypted contentkey
- The password- Returns:
- An unencrypted version of the content
-
decryptToString
public final String decryptToString(@NonNull @NonNull String content, @NonNull @NonNull String key)
Decrypts encrypted content in a Base64 encoded string into a string.- Parameters:
content
- The encrypted contentkey
- The password- Returns:
- An unencrypted version of the content
-
encrypt
public String encrypt(@NonNull @lombok.NonNull byte[] content, @NonNull @lombok.NonNull byte[] key)
Encrypts content into a Base64 encoded string.- Parameters:
content
- The contentkey
- The password- Returns:
- A Base64 encoded version of the encrypted content
-
encrypt
public final String encrypt(@NonNull @NonNull String content, @NonNull @NonNull String key)
Encrypts content into a Base64 encoded string.- Parameters:
content
- The contentkey
- The password- Returns:
- A Base64 encoded version of the encrypted content
-
ensureKeyLength
protected final byte[] ensureKeyLength(byte[] key)
Ensures the the key is needed length for the encryption method.
- Parameters:
key
- The key- Returns:
- A key of the need length
-
-