Class CredentialEncrypter


  • public class CredentialEncrypter
    extends java.lang.Object
    Utility 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 by encryptBytes(byte[]).
      java.lang.String decryptString​(java.lang.String encryptedCredentials)
      Recovers the plaintext String from the encrypted value returned by encryptString(String).
      java.lang.String encryptBytes​(byte[] credentials)
      Encrypts a byte array and returns a string representation of the encrypted value.
      java.lang.String encryptString​(java.lang.String credentials)
      Encrypts a String and returns a string representation of the encrypted value.
      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.
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 using decryptBytes(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 using decryptString(String).
      • decryptBytes

        public byte[] decryptBytes​(java.lang.String encryptedCredentials)
        Recovers the plaintext bytes from the encrypted value returned by encryptBytes(byte[]).
      • decryptString

        public java.lang.String decryptString​(java.lang.String encryptedCredentials)
        Recovers the plaintext String from the encrypted value returned by encryptString(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.