nu.studer.gradle.credentials.domain
Class Encryption

java.lang.Object
  extended by nu.studer.gradle.credentials.domain.Encryption

public final class Encryption
extends java.lang.Object

Encryption/decryption of text using ciphers.

Note: The author of this class is by far not a security expert. The chosen implementation has been primarily gathered from examples in the javax.crypto Javadoc and from discussions on StackOverflow.

See also here for a more detailed explanation on the selected security algorithms.


Constructor Summary
Encryption(javax.crypto.Cipher ecipher, javax.crypto.Cipher dcipher)
           
 
Method Summary
static Encryption createEncryption(char[] passphrase)
          Creates a new Encryption instance that uses password-based encryption (PBE).
 java.lang.String decrypt(java.lang.String string)
          Decrypts the given text.
 java.lang.String encrypt(java.lang.String string)
          Encrypts the given text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Encryption

public Encryption(javax.crypto.Cipher ecipher,
                  javax.crypto.Cipher dcipher)
           throws java.security.GeneralSecurityException
Throws:
java.security.GeneralSecurityException
Method Detail

encrypt

public java.lang.String encrypt(java.lang.String string)
Encrypts the given text.

Parameters:
string - the text to encrypt
Returns:
the encrypted text

decrypt

public java.lang.String decrypt(java.lang.String string)
Decrypts the given text.

Parameters:
string - the text to decrypt
Returns:
the decrypted text

createEncryption

public static Encryption createEncryption(char[] passphrase)
Creates a new Encryption instance that uses password-based encryption (PBE). The algorithm used to create the secret key is PBEWithMD5AndDES.

Parameters:
passphrase - the passphrase to apply when creating the secret key
Returns:
the new Encryption instance
Throws:
java.lang.RuntimeException - with wrapped GeneralSecurityException in case of crypto-related exceptions