Package io.jsondb.crypto
Class CryptoUtil
- java.lang.Object
-
- io.jsondb.crypto.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 voiddecryptFields(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 voidencryptFields(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.Stringgenerate128BitKey(java.lang.String password, java.lang.String salt)Utility method to help generate a strong 128 bit Key to be used for the DefaultAESCBCCipher.
-
-
-
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.InvocationTargetExceptionA 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 annotationcipher- the actual cipher implementation to use- Throws:
java.lang.IllegalAccessException- Error when invoking method for a @Secret annotated field due to permissionsjava.lang.IllegalArgumentException- Error when invoking method for a @Secret annotated field due to wrong argumentsjava.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.InvocationTargetExceptionA 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 annotationcipher- the actual cipher implementation to use- Throws:
java.lang.IllegalAccessException- Error when invoking method for a @Secret annotated field due to permissionsjava.lang.IllegalArgumentException- Error when invoking method for a @Secret annotated field due to wrong argumentsjava.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.InvalidKeySpecExceptionUtility 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 toPBEKeySpecbelow to 256- Parameters:
password- A password which acts as a seed for generation of the keysalt- 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 providersjava.io.UnsupportedEncodingException- if the char encoding of the salt is not known.java.security.spec.InvalidKeySpecException- invalid generated key
-
-