public class CryptoUtils
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
CryptoUtils.CipherEngine
The supported symmetric ciphers
|
static class |
CryptoUtils.CipherMode
The supported symmetric ciphers' modes
|
static class |
CryptoUtils.CipherParams
Symmetric cipher parameters
|
| Modifier and Type | Field and Description |
|---|---|
static java.util.Set<java.lang.String> |
CIPHERS
Supported symmetric ciphers' list as Set Please note that ImmutableSet.of()
"preserves order" so the names will be iterated in the order they are
specified below
|
static java.util.Map<java.lang.String,java.util.function.Supplier<org.bouncycastle.crypto.Digest>> |
DIGESTS
Supported PBE hash algorithms
|
| Constructor and Description |
|---|
CryptoUtils() |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
generatePbeKey(byte[] password,
byte[] salt,
java.lang.String digestName,
int rounds)
Generates a password-based encryption key, based on the PKCS#5/RFC 2898 standard
|
static void |
main(java.lang.String... args)
Test encryption/decryption with supported algorithms
|
private static boolean |
test(java.util.Random rnd,
byte[] plainBytes,
CryptoUtils.CipherParams cp)
Test encryption/decryption for a particular cipher
|
private static void |
testAll(java.lang.String plain)
Test encryption/decryption for all supported ciphers
|
public static final java.util.Set<java.lang.String> CIPHERS
public static final java.util.Map<java.lang.String,java.util.function.Supplier<org.bouncycastle.crypto.Digest>> DIGESTS
public static byte[] generatePbeKey(byte[] password,
byte[] salt,
java.lang.String digestName,
int rounds)
throws java.security.NoSuchAlgorithmException
password - passwordsalt - optional saltdigestName - a name of the hash algorithmrounds - a number of roundsjava.security.NoSuchAlgorithmExceptionpublic static void main(java.lang.String... args)
throws java.lang.Exception
args - command line argsjava.lang.Exceptionprivate static void testAll(java.lang.String plain)
throws java.lang.Exception
plain - string to be encryptedjava.lang.Exceptionprivate static boolean test(java.util.Random rnd,
byte[] plainBytes,
CryptoUtils.CipherParams cp)
throws java.security.NoSuchAlgorithmException,
java.security.NoSuchProviderException,
javax.crypto.NoSuchPaddingException,
java.security.InvalidKeyException,
java.security.InvalidAlgorithmParameterException,
javax.crypto.IllegalBlockSizeException,
javax.crypto.BadPaddingException
rnd - Random generatorplainBytes - bytes to be encryptedcp - cipher parameterstrue if operation succeeded or false
otherwisejava.security.NoSuchAlgorithmExceptionjava.security.NoSuchProviderExceptionjavax.crypto.NoSuchPaddingExceptionjava.security.InvalidKeyExceptionjava.security.InvalidAlgorithmParameterExceptionjavax.crypto.IllegalBlockSizeExceptionjavax.crypto.BadPaddingException