Package com.bazaarvoice.emodb.auth.util
Class CredentialEncrypter
- java.lang.Object
-
- com.bazaarvoice.emodb.auth.util.CredentialEncrypter
-
public class CredentialEncrypter extends java.lang.ObjectUtility class for encrypting and decrypting credentials. This is useful when credentials need to be explicitly stored somewhere but for security reasons should not be in plain-text, such as in configuration files.
-
-
Constructor Summary
Constructors Constructor Description CredentialEncrypter(byte[] initializationBytes)Creates a new instance initialized from a byte array.CredentialEncrypter(java.lang.String initializationString)Convenience constructor to initialize from a string converted to a UTF-8 byte array.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]decryptBytes(java.lang.String encryptedCredentials)Recovers the plaintext bytes from the encrypted value returned byencryptBytes(byte[]).java.lang.StringdecryptString(java.lang.String encryptedCredentials)Recovers the plaintext String from the encrypted value returned byencryptString(String).java.lang.StringencryptBytes(byte[] credentials)Encrypts a byte array and returns a string representation of the encrypted value.java.lang.StringencryptString(java.lang.String credentials)Encrypts a String and returns a string representation of the encrypted value.static booleanisPotentiallyEncryptedBytes(byte[] bytes)Returns true if the provided bytes _could_ be encrypted credentials, even if they can't be decrypted by a specific instance.static booleanisPotentiallyEncryptedString(java.lang.String string)Returns true if the provided String _could_ be encrypted credentials, even if it can't be decrypted by a specific instance.
-
-
-
Constructor Detail
-
CredentialEncrypter
public CredentialEncrypter(byte[] initializationBytes)
Creates a new instance initialized from a byte array. Two instances created with the same initialization bytes will always produce the same encrypted values when given the same input.
-
CredentialEncrypter
public CredentialEncrypter(java.lang.String initializationString)
Convenience constructor to initialize from a string converted to a UTF-8 byte array.
-
-
Method Detail
-
encryptBytes
public java.lang.String encryptBytes(byte[] credentials)
Encrypts a byte array and returns a string representation of the encrypted value. The original byte array can be recovered usingdecryptBytes(String).
-
encryptString
public java.lang.String encryptString(java.lang.String credentials)
Encrypts a String and returns a string representation of the encrypted value. The original String can be recovered usingdecryptString(String).
-
decryptBytes
public byte[] decryptBytes(java.lang.String encryptedCredentials)
Recovers the plaintext bytes from the encrypted value returned byencryptBytes(byte[]).
-
decryptString
public java.lang.String decryptString(java.lang.String encryptedCredentials)
Recovers the plaintext String from the encrypted value returned byencryptString(String).
-
isPotentiallyEncryptedBytes
public static boolean isPotentiallyEncryptedBytes(byte[] bytes)
Returns true if the provided bytes _could_ be encrypted credentials, even if they can't be decrypted by a specific instance.
-
isPotentiallyEncryptedString
public static boolean isPotentiallyEncryptedString(java.lang.String string)
Returns true if the provided String _could_ be encrypted credentials, even if it can't be decrypted by a specific instance.
-
-