public final class CryptoUtils extends Object
Modifier and Type | Method and Description |
---|---|
static String |
decrypt(String algo,
byte[] secretKey,
byte[] encrypted)
Decrypts a bytes array.
|
static String |
decrypt(String algo,
String base64Secret,
byte[] encrypted)
Decrypts a bytes array.
|
static byte[] |
encrypt(String algo,
byte[] secretKey,
String content)
Encrypts a content string.
|
static byte[] |
encrypt(String algo,
String base64Secret,
String content)
Encrypts a content string.
|
static String |
makeNonce(String secretKey)
Generates a nonce as recommended in section 3.2.1 of RFC-2617, but
without the ETag field.
|
public static String decrypt(String algo, byte[] secretKey, byte[] encrypted) throws GeneralSecurityException
algo
- The cryptographic algorithm.secretKey
- The cryptographic secret key.encrypted
- The encrypted bytes.GeneralSecurityException
public static String decrypt(String algo, String base64Secret, byte[] encrypted) throws GeneralSecurityException
algo
- The cryptographic algorithm.base64Secret
- The cryptographic secret key, encoded as a Base64 string.encrypted
- The encrypted bytes.GeneralSecurityException
public static byte[] encrypt(String algo, byte[] secretKey, String content) throws GeneralSecurityException
algo
- The cryptographic algorithm.secretKey
- The cryptographic secret key.content
- The content string to encrypt.GeneralSecurityException
public static byte[] encrypt(String algo, String base64Secret, String content) throws GeneralSecurityException
algo
- The cryptographic algorithm.base64Secret
- The cryptographic secret, encoded as a Base64 string.content
- The content string to encrypt.GeneralSecurityException
public static String makeNonce(String secretKey)
Base64.encodeBytes(currentTimeMS + ":"
+ md5String(currentTimeMS + ":" + secretKey))
secretKey
- a secret value known only to the creator of the nonce. It's
inserted into the nonce, and can be used later to validate the
nonce.Copyright © 2005–2016. All rights reserved.