Class DataEncryptor

java.lang.Object
com.sun.identity.security.DataEncryptor

@SupportedAll public class DataEncryptor extends Object
This class DataEncryptor is used to encrypt the data with symmetric and asymmetric keys.
  • Constructor Details

    • DataEncryptor

      public DataEncryptor()
  • Method Details

    • encryptWithAsymmetricKey

      public static String encryptWithAsymmetricKey(String data, String encryptionAlgorithm, int encryptionStrength, Key encKey) throws Exception
      Encrypts the given data with an asymmetric key. The asymmetric encryption uses symmetric secret key for data encryption and sends the secret key to the recipient by encrypting the same with given transport key (publick key).
      Parameters:
      data - the data to be encrypted.
      encryptionAlgorithm - the encryption algorithm to be used. The encryption algorithm must be one of the supported algorithm by the underlying JCE encryption provider. Examples of encryption algorithms are "DES", "AES" etc.
      encryptionStrength - the encryption strength for a given encryption algorithm.
      encKey - the encryption key to be used. For PKI, this key should be public key of the intended recipient.
      Returns:
      the encrypted data in Base64 encoded format.
      Throws:
      Exception
    • decryptWithAsymmetricKey

      public static String decryptWithAsymmetricKey(String data, String encAlgorithm, Key encKey) throws Exception
      Decrypts the given data with asymmetric key.
      Parameters:
      data - the data to be decrypted.
      encAlgorithm - the encryption algorithm was used for encrypted data.
      encKey - the private key for decrypting the data.
      Returns:
      the decrypted data.
      Throws:
      Exception
    • encryptWithSymmetricKey

      public static String encryptWithSymmetricKey(String data, String encAlgorithm, String secret) throws Exception
      Encrypts the given data with a symmetric key that was generated using given shared secret.
      Parameters:
      data - the data to be encrypted.
      encAlgorithm - the encryption algorithm to be used. The encryption algorithm must be one of the supported algorithm by the underlying JCE encryption provider. For password based encryptions, the encryption algorithm PBEWithMD5AndDES is commonly used.
      secret - the shared secret to be used for symmetric encryption.
      Returns:
      the encrypted data in Base64 encoded format.
      Throws:
      Exception
    • decryptWithSymmetricKey

      public static String decryptWithSymmetricKey(String data, String encAlgorithm, String secret) throws Exception
      Decrypts the given data with a symmetric key generated using shared secret.
      Parameters:
      data - the data to be decrypted with symmetric key.
      encAlgorithm - the encryption algorithm was used for encrypting the data.
      secret - the shared secret to be used for decrypting the data.
      Returns:
      the decrypted data.
      Throws:
      Exception