Class Crypto

java.lang.Object
com.tridion.crypto.Crypto

public final class Crypto extends Object
Generic cryptography implementation.
  • Constructor Details

    • Crypto

      public Crypto()
      Construct a Crypto instance with the default encryption provider.
    • Crypto

      public Crypto(KeyProvider keyProvider)
      Construct a Crypto instance with the given encryption provider.
      Parameters:
      keyProvider - The encryption provider to use.
  • Method Details

    • encrypt

      public String encrypt(String secret) throws GeneralSecurityException
      Encrypt the provided secret.
      Parameters:
      secret - The password or other secret to encrypt.
      Returns:
      The encrypted version of the input.
      Throws:
      GeneralSecurityException - If something goes wrong with the encryption (wrong key size/algorithm/etc).
    • decrypt

      public String decrypt(String secret) throws GeneralSecurityException
      Decrypts the provided secret.
      Parameters:
      secret - The password or other secret to decrypt.
      Returns:
      The decrypted version of the input.
      Throws:
      GeneralSecurityException - If something goes wrong with the encryption (wrong key size/algorithm/etc).
    • decryptIfNecessary

      public static String decryptIfNecessary(String value) throws GeneralSecurityException
      Tries to decrypt the value if and only if this is necessary. This is, the value starts with ENCRYPTED_PREFIX and has at least one character after.
      Parameters:
      value - value to be processed.
      Returns:
      decrypted value.
      Throws:
      GeneralSecurityException - in case of decryption error.