Class AesEncrypter

  • All Implemented Interfaces:
    Encrypter

    public class AesEncrypter
    extends java.lang.Object
    implements Encrypter
    AES encrypter implementation.
    • Constructor Summary

      Constructors 
      Constructor Description
      AesEncrypter​(java.lang.String algorithm, javax.crypto.SecretKey encryptionKey)
      Creates an encrypter for the specified key using specific encryption algorithms.
      AesEncrypter​(javax.crypto.SecretKey encryptionKey)
      Creates an encrypter for the specified key using default encryption algorithms.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String encrypt​(java.lang.String text)
      Encrypts the specified text using a symmetric key.
      java.lang.String getAlgorithm()
      Returns the algorithm name of the encrypter.
      • Methods inherited from class java.lang.Object

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

      • AesEncrypter

        public AesEncrypter​(javax.crypto.SecretKey encryptionKey)
        Creates an encrypter for the specified key using default encryption algorithms.
        Parameters:
        encryptionKey - the public key to be used for encryption
      • AesEncrypter

        public AesEncrypter​(java.lang.String algorithm,
                            javax.crypto.SecretKey encryptionKey)
        Creates an encrypter for the specified key using specific encryption algorithms.
        Parameters:
        algorithm - the encryption algorithm
        encryptionKey - the public key to be used for encryption
    • Method Detail

      • getAlgorithm

        public java.lang.String getAlgorithm()
        Description copied from interface: Encrypter
        Returns the algorithm name of the encrypter.
        Specified by:
        getAlgorithm in interface Encrypter
        Returns:
        the name of the algorithm
      • encrypt

        public java.lang.String encrypt​(java.lang.String text)
        Encrypts the specified text using a symmetric key. The produced ciphertext is prepended with the IV used by the encrypter.

        The data is represented in the following format:
        [iv size] [tag size] [iv data] [ciphertext]
        1. The first byte is the size of the iv;
        2. followed by the iv data of the size from #1;
        3. then followed by the ciphertext bytes.

        Specified by:
        encrypt in interface Encrypter
        Parameters:
        text - the text to be encrypted
        Returns:
        ciphertext