Class CryptoUtil


  • public class CryptoUtil
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      CryptoUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void decryptFields​(java.lang.Object object, CollectionMetaData cmd, ICipher cipher)
      A utility method to decrypt the value of field marked by the @Secret annotation using its setter/mutator method.
      static void encryptFields​(java.lang.Object object, CollectionMetaData cmd, ICipher cipher)
      A utility method to encrypt the value of field marked by the @Secret annotation using its setter/mutator method.
      static java.lang.String generate128BitKey​(java.lang.String password, java.lang.String salt)
      Utility method to help generate a strong 128 bit Key to be used for the DefaultAESCBCCipher.
      • Methods inherited from class java.lang.Object

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

      • CryptoUtil

        public CryptoUtil()
    • Method Detail

      • encryptFields

        public static void encryptFields​(java.lang.Object object,
                                         CollectionMetaData cmd,
                                         ICipher cipher)
                                  throws java.lang.IllegalAccessException,
                                         java.lang.IllegalArgumentException,
                                         java.lang.reflect.InvocationTargetException
        A utility method to encrypt the value of field marked by the @Secret annotation using its setter/mutator method.
        Parameters:
        object - the actual Object representing the POJO we want the Id of.
        cmd - the CollectionMetaData object from which we can obtain the list containing names of fields which have the @Secret annotation
        cipher - the actual cipher implementation to use
        Throws:
        java.lang.IllegalAccessException - Error when invoking method for a @Secret annotated field due to permissions
        java.lang.IllegalArgumentException - Error when invoking method for a @Secret annotated field due to wrong arguments
        java.lang.reflect.InvocationTargetException - Error when invoking method for a @Secret annotated field, the method threw a exception
      • decryptFields

        public static void decryptFields​(java.lang.Object object,
                                         CollectionMetaData cmd,
                                         ICipher cipher)
                                  throws java.lang.IllegalAccessException,
                                         java.lang.IllegalArgumentException,
                                         java.lang.reflect.InvocationTargetException
        A utility method to decrypt the value of field marked by the @Secret annotation using its setter/mutator method.
        Parameters:
        object - the actual Object representing the POJO we want the Id of.
        cmd - the CollectionMetaData object from which we can obtain the list containing names of fields which have the @Secret annotation
        cipher - the actual cipher implementation to use
        Throws:
        java.lang.IllegalAccessException - Error when invoking method for a @Secret annotated field due to permissions
        java.lang.IllegalArgumentException - Error when invoking method for a @Secret annotated field due to wrong arguments
        java.lang.reflect.InvocationTargetException - Error when invoking method for a @Secret annotated field, the method threw a exception
      • generate128BitKey

        public static java.lang.String generate128BitKey​(java.lang.String password,
                                                         java.lang.String salt)
                                                  throws java.security.NoSuchAlgorithmException,
                                                         java.io.UnsupportedEncodingException,
                                                         java.security.spec.InvalidKeySpecException
        Utility method to help generate a strong 128 bit Key to be used for the DefaultAESCBCCipher. Note: This function is only provided as a utility to generate strong password it should be used statically to generate a key and then the key should be captured and used in your program. This function defaults to using 65536 iterations and 128 bits for key size. If you wish to use 256 bits key size then ensure that you have Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy installed and change the last argument to PBEKeySpec below to 256
        Parameters:
        password - A password which acts as a seed for generation of the key
        salt - A salt used in combination with the password for the generation of the key
        Returns:
        A Base64 Encoded string representing the 128 bit key
        Throws:
        java.security.NoSuchAlgorithmException - if the KeyFactory algorithm is not found in available crypto providers
        java.io.UnsupportedEncodingException - if the char encoding of the salt is not known.
        java.security.spec.InvalidKeySpecException - invalid generated key