Class Crypto


  • public class Crypto
    extends Object
    Convenient class for encryption and decryption
    Author:
    svenkubiak
    • Constructor Detail

      • Crypto

        @Inject
        public Crypto​(Config config)
    • Method Detail

      • decrypt

        public String decrypt​(String encrytedText)
        Decrypts an given encrypted text using the application secret property (application.secret) as key
        Parameters:
        encrytedText - The encrypted text
        Returns:
        The clear text or null if decryption fails
      • decrypt

        public String decrypt​(String encrytedText,
                              String key)
        Decrypts an given encrypted text using the given key
        Parameters:
        encrytedText - The encrypted text
        key - The encryption key
        Returns:
        The clear text or null if decryption fails
      • encrypt

        public String encrypt​(String plainText)
        Encrypts a given plain text using the application secret property (application.secret) as key Encryption is done by using AES and CBC Cipher and a key length of 256 bit
        Parameters:
        plainText - The plain text to encrypt
        Returns:
        The encrypted text or null if encryption fails
      • encrypt

        public String encrypt​(String plainText,
                              String key)
        Encrypts a given plain text using the given key Encryption is done by using AES and CBC Cipher and a key length of 256 bit
        Parameters:
        plainText - The plain text to encrypt
        key - The key to use for encryption
        Returns:
        The encrypted text or null if encryption fails
      • getSizedSecret

        public String getSizedSecret​(String secret)
      • generateKeyPair

        public KeyPair generateKeyPair()
        Generate key which contains a pair of private and public key using 4096 bytes
        Returns:
        key pair
      • getKeyAsString

        public String getKeyAsString​(Key key)
        Convert a Key to string encoded as Base64
        Parameters:
        key - The key (private or public)
        Returns:
        A string representation of the key
      • getPrivateKeyFromString

        public PrivateKey getPrivateKeyFromString​(String key)
                                           throws MangooEncryptionException
        Generates Private Key from Base64 encoded string
        Parameters:
        key - Base64 encoded string which represents the key
        Returns:
        The PrivateKey
        Throws:
        MangooEncryptionException - if getting private key from string fails
      • getPublicKeyFromString

        public PublicKey getPublicKeyFromString​(String key)
                                         throws MangooEncryptionException
        Generates Public Key from Base64 encoded string
        Parameters:
        key - Base64 encoded string which represents the key
        Returns:
        The PublicKey
        Throws:
        MangooEncryptionException - if getting public key from string fails