public class CryptoServiceSingleton extends Object implements org.wisdom.api.crypto.Crypto
crypto.default.hash: the default Hash algorithm among SHA1, SHA-256, SHA-512 and MD5 (default).aes.key.size: the key size used in AES with CBC methods. 128 is used by default. Be aware
the 256+ keys require runtime adaption because of legal limitations (see unlimited crypto package JCE)aes.iterations: the number of iterations used to generate the key (20 by default)| Modifier and Type | Field and Description |
|---|---|
static String |
AES_CBC_ALGORITHM |
static String |
AES_ECB_ALGORITHM |
private org.wisdom.api.crypto.Hash |
defaultHash |
static String |
HMAC_SHA_1 |
private int |
iterationCount |
private int |
keySize |
static String |
PBKDF_2_WITH_HMAC_SHA_1 |
private String |
secret |
private static Charset |
UTF_8 |
| Constructor and Description |
|---|
CryptoServiceSingleton(org.wisdom.api.configuration.ApplicationConfiguration configuration) |
CryptoServiceSingleton(String secret,
org.wisdom.api.crypto.Hash defaultHash,
Integer keySize,
Integer iterationCount) |
| Modifier and Type | Method and Description |
|---|---|
private boolean |
constantTimeEquals(String a,
String b)
Constant time equals method.
|
byte[] |
decodeBase64(String value)
Decode a base64 value.
|
String |
decryptAES(String value)
Decrypt a String with the standard AES encryption (using the ECB mode) using the default secret (the
application secret).
|
String |
decryptAES(String value,
String privateKey)
Decrypt a String with the standard AES encryption (using the ECB mode).
|
String |
decryptAESWithCBC(String value,
String salt)
Decrypt a String with the AES encryption advanced using 'AES/CBC/PKCS5Padding'.
|
String |
decryptAESWithCBC(String value,
String privateKey,
String salt,
String iv)
Decrypt a String with the AES encryption advanced using 'AES/CBC/PKCS5Padding'.
|
private byte[] |
doFinal(int encryptMode,
SecretKey generatedKey,
String vector,
byte[] message)
Utility method encrypting/decrypting the given message.
|
String |
encodeBase64(byte[] value)
Encode binary data to base64.
|
String |
encryptAES(String value)
Encrypt a String with the AES standard encryption (using the ECB mode) using the default secret (the
application secret).
|
String |
encryptAES(String value,
String privateKey)
Encrypt a String with the AES standard encryption (using the ECB mode).
|
String |
encryptAESWithCBC(String value,
String salt)
Encrypt a String with the AES encryption advanced using 'AES/CBC/PKCS5Padding'.
|
String |
encryptAESWithCBC(String value,
String privateKey,
String salt,
String iv)
Encrypt a String with the AES encryption advanced using 'AES/CBC/PKCS5Padding'.
|
String |
extractSignedToken(String token)
Extract a signed token that was signed by
signToken(String). |
private SecretKey |
generateAESKey(String privateKey,
String salt)
Generate the AES key from the salt and the private key.
|
private String |
getDefaultIV()
Gets a segment of the application secret of 16 characters and encoded them in hexadecimal.
|
private String |
getSecretPrefix()
Gets the 16 first characters of the application secret.
|
String |
hash(String input)
Create a hash using the default hashing algorithm.
|
String |
hash(String input,
org.wisdom.api.crypto.Hash hashType)
Create a hash using specific hashing algorithm.
|
String |
hexMD5(String value)
Build an hexadecimal MD5 hash for a String.
|
String |
hexSHA1(String value)
Build an hexadecimal SHA1 hash for a String.
|
String |
sign(String message)
Sign a message using the application secret key (HMAC-SHA1).
|
String |
sign(String message,
byte[] key)
Sign a message with a key.
|
String |
signToken(String token)
Sign a token.
|
public static final String AES_CBC_ALGORITHM
public static final String AES_ECB_ALGORITHM
private static final Charset UTF_8
public static final String HMAC_SHA_1
public static final String PBKDF_2_WITH_HMAC_SHA_1
private int keySize
private int iterationCount
private org.wisdom.api.crypto.Hash defaultHash
private final String secret
public CryptoServiceSingleton(org.wisdom.api.configuration.ApplicationConfiguration configuration)
private SecretKey generateAESKey(String privateKey, String salt)
salt - the salt (hexadecimal)privateKey - the private keypublic String encryptAESWithCBC(String value, String salt)
encryptAESWithCBC in interface org.wisdom.api.crypto.Cryptovalue - The message to encryptsalt - The salt (hexadecimal String)public String encryptAESWithCBC(String value, String privateKey, String salt, String iv)
encryptAESWithCBC in interface org.wisdom.api.crypto.Cryptovalue - The message to encryptprivateKey - The private keysalt - The salt (hexadecimal String)iv - The initialization vector (hexadecimal String)public String decryptAESWithCBC(String value, String salt)
decryptAESWithCBC in interface org.wisdom.api.crypto.Cryptovalue - An encrypted String encoded using Base64.salt - The salt (hexadecimal String)public String decryptAESWithCBC(String value, String privateKey, String salt, String iv)
decryptAESWithCBC in interface org.wisdom.api.crypto.Cryptovalue - An encrypted String encoded using Base64.privateKey - The private keysalt - The salt (hexadecimal String)iv - The initialization vector (hexadecimal String)private byte[] doFinal(int encryptMode,
SecretKey generatedKey,
String vector,
byte[] message)
encryptMode - encrypt or decrypt mode (Cipher.DECRYPT_MODE or
Cipher.ENCRYPT_MODE).generatedKey - the generated keyvector - the initialization vectormessage - the plain/cipher text to encrypt/decryptpublic String sign(String message)
sign in interface org.wisdom.api.crypto.Cryptopublic String sign(String message, byte[] key)
sign in interface org.wisdom.api.crypto.Cryptomessage - The message to signkey - The key to usepublic String hash(String input)
hash in interface org.wisdom.api.crypto.Cryptoinput - The passwordpublic String hash(String input, org.wisdom.api.crypto.Hash hashType)
hash in interface org.wisdom.api.crypto.Cryptoinput - The passwordhashType - The hashing algorithmpublic String encryptAES(String value)
encryptAES in interface org.wisdom.api.crypto.Cryptovalue - The String to encryptpublic String encryptAES(String value, String privateKey)
encryptAES in interface org.wisdom.api.crypto.Cryptovalue - The String to encryptprivateKey - The key used to encryptpublic String decryptAES(String value)
decryptAES in interface org.wisdom.api.crypto.Cryptovalue - An hexadecimal encrypted stringpublic String decryptAES(String value, String privateKey)
decryptAES in interface org.wisdom.api.crypto.Cryptovalue - An hexadecimal encrypted stringprivateKey - The key used to encryptprivate String getSecretPrefix()
private String getDefaultIV()
public String signToken(String token)
signToken in interface org.wisdom.api.crypto.Cryptotoken - The token to signpublic String extractSignedToken(String token)
signToken(String).extractSignedToken in interface org.wisdom.api.crypto.Cryptotoken - The signed token to extract.private boolean constantTimeEquals(String a, String b)
public String encodeBase64(byte[] value)
encodeBase64 in interface org.wisdom.api.crypto.Cryptovalue - The binary datapublic byte[] decodeBase64(String value)
decodeBase64 in interface org.wisdom.api.crypto.Cryptovalue - The base64 encoded Stringpublic String hexMD5(String value)
hexMD5 in interface org.wisdom.api.crypto.Cryptovalue - The String to hashCopyright © 2013–2014 Wisdom Framework. All rights reserved.