Class Default1Cipher

  • All Implemented Interfaces:
    ICipher

    public class Default1Cipher
    extends java.lang.Object
    implements ICipher
    A default AES (GCM Mode) Cipher. AES is a 128-bit block cipher supporting keys of 128, 192, and 256 bits. The constructors do not check if key provided as parameter indeed specifies a valid AES key. It does not check key size, nor does it check for weak or sem-weak keys. Note: If you want to use Key > 128 bits then you need to install Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy files.
    • Constructor Summary

      Constructors 
      Constructor Description
      Default1Cipher​(byte[] encryptionKey)
      Creates a new default cipher using 'UTF-8' encoding and key.
      Default1Cipher​(byte[] encryptionKey, java.nio.charset.Charset charset)
      Creates a new default cipher with the specified charset encoding and key.
      Default1Cipher​(java.lang.String base64CodedEncryptionKey)
      Creates a new default cipher using 'UTF-8' encoding, with a base64-encoded key.
      Default1Cipher​(java.lang.String base64CodedEncryptionKey, java.nio.charset.Charset charset)
      Creates a new default cipher with the specified charset encoding, with a base64-encoded key.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String decrypt​(java.lang.String cipherText)
      A method to decrypt the provided cipher text.
      java.lang.String encrypt​(java.lang.String plainText)
      This method is used to encrypt(Symmetric) plainText coming in input using AES algorithm
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Default1Cipher

        public Default1Cipher​(java.lang.String base64CodedEncryptionKey)
                       throws java.security.GeneralSecurityException
        Creates a new default cipher using 'UTF-8' encoding, with a base64-encoded key.
        Parameters:
        base64CodedEncryptionKey - A base 64 encoded symmetric key to be used during encryption and decryption.
        Throws:
        java.security.GeneralSecurityException - a general security exception
      • Default1Cipher

        public Default1Cipher​(byte[] encryptionKey)
                       throws java.security.GeneralSecurityException
        Creates a new default cipher using 'UTF-8' encoding and key.
        Parameters:
        encryptionKey - A symmetric key to be used during encryption and decryption.
        Throws:
        java.security.GeneralSecurityException - a general security exception
      • Default1Cipher

        public Default1Cipher​(java.lang.String base64CodedEncryptionKey,
                              java.nio.charset.Charset charset)
                       throws java.security.GeneralSecurityException
        Creates a new default cipher with the specified charset encoding, with a base64-encoded key.
        Parameters:
        base64CodedEncryptionKey - A base 64 encoded symmetric key to be used during encryption and decryption.
        charset - The charset to be considered when encrypting plaintext or decrypting ciphertext.
        Throws:
        java.security.GeneralSecurityException - a general security exception
      • Default1Cipher

        public Default1Cipher​(byte[] encryptionKey,
                              java.nio.charset.Charset charset)
                       throws java.security.GeneralSecurityException
        Creates a new default cipher with the specified charset encoding and key.
        Parameters:
        encryptionKey - A symmetric key to be used during encryption and decryption.
        charset - The charset to be considered when encrypting plaintext or decrypting ciphertext.
        Throws:
        java.security.GeneralSecurityException - a general security exception
    • Method Detail

      • encrypt

        public java.lang.String encrypt​(java.lang.String plainText)
        This method is used to encrypt(Symmetric) plainText coming in input using AES algorithm
        Specified by:
        encrypt in interface ICipher
        Parameters:
        plainText - the plain text string to be encrypted
        Returns:
        Base64 encoded AES encrypted cipher text
      • decrypt

        public java.lang.String decrypt​(java.lang.String cipherText)
        A method to decrypt the provided cipher text.
        Specified by:
        decrypt in interface ICipher
        Parameters:
        cipherText - AES encrypted cipherText
        Returns:
        decrypted text