org.jutil
Class TCrypt

java.lang.Object
  extended by org.jutil.TCrypt

public final class TCrypt
extends java.lang.Object

This is the TCrypt utility code class.

TO DO: need to create methods for accessing key stores and ArgParser pb...


Constructor Summary
TCrypt()
          Ensure that no one can create instances of this Class.
 
Method Summary
static boolean authenticate(byte[] crypt, byte[] pass)
          Can this user be authenticated with the specified password?
static boolean authenticate(byte[] crypt, java.lang.String pass)
          Can this user be authenticated with the specified password?
static boolean authenticate(java.lang.String crypt, java.lang.String pass)
          Can this user be authenticated with the specified password?
static void debug(java.lang.String msg, java.io.PrintWriter writer)
           
static java.lang.Object decrypt(java.security.Key key, byte[] obj)
          USAGE: org.jutil.TCrypt.decrypt(Key key, byte[] obj);
static java.lang.Object decrypt(java.security.Key key, byte[] obj, java.lang.String algorithm, java.lang.String provider)
           
static byte[] decryptRaw(java.security.Key key, byte[] obj, java.lang.String algorithm, java.lang.String provider)
           
static java.lang.Object deserialize(java.security.Key key, java.io.File file)
           
static java.lang.Object deserialize(java.security.Key key, java.io.File file, java.lang.String algorithm, java.lang.String provider)
           
static java.lang.Object deserializeGZIP(java.security.Key key, java.io.File file)
           
static java.lang.Object deserializeGZIP(java.security.Key key, java.io.File file, java.lang.String algorithm, java.lang.String provider)
           
static java.security.Key deserializeKey(java.io.File file)
           
static byte[] encrypt(java.security.Key key, java.lang.Object obj)
          USAGE: org.jutil.TCrypt.encrypt(Key key, Object obj);
static byte[] encrypt(java.security.Key key, java.lang.Object obj, java.lang.String algorithm, java.lang.String provider)
           
static byte[] encryptRaw(java.security.Key key, byte[] bytes, java.lang.String algorithm, java.lang.String provider)
           
static java.lang.Object fromFile(java.security.Key key, java.io.File file)
           
static java.lang.Object fromFile(java.security.Key key, java.io.File file, java.lang.String algorithm, java.lang.String provider)
           
static java.security.Key generateKey(int len)
           
static java.security.Key generateKey(int len, byte[] seed)
           
static java.security.Key generateKey(int len, byte[] seed, java.lang.String algorithm, java.lang.String provider)
           
static java.security.KeyPair generateKeyPair(int len)
           
static java.security.KeyPair generateKeyPair(int len, byte[] seed)
           
static java.security.KeyPair generateKeyPair(int len, byte[] seed, java.lang.String algorithm, java.lang.String provider)
           
static java.lang.String genRandomPassword(int length)
           
static byte[] hash(byte[] src)
          Return the encrypted version of this cleartext password.
static byte[] hash(byte[] src, java.lang.String algorithm)
           
static byte[] hash(java.lang.String src)
          Return the encrypted version of this cleartext password.
static java.lang.String hashToString(byte[] src)
          Return the encrypted version of this cleartext password.
static java.lang.String hashToString(byte[] src, java.lang.String algorithm)
           
static java.lang.String hashToString(java.lang.String src)
          Return the encrypted version of this cleartext password.
static java.lang.String hashToString(java.lang.String src, java.lang.String algorithm)
           
static byte[] hexDecode(java.lang.String src)
          Returns a byte array from a string of hexadecimal digits.
static java.lang.String hexEncode(byte[] src)
           
static java.lang.String hexEncode0(byte[] src)
           
static void main(java.lang.String[] args)
           java org.jutil.TCrypt -cmd genkey -keyfile crypt.key java org.jutil.TCrypt -cmd genrand -len 8 java org.jutil.TCrypt -cmd genpass -pass secret java org.jutil.TCrypt -cmd testpass -pass secret -hash 123456789 java org.jutil.TCrypt -cmd testpass -pass secret -hash 123456789 -debug true java org.jutil.TCrypt -cmd encrypt -keyfile secret.key -encrypted secret.dat -value accounts.data java org.jutil.TCrypt fromFile keyFile encryptedFile java org.jutil.TCrypt fromFile keyFile encryptedFile java org.jutil.TCrypt fromFile keyFile encryptedFile
static void main0(java.lang.String[] args)
           
static void prn(java.lang.String msg, java.io.PrintWriter writer)
           
static void serialize(java.security.Key key, java.lang.Object obj, java.io.File file)
           
static void serialize(java.security.Key key, java.lang.Object obj, java.io.File file, java.lang.String algorithm, java.lang.String provider)
           
static void serializeGZIP(java.security.Key key, java.lang.Object obj, java.io.File file)
           
static void serializeGZIP(java.security.Key key, java.lang.Object obj, java.io.File file, java.lang.String algorithm, java.lang.String provider)
           
static void serializeKey(java.security.Key key, java.io.File file)
           
static void toFile(java.security.Key key, java.lang.Object obj, java.io.File file)
           
static void toFile(java.security.Key key, java.lang.Object obj, java.io.File file, java.lang.String algorithm, java.lang.String provider)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TCrypt

public TCrypt()
Ensure that no one can create instances of this Class.

Method Detail

generateKeyPair

public static final java.security.KeyPair generateKeyPair(int len)

generateKeyPair

public static final java.security.KeyPair generateKeyPair(int len,
                                                          byte[] seed)

generateKeyPair

public static final java.security.KeyPair generateKeyPair(int len,
                                                          byte[] seed,
                                                          java.lang.String algorithm,
                                                          java.lang.String provider)
                                                   throws java.security.NoSuchAlgorithmException,
                                                          java.security.NoSuchProviderException
Throws:
java.security.NoSuchAlgorithmException
java.security.NoSuchProviderException

generateKey

public static final java.security.Key generateKey(int len)

generateKey

public static final java.security.Key generateKey(int len,
                                                  byte[] seed)

generateKey

public static final java.security.Key generateKey(int len,
                                                  byte[] seed,
                                                  java.lang.String algorithm,
                                                  java.lang.String provider)
                                           throws java.security.NoSuchAlgorithmException,
                                                  java.security.NoSuchProviderException
Throws:
java.security.NoSuchAlgorithmException
java.security.NoSuchProviderException

serializeKey

public static final void serializeKey(java.security.Key key,
                                      java.io.File file)
                               throws java.io.IOException
Throws:
java.io.IOException

deserializeKey

public static final java.security.Key deserializeKey(java.io.File file)
                                              throws java.io.IOException,
                                                     java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

toFile

public static final void toFile(java.security.Key key,
                                java.lang.Object obj,
                                java.io.File file)
                         throws java.io.IOException
Throws:
java.io.IOException

toFile

public static final void toFile(java.security.Key key,
                                java.lang.Object obj,
                                java.io.File file,
                                java.lang.String algorithm,
                                java.lang.String provider)
                         throws java.io.IOException
Throws:
java.io.IOException

fromFile

public static final java.lang.Object fromFile(java.security.Key key,
                                              java.io.File file)
                                       throws java.io.IOException,
                                              java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

fromFile

public static final java.lang.Object fromFile(java.security.Key key,
                                              java.io.File file,
                                              java.lang.String algorithm,
                                              java.lang.String provider)
                                       throws java.io.IOException,
                                              java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

serialize

public static final void serialize(java.security.Key key,
                                   java.lang.Object obj,
                                   java.io.File file)
                            throws java.io.IOException
Throws:
java.io.IOException

serialize

public static final void serialize(java.security.Key key,
                                   java.lang.Object obj,
                                   java.io.File file,
                                   java.lang.String algorithm,
                                   java.lang.String provider)
                            throws java.io.IOException
Throws:
java.io.IOException

deserialize

public static final java.lang.Object deserialize(java.security.Key key,
                                                 java.io.File file)
                                          throws java.io.IOException,
                                                 java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

deserialize

public static final java.lang.Object deserialize(java.security.Key key,
                                                 java.io.File file,
                                                 java.lang.String algorithm,
                                                 java.lang.String provider)
                                          throws java.io.IOException,
                                                 java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

serializeGZIP

public static final void serializeGZIP(java.security.Key key,
                                       java.lang.Object obj,
                                       java.io.File file)
                                throws java.io.IOException
Throws:
java.io.IOException

serializeGZIP

public static final void serializeGZIP(java.security.Key key,
                                       java.lang.Object obj,
                                       java.io.File file,
                                       java.lang.String algorithm,
                                       java.lang.String provider)
                                throws java.io.IOException
Throws:
java.io.IOException

deserializeGZIP

public static final java.lang.Object deserializeGZIP(java.security.Key key,
                                                     java.io.File file)
                                              throws java.io.IOException,
                                                     java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

deserializeGZIP

public static final java.lang.Object deserializeGZIP(java.security.Key key,
                                                     java.io.File file,
                                                     java.lang.String algorithm,
                                                     java.lang.String provider)
                                              throws java.io.IOException,
                                                     java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

encrypt

public static final byte[] encrypt(java.security.Key key,
                                   java.lang.Object obj)
                            throws java.io.IOException
USAGE: org.jutil.TCrypt.encrypt(Key key, Object obj);

Throws:
java.io.IOException

encrypt

public static final byte[] encrypt(java.security.Key key,
                                   java.lang.Object obj,
                                   java.lang.String algorithm,
                                   java.lang.String provider)
                            throws java.io.IOException
Throws:
java.io.IOException

encryptRaw

public static final byte[] encryptRaw(java.security.Key key,
                                      byte[] bytes,
                                      java.lang.String algorithm,
                                      java.lang.String provider)
                               throws java.io.IOException
Throws:
java.io.IOException

decrypt

public static final java.lang.Object decrypt(java.security.Key key,
                                             byte[] obj)
                                      throws java.io.IOException,
                                             java.lang.ClassNotFoundException
USAGE: org.jutil.TCrypt.decrypt(Key key, byte[] obj);

Throws:
java.io.IOException
java.lang.ClassNotFoundException

decrypt

public static final java.lang.Object decrypt(java.security.Key key,
                                             byte[] obj,
                                             java.lang.String algorithm,
                                             java.lang.String provider)
                                      throws java.io.IOException,
                                             java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

decryptRaw

public static final byte[] decryptRaw(java.security.Key key,
                                      byte[] obj,
                                      java.lang.String algorithm,
                                      java.lang.String provider)
                               throws java.io.IOException
Throws:
java.io.IOException

hashToString

public static final java.lang.String hashToString(java.lang.String src)
Return the encrypted version of this cleartext password.

Parameters:
pass - Cleartext pass to be encrypted

hashToString

public static final java.lang.String hashToString(java.lang.String src,
                                                  java.lang.String algorithm)

hashToString

public static final java.lang.String hashToString(byte[] src)
Return the encrypted version of this cleartext password.

Parameters:
pass - bytes to be encrypted

hashToString

public static final java.lang.String hashToString(byte[] src,
                                                  java.lang.String algorithm)

hash

public static final byte[] hash(java.lang.String src)
Return the encrypted version of this cleartext password.

Parameters:
pass - Cleartext pass to be encrypted

hash

public static final byte[] hash(byte[] src)
Return the encrypted version of this cleartext password.

Parameters:
pass - bytes to be encrypted

hash

public static final byte[] hash(byte[] src,
                                java.lang.String algorithm)

authenticate

public static final boolean authenticate(java.lang.String crypt,
                                         java.lang.String pass)
Can this user be authenticated with the specified password?

Parameters:
crypt - Password previously encrypted using TCrypt.hashToString(String src) or TCrypt.hashToString(byte src)
pass - Password (cleartext) to be tested

authenticate

public static final boolean authenticate(byte[] crypt,
                                         java.lang.String pass)
Can this user be authenticated with the specified password?

Parameters:
crypt - Password previously encrypted using TCrypt.hash(String src)
pass - Password (cleartext) to be tested

authenticate

public static final boolean authenticate(byte[] crypt,
                                         byte[] pass)
Can this user be authenticated with the specified password?

Parameters:
crypt - Password previously encrypted using TCrypt.hash(byte[] src)
pass - Password (cleartext) to be tested

hexEncode

public static java.lang.String hexEncode(byte[] src)

hexEncode0

public static final java.lang.String hexEncode0(byte[] src)

hexDecode

public static byte[] hexDecode(java.lang.String src)
Returns a byte array from a string of hexadecimal digits.


genRandomPassword

public static final java.lang.String genRandomPassword(int length)

prn

public static final void prn(java.lang.String msg,
                             java.io.PrintWriter writer)

debug

public static final void debug(java.lang.String msg,
                               java.io.PrintWriter writer)

main

public static void main(java.lang.String[] args)
        java org.jutil.TCrypt -cmd genkey -keyfile crypt.key
        java org.jutil.TCrypt -cmd genrand -len 8
        java org.jutil.TCrypt -cmd genpass -pass secret
        java org.jutil.TCrypt -cmd testpass -pass secret -hash 123456789
        java org.jutil.TCrypt -cmd testpass -pass secret -hash 123456789 -debug true
        java org.jutil.TCrypt -cmd encrypt -keyfile secret.key -encrypted secret.dat -value accounts.data
        java org.jutil.TCrypt fromFile keyFile encryptedFile            
        java org.jutil.TCrypt fromFile keyFile encryptedFile            
        java org.jutil.TCrypt fromFile keyFile encryptedFile            
        


main0

public static void main0(java.lang.String[] args)