edu.sdsc.inca.util
Class Crypter

java.lang.Object
  extended byedu.sdsc.inca.util.Crypter

public class Crypter
extends java.lang.Object

The Crypter class provides the ability to de/encrypt strings.


Field Summary
protected  javax.crypto.Cipher decipher
           
protected  javax.crypto.Cipher encipher
           
 
Constructor Summary
Crypter(java.lang.String passphrase, java.lang.String algorithm)
          Constructs a Crypter that can de/encrypt strings using a specified passphrase and algorithm.
 
Method Summary
protected  java.lang.String cryptMatchingSubstrings(java.lang.String s, java.util.regex.Pattern p, boolean decrypt)
          Returns a specified string with all substrings that match a specified pattern de/encrypted.
 java.lang.String decrypt(java.lang.String s)
          Returns the decrypted version of a specified string.
 java.lang.String decryptMatchingSubstrings(java.lang.String s, java.util.regex.Pattern p)
          Returns a specified string with all substrings that match a specified pattern decrypted.
 java.lang.String decryptMatchingSubstrings(java.lang.String s, java.lang.String p)
          Returns a specified string with all substrings that match a specified pattern decrypted.
 java.lang.String encrypt(java.lang.String s)
          Returns the encrypted version of a specified string.
 java.lang.String encryptMatchingSubstrings(java.lang.String s, java.util.regex.Pattern p)
          Returns a specified string with all substrings that match a specified pattern encrypted.
 java.lang.String encryptMatchingSubstrings(java.lang.String s, java.lang.String p)
          Returns a specified string with all substrings that match a specified pattern encrypted.
 javax.crypto.Cipher getDecipher()
          Return a cipher that can be used for decryption.
 javax.crypto.Cipher getEncipher()
          Return a cipher that can be used for encryption.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

decipher

protected javax.crypto.Cipher decipher

encipher

protected javax.crypto.Cipher encipher
Constructor Detail

Crypter

public Crypter(java.lang.String passphrase,
               java.lang.String algorithm)
        throws CrypterException
Constructs a Crypter that can de/encrypt strings using a specified passphrase and algorithm. The caller must assure that an installed security provider supports the specified algorithm.

Parameters:
passphrase - the de/encryption passphrase
algorithm - the de/encryption algorithm, e.g., DES
Throws:
CrypterException - if initialization of the ciphers fail
Method Detail

decrypt

public java.lang.String decrypt(java.lang.String s)
                         throws CrypterException
Returns the decrypted version of a specified string.

Parameters:
s - the string to decrypt
Returns:
the decrypted equivalent of the string
Throws:
CrypterException - on error

decryptMatchingSubstrings

public java.lang.String decryptMatchingSubstrings(java.lang.String s,
                                                  java.util.regex.Pattern p)
                                           throws CrypterException
Returns a specified string with all substrings that match a specified pattern decrypted.

Parameters:
s - the string to decrypt
p - the pattern to search for and decrypt in the string
Returns:
the string with matching substrings decrypted
Throws:
CrypterException - on error

decryptMatchingSubstrings

public java.lang.String decryptMatchingSubstrings(java.lang.String s,
                                                  java.lang.String p)
                                           throws CrypterException,
                                                  java.util.regex.PatternSyntaxException
Returns a specified string with all substrings that match a specified pattern decrypted.

Parameters:
s - the string to decrypt
p - the pattern to search for and decrypt in the string
Returns:
the string with matching substrings decrypted
Throws:
CrypterException - on error
java.util.regex.PatternSyntaxException - if the pattern is faulty

encrypt

public java.lang.String encrypt(java.lang.String s)
                         throws CrypterException
Returns the encrypted version of a specified string.

Parameters:
s - the string to encrypt
Returns:
the encrypted equivalent of the string, or null on error
Throws:
CrypterException - on error

encryptMatchingSubstrings

public java.lang.String encryptMatchingSubstrings(java.lang.String s,
                                                  java.util.regex.Pattern p)
                                           throws CrypterException
Returns a specified string with all substrings that match a specified pattern encrypted.

Parameters:
s - the string to encrypt
p - the pattern to search for and encrypt in the string
Returns:
the string with matching substrings encrypted
Throws:
CrypterException

encryptMatchingSubstrings

public java.lang.String encryptMatchingSubstrings(java.lang.String s,
                                                  java.lang.String p)
                                           throws CrypterException,
                                                  java.util.regex.PatternSyntaxException
Returns a specified string with all substrings that match a specified pattern encrypted.

Parameters:
s - the string to encrypt
p - the pattern to search for and encrypt in the string
Returns:
the string with matching substrings encrypted
Throws:
CrypterException - on error
java.util.regex.PatternSyntaxException - if the pattern is faulty

getDecipher

public javax.crypto.Cipher getDecipher()
Return a cipher that can be used for decryption.

Returns:
A cipher object.

getEncipher

public javax.crypto.Cipher getEncipher()
Return a cipher that can be used for encryption.

Returns:
A cipher object.

cryptMatchingSubstrings

protected java.lang.String cryptMatchingSubstrings(java.lang.String s,
                                                   java.util.regex.Pattern p,
                                                   boolean decrypt)
                                            throws CrypterException
Returns a specified string with all substrings that match a specified pattern de/encrypted.

Parameters:
s - the string to encrypt
p - the pattern to search for and de/encrypt in the string
decrypt - whether the method should decrypt or decrypt
Returns:
the string with matching substrings de/encrypted
Throws:
CrypterException - on error