Class AESEncrypter


  • public class AESEncrypter
    extends java.lang.Object
    This utility class can be used to encrypt and decrypt data using the AES encryption algorithm.
    • Constructor Summary

      Constructors 
      Constructor Description
      AESEncrypter()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static dev.netcode.util.Result<java.lang.String> decrypt​(java.lang.String message, java.lang.String password)
      Decrypts a message using a given password and returns it as String.
      static dev.netcode.util.Result<java.lang.String> encrypt​(java.lang.String message, java.lang.String password)
      Encrypts a message using a given password and returns it as Base64 encrypted String.
      static javax.crypto.spec.SecretKeySpec getKey​(java.lang.String password)
      Generates a SecretKeySpec from a password to be used for AES encryption
      • Methods inherited from class java.lang.Object

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

      • AESEncrypter

        public AESEncrypter()
    • Method Detail

      • getKey

        public static javax.crypto.spec.SecretKeySpec getKey​(java.lang.String password)
        Generates a SecretKeySpec from a password to be used for AES encryption
        Parameters:
        password - to generate the SecretKeySpec for
        Returns:
        the generated SecretKeySpec
      • encrypt

        public static dev.netcode.util.Result<java.lang.String> encrypt​(java.lang.String message,
                                                                        java.lang.String password)
        Encrypts a message using a given password and returns it as Base64 encrypted String. For encryption the cipher instance of AES/ECB/PKCS5PADDING is used
        Parameters:
        message - to be encrypted
        password - to be used to encrypt the message
        Returns:
        encrypted message wrapped inside Result
      • decrypt

        public static dev.netcode.util.Result<java.lang.String> decrypt​(java.lang.String message,
                                                                        java.lang.String password)
        Decrypts a message using a given password and returns it as String. It is assumed that the message is encrypted using AES/ECB/PKCS5PADDING and transformed to Base64.
        Parameters:
        message - to be decrypted
        password - to be used to decrypt the message
        Returns:
        decrypted message wrapped inside Result