Class StringEncrypter


  • public class StringEncrypter
    extends java.lang.Object
    Encrypts and decrypts string using Java Cryptography Extension (JCE)
    Author:
    Javid Jamae - http://www.devx.com/Java/10MinuteSolution/21385
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  StringEncrypter.EncryptionException
      Exception Wrapper for any error that might occur during the encryption or decryption process.
    • Constructor Summary

      Constructors 
      Constructor Description
      StringEncrypter​(java.lang.String encryptionScheme, java.lang.String encryptionKey)
      Create a new StringEncrypter using the specified encryption scheme and key.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String decrypt​(java.lang.String encryptedString)
      Decrypt the specified string using this StringEncrypter.
      java.lang.String encrypt​(java.lang.String unencryptedString)
      Encrypt the specified string using this StringEncrypter.
      • Methods inherited from class java.lang.Object

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

      • DESEDE_ENCRYPTION_SCHEME

        public static final java.lang.String DESEDE_ENCRYPTION_SCHEME
        DES3 (DESede) encryption scheme.
        See Also:
        Constant Field Values
      • DES_ENCRYPTION_SCHEME

        public static final java.lang.String DES_ENCRYPTION_SCHEME
        DES encryption scheme.
        See Also:
        Constant Field Values
    • Constructor Detail

      • StringEncrypter

        public StringEncrypter​(java.lang.String encryptionScheme,
                               java.lang.String encryptionKey)
                        throws StringEncrypter.EncryptionException
        Create a new StringEncrypter using the specified encryption scheme and key.
        Parameters:
        encryptionScheme - an encryption scheme from one of the following : DESEDE_ENCRYPTION_SCHEME or DES_ENCRYPTION_SCHEME
        encryptionKey - the key to use for the encrypter, must be a valid string of 24 or more characters, must not be null.
        Throws:
        java.lang.IllegalArgumentException - if encryptionKey is null or less than 24 characters
        StringEncrypter.EncryptionException
    • Method Detail

      • encrypt

        public java.lang.String encrypt​(java.lang.String unencryptedString)
                                 throws StringEncrypter.EncryptionException
        Encrypt the specified string using this StringEncrypter.
        Parameters:
        unencryptedString - the string to encrypt, must not be null or empty.
        Returns:
        the encrypted string.
        Throws:
        java.lang.IllegalArgumentException - if unencryptedString is null or empty
        StringEncrypter.EncryptionException
      • decrypt

        public java.lang.String decrypt​(java.lang.String encryptedString)
                                 throws StringEncrypter.EncryptionException
        Decrypt the specified string using this StringEncrypter.
        Parameters:
        encryptedString - the string to decrypt, must not be null or empty.
        Returns:
        the decrypted string.
        Throws:
        java.lang.IllegalArgumentException - if encryptedString is null or empty
        StringEncrypter.EncryptionException