@Singleton
public class Crypto
extends java.lang.Object
Constructor and Description |
---|
Crypto(play.api.libs.Crypto crypto) |
Modifier and Type | Method and Description |
---|---|
boolean |
compareSignedTokens(java.lang.String tokenA,
java.lang.String tokenB)
Compare two signed tokens
|
boolean |
constantTimeEquals(java.lang.String a,
java.lang.String b)
Constant time equals method.
|
java.lang.String |
decryptAES(java.lang.String value)
Decrypt a String with the AES encryption standard using the application's secret key.
|
java.lang.String |
decryptAES(java.lang.String value,
java.lang.String privateKey)
Decrypt a String with the AES encryption standard.
|
java.lang.String |
encryptAES(java.lang.String value)
Encrypt a String with the AES encryption standard using the application's secret key.
|
java.lang.String |
encryptAES(java.lang.String value,
java.lang.String privateKey)
Encrypt a String with the AES encryption standard and the supplied private key.
|
java.lang.String |
extractSignedToken(java.lang.String token)
Extract a signed token that was signed by
signToken(String) . |
java.lang.String |
generateSignedToken()
Generate a signed token
|
java.lang.String |
generateToken()
Generate a cryptographically secure token
|
java.lang.String |
sign(java.lang.String message)
Signs the given String with HMAC-SHA1 using the application's secret key.
|
java.lang.String |
sign(java.lang.String message,
byte[] key)
Signs the given String with HMAC-SHA1 using the given key.
|
java.lang.String |
signToken(java.lang.String token)
Sign a token.
|
public java.lang.String sign(java.lang.String message, byte[] key)
application.crypto.provider
in application.conf
.message
- The message to sign.key
- The private key to sign with.public java.lang.String sign(java.lang.String message)
application.crypto.provider
in application.conf
.message
- The message to sign.public java.lang.String signToken(java.lang.String token)
token
- The token to signpublic java.lang.String extractSignedToken(java.lang.String token)
signToken(String)
.token
- The signed token to extract.public java.lang.String generateToken()
public java.lang.String generateSignedToken()
public boolean compareSignedTokens(java.lang.String tokenA, java.lang.String tokenB)
public boolean constantTimeEquals(java.lang.String a, java.lang.String b)
public java.lang.String encryptAES(java.lang.String value)
application.crypto.provider
in application.conf
.
AES
name. On
Oracles JDK, this is AES/CTR/NoPadding
. This algorithm is suitable for small amounts of data,
typically less than 32 bytes, hence is useful for encrypting credit card numbers, passwords etc. For larger
blocks of data, this algorithm may expose patterns and be vulnerable to repeat attacks.
application.crypto.aes.transformation
in
application.conf
. Although any cipher transformation algorithm can be selected here, the secret key
spec used is always AES, so only AES transformation algorithms will work.value
- The String to encrypt.public java.lang.String encryptAES(java.lang.String value, java.lang.String privateKey)
application.crypto.provider
in application.conf
.
AES
name. On
Oracles JDK, this is AES/CTR/NoPadding
. This algorithm is suitable for small amounts of data,
typically less than 32bytes, hence is useful for encrypting credit card numbers, passwords etc. For larger
blocks of data, this algorithm may expose patterns and be vulnerable to repeat attacks.
application.crypto.aes.transformation
in
application.conf
. Although any cipher transformation algorithm can be selected here, the secret key
spec used is always AES, so only AES transformation algorithms will work.value
- The String to encrypt.privateKey
- The key used to encrypt.public java.lang.String decryptAES(java.lang.String value)
application.crypto.provider
in application.conf
.
AES/CTR/NoPadding
. It can be configured by defining
application.crypto.aes.transformation
in application.conf
. Although any cipher
transformation algorithm can be selected here, the secret key spec used is always AES, so only AES transformation
algorithms will work.value
- An hexadecimal encrypted string.public java.lang.String decryptAES(java.lang.String value, java.lang.String privateKey)
application.crypto.provider
in application.conf
.
AES/CTR/NoPadding
. It can be configured by defining
application.crypto.aes.transformation
in application.conf
. Although any cipher
transformation algorithm can be selected here, the secret key spec used is always AES, so only AES transformation
algorithms will work.value
- An hexadecimal encrypted string.privateKey
- The key used to encrypt.