Class AsymmetricCipher

  • All Implemented Interfaces:
    CommonCipher

    public class AsymmetricCipher
    extends Object
    implements CommonCipher
    This class provides simple and stateless way to encrypt and decrypt messages using selected asymmetric cipher.
    It requires to have a PrivateKey provided for decryption purposes and a PublicKey for encryption purposes.
    • Field Detail

      • ALGORITHM_RSA_ECB_OAEP_MD5

        @Deprecated
        public static final String ALGORITHM_RSA_ECB_OAEP_MD5
        Deprecated.
        It is strongly recommended not to use this algorithm as stated here RFC6151 - 2.
        RSA cipher with ECB method using optimal asymmetric encryption padding with MD5 and MGF1.
        Value is: "RSA/ECB/OAEPWithMD5AndMGF1Padding".
        See Also:
        Constant Field Values
      • ALGORITHM_RSA_ECB_OAEP_SHA1

        public static final String ALGORITHM_RSA_ECB_OAEP_SHA1
        RSA cipher with ECB method using optimal asymmetric encryption padding with SHA1 and MGF1.
        Value is: "RSA/ECB/OAEPWithSHA1AndMGF1Padding".
        See Also:
        Constant Field Values
      • ALGORITHM_RSA_ECB_OAEP256

        public static final String ALGORITHM_RSA_ECB_OAEP256
        RSA cipher with ECB method using optimal asymmetric encryption padding with SHA-256 and MGF1.
        Value is: "RSA/ECB/OAEPWithSHA-256AndMGF1Padding".
        See Also:
        Constant Field Values
      • ALGORITHM_RSA_ECB_OAEP384

        public static final String ALGORITHM_RSA_ECB_OAEP384
        RSA cipher with ECB method using optimal asymmetric encryption padding with SHA-384 and MGF1.
        Value is: "RSA/ECB/OAEPWithSHA-384AndMGF1Padding".
        See Also:
        Constant Field Values
      • ALGORITHM_RSA_ECB_OAEP512_224

        public static final String ALGORITHM_RSA_ECB_OAEP512_224
        RSA cipher with ECB method using optimal asymmetric encryption padding with SHA-512/224 and MGF1.
        Value is: "RSA/ECB/OAEPWithSHA-512/224AndMGF1Padding".
        See Also:
        Constant Field Values
      • ALGORITHM_RSA_ECB_OAEP512_256

        public static final String ALGORITHM_RSA_ECB_OAEP512_256
        RSA cipher with ECB method using optimal asymmetric encryption padding with SHA-512/256 and MGF1.
        Value is: "RSA/ECB/OAEPWithSHA-512/256AndMGF1Padding".
        See Also:
        Constant Field Values
      • ALGORITHM_RSA_ECB_PKCS1

        public static final String ALGORITHM_RSA_ECB_PKCS1
        RSA cipher with ECB method using PKCS1 padding.
        Value is: "RSA/ECB/PKCS1Padding".
        See Also:
        Constant Field Values
    • Method Detail

      • encrypt

        public static Base64Value encrypt​(String algorithm,
                                          String provider,
                                          PublicKey publicKey,
                                          Base64Value message)
        Encrypt the message with the provided public key and selected algorithm.
        Parameters:
        algorithm - algorithm name
        provider - algorithm provider
        publicKey - public key used for encryption
        message - message to be encrypted
        Returns:
        encrypted message
      • decrypt

        public static Base64Value decrypt​(String algorithm,
                                          String provider,
                                          PrivateKey privateKey,
                                          Base64Value message)
        Decrypt the message with the provided private key and selected algorithm.
        Parameters:
        algorithm - algorithm name
        provider - algorithm provider
        privateKey - private key used for decryption
        message - message to be decrypted
        Returns:
        decrypted message