public enum Crypto extends Enum<Crypto>
Cryptography utils. Comes from play!framework under apache license
| Modifier and Type | Class and Description |
|---|---|
static class |
Crypto.HashType
Define a hash type enumeration for strong-typing
|
| Modifier and Type | Method and Description |
|---|---|
static String |
decryptAES(String value,
byte[] privateKey)
Decrypt a String with the AES encryption standard.
|
static String |
decryptAES(String value,
byte[] privateKey,
byte[] salt)
Decrypt a String with the AES encryption standard.
|
static String |
decryptAES(String value,
String privateKey)
Deprecated.
|
static String |
decryptAES(String value,
String privateKey,
String salt)
Deprecated.
|
static String |
encryptAES(String value,
byte[] privateKey)
Encrypt a String with the AES encryption standard.
|
static String |
encryptAES(String value,
byte[] privateKey,
byte[] salt)
Encrypt a String with the AES encryption standard.
|
static String |
encryptAES(String value,
String privateKey)
Deprecated.
|
static String |
encryptAES(String value,
String privateKey,
String salt)
Deprecated.
|
static char[] |
generatePassword() |
static char[] |
generatePassword(char[] ca) |
static char[] |
generatePassword(int len) |
static String |
genRandomDigits()
Generate random digital string of random size range from 4 to 12 inclusive
|
static String |
genRandomDigits(int len)
Generate random digital string with the size specified.
|
static String |
genRandomStr()
Generate random string with random length from 4 to 12 inclusive
|
static String |
genRandomStr(int len)
Generate random String with readable characters.
|
static String |
genSecret()
Generate secret string using 4 bytes
|
static String |
genSecret(int len)
Generate a secret string from random byte array
|
static void |
main(String[] args) |
static char[] |
passwordHash(char[] input)
Create a password hash using the default hashing algorithm
|
static char[] |
passwordHash(char[] input,
Crypto.HashType hashType)
Create a password hash using specific hashing algorithm
|
static String |
passwordHash(String input)
Create a password hash using the default hashing algorithm
|
static String |
passwordHash(String input,
Crypto.HashType hashType)
Create a password hash using specific hashing algorithm
|
static void |
setCryptoService(CryptoService service) |
static String |
sign(String message,
byte[] key)
Sign a message with a key
|
static Crypto |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static Crypto[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static Crypto[] values()
for (Crypto c : Crypto.values()) System.out.println(c);
public static Crypto valueOf(String name)
name - the name of the enum constant to be returned.IllegalArgumentException - if this enum type has no constant with the specified nameNullPointerException - if the argument is nullpublic static void setCryptoService(CryptoService service)
public static char[] generatePassword()
public static char[] generatePassword(int len)
public static char[] generatePassword(char[] ca)
public static String sign(String message, byte[] key)
Sign a message with a key
message - The message to signkey - The key to usepublic static String passwordHash(String input)
Create a password hash using the default hashing algorithm
input - The passwordpublic static String passwordHash(String input, Crypto.HashType hashType)
Create a password hash using specific hashing algorithm
input - The passwordhashType - The hashing algorithmpublic static char[] passwordHash(char[] input)
Create a password hash using the default hashing algorithm
input - The passwordpublic static char[] passwordHash(char[] input,
Crypto.HashType hashType)
Create a password hash using specific hashing algorithm
input - The passwordhashType - The hashing algorithm@Deprecated public static String encryptAES(String value, String privateKey)
This method is deprecated. Please use encryptAES(String, byte[]) instead
Encrypt a String with the AES encryption standard. Private key must have a length of 16 bytes
value - The String to encryptprivateKey - The key used to encryptpublic static String encryptAES(String value, byte[] privateKey)
Encrypt a String with the AES encryption standard. Private key must have a length of 16 bytes
value - The String to encryptprivateKey - The key used to encrypt@Deprecated public static String encryptAES(String value, String privateKey, String salt)
This method is deprecated, please use encryptAES(String, byte[]) instead
Encrypt a String with the AES encryption standard. Private key must have a length of 16 bytes
value - The String to encryptprivateKey - The key used to encryptsalt - The saltpublic static String encryptAES(String value, byte[] privateKey, byte[] salt)
Encrypt a String with the AES encryption standard. Private key must have a length of 16 bytes
value - The String to encryptprivateKey - The key used to encryptsalt - The salt@Deprecated public static String decryptAES(String value, String privateKey)
This method is deprecated. please use decryptAES(String, byte[]) instead
Decrypt a String with the AES encryption standard. Private key must have a length of 16 bytes
value - An hexadecimal encrypted stringprivateKey - The key used to encryptpublic static String decryptAES(String value, byte[] privateKey)
Decrypt a String with the AES encryption standard. Private key must have a length of 16 bytes
value - An hexadecimal encrypted stringprivateKey - The key used to encrypt@Deprecated public static String decryptAES(String value, String privateKey, String salt)
This method is deprecated. please use decryptAES(String, byte[], byte[]) instead
Decrypt a String with the AES encryption standard. Private key must have a length of 16 bytes
value - An hexadecimal encrypted stringprivateKey - The key used to encryptsalt - the saltpublic static String decryptAES(String value, byte[] privateKey, byte[] salt)
Decrypt a String with the AES encryption standard. Private key must have a length of 16 bytes
value - An hexadecimal encrypted stringprivateKey - The key used to encryptsalt - the saltpublic static String genSecret(int len)
Generate a secret string from random byte array
len - the number of bytes used to generate the secretpublic static String genSecret()
Generate secret string using 4 bytes
public static String genRandomDigits(int len)
Generate random digital string with the size specified. The method use the SecureRandom
len - the number of digits in the string generatedpublic static String genRandomDigits()
Generate random digital string of random size range from 4 to 12 inclusive
genRandomDigits(int)public static String genRandomStr(int len)
Generate random String with readable characters. This method will use the SecureRandom
len - the size of the string returnedpublic static String genRandomStr()
Generate random string with random length from 4 to 12 inclusive
genRandomStr(int)public static void main(String[] args)
Copyright © 2014–2019 OSGL (Open Source General Library). All rights reserved.