- All Implemented Interfaces:
Serializable
,Comparable<HashedKey.Algorithm>
- Enclosing class:
HashedKey
- See Also:
-
Enum Constant Summary
Enum ConstantDescriptionDeprecated.MD5 should not be used for any cryptographic purpose.Deprecated.SHA-1 should no longer be used for any cryptographic purpose.Deprecated.Collision resistance of at least 128 bits is requiredDeprecated.Collision resistance of at least 128 bits is requiredDeprecated.Collision resistance of at least 128 bits is required -
Method Summary
Modifier and TypeMethodDescriptionstatic HashedKey.Algorithm
findAlgorithm
(String algorithmName) Case-insensitive lookup by algorithm name.Generates a random plaintext key ofgetKeyBytes()
bytes in length using a defaultSecureRandom
instance, which is not a strong instance to avoid blocking.generateKey
(SecureRandom secureRandom) Generates a random plaintext key ofgetKeyBytes()
bytes in length using the providedSecureRandom
source.generateKey
(Random random) Deprecated.Please useSecureRandom
.Gets theMessageDigest
algorithm name.int
Gets the number of bytes required to store the generated hash.int
Gets the number of bytes of cryptographically strong random data that must be used with this algorithm.byte[]
hash
(byte[] key) Deprecated.Please usehash(com.aoapps.security.Key)
instead.byte[]
Hashes the given key.toString()
<Ex extends Throwable>
byte[]validateHash
(Function<? super String, Ex> newThrowable, byte[] hash) <Ex extends Throwable>
byte[]validateKey
(Function<? super String, Ex> newThrowable, byte[] key) Deprecated.Please usevalidateKey(java.util.function.Function, com.aoapps.security.Key)
instead.validateKey
(Function<? super String, Ex> newThrowable, Key key) static HashedKey.Algorithm
Returns the enum constant of this type with the specified name.static HashedKey.Algorithm[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
MD5
Deprecated.MD5 should not be used for any cryptographic purpose. -
SHA_1
Deprecated.SHA-1 should no longer be used for any cryptographic purpose.SHA-1 is now considered to have at best 65-bits of collision resistance, if using SHA-1 (which you shouldn't) its key size is correspondingly limited to 128 bits. See: -
SHA_224
Deprecated.Collision resistance of at least 128 bits is required -
SHA_256
-
SHA_384
-
SHA_512
-
SHA_512_224
Deprecated.Collision resistance of at least 128 bits is required -
SHA_512_256
-
SHA3_224
Deprecated.Collision resistance of at least 128 bits is required -
SHA3_256
-
SHA3_384
-
SHA3_512
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
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
-
findAlgorithm
public static HashedKey.Algorithm findAlgorithm(String algorithmName) throws IllegalArgumentException Case-insensitive lookup by algorithm name.- Returns:
- The algorithm or
null
whenalgorithmName == null
- Throws:
IllegalArgumentException
- when no enum with the given algorithm name (case-insensitive) is found
-
toString
- Overrides:
toString
in classEnum<HashedKey.Algorithm>
-
getAlgorithmName
Gets theMessageDigest
algorithm name. -
getKeyBytes
public int getKeyBytes()Gets the number of bytes of cryptographically strong random data that must be used with this algorithm. -
validateKey
public <Ex extends Throwable> Key validateKey(Function<? super String, Ex> newThrowable, Key key) throws Ex- Type Parameters:
Ex
- An arbitrary exception type that may be thrown- Parameters:
key
- Is destroyed when invalid- Throws:
Ex
-
validateKey
@Deprecated public <Ex extends Throwable> byte[] validateKey(Function<? super String, Ex> newThrowable, byte[] key) throws ExDeprecated.Please usevalidateKey(java.util.function.Function, com.aoapps.security.Key)
instead.- Type Parameters:
Ex
- An arbitrary exception type that may be thrown- Parameters:
key
- Is not zeroed- Throws:
Ex
-
generateKey
Deprecated.Please useSecureRandom
. This method will stay, but will remain deprecated since it should only be used after careful consideration.Generates a random plaintext key ofgetKeyBytes()
bytes in length using the providedRandom
source.- See Also:
-
generateKey
Generates a random plaintext key ofgetKeyBytes()
bytes in length using the providedSecureRandom
source.- See Also:
-
generateKey
Generates a random plaintext key ofgetKeyBytes()
bytes in length using a defaultSecureRandom
instance, which is not a strong instance to avoid blocking.- See Also:
-
getHashBytes
public int getHashBytes()Gets the number of bytes required to store the generated hash. -
validateHash
public <Ex extends Throwable> byte[] validateHash(Function<? super String, Ex> newThrowable, byte[] hash) throws Ex- Type Parameters:
Ex
- An arbitrary exception type that may be thrown- Throws:
Ex
-
hash
Hashes the given key.- Parameters:
key
- Is destroyed before this method returns. If the original key is needed, pass a clone to this method.- See Also:
-
hash
Deprecated.Please usehash(com.aoapps.security.Key)
instead.Hashes the given key.- Parameters:
key
- Is not zeroed- See Also:
-