org.bibalex.daf.installer
Class Cryptography
java.lang.Object
org.bibalex.daf.installer.Cryptography
public class Cryptography
- extends java.lang.Object
Copyright (c) 2006-2007 by Bibliotheca Alexandrina
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
This class provides a wrapping for the Encryption and Decryption functionalities.
- Author:
- Ramy.Nagah
Currently it only supports one embededd encrption algorithm "PBEWithMD5AndDES",
but it can be modified to support multi encrption
algoritms or added providers.
Field Summary |
private javax.crypto.Cipher |
c
The Cipher ing instance used in encryption and decryption |
private static char[] |
hexChar
The hexadecimal characters in an array to be used in converions from string to hexadecimals, and in
validations. |
private javax.crypto.SecretKey |
key
The SecretKey instance used in encryption and decryption (generated) from the password and the SALT |
private javax.crypto.spec.PBEParameterSpec |
paramSpec
|
Constructor Summary |
Cryptography(java.lang.String strPassword,
java.lang.String strSalt)
Constructor. |
Method Summary |
java.lang.String |
Decrypt(java.lang.String strValue)
Decrypts the given strValue using the instantiated object of Password and Salt |
java.lang.String |
Encrypt(java.lang.String strValue)
Encrypts the given strValue using the instantiated object of Password and Salt |
protected static byte[] |
toBinArray(java.lang.String hexStr)
Converts a Hexadecimal String into a binary array. |
protected static java.lang.String |
toHexString(byte[] b)
Converts a String to its equivalent Hexadecimal representation. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
hexChar
private static final char[] hexChar
- The hexadecimal characters in an array to be used in converions from string to hexadecimals, and in
validations.
c
private javax.crypto.Cipher c
- The
Cipher
ing instance used in encryption and decryption
key
private javax.crypto.SecretKey key
- The
SecretKey
instance used in encryption and decryption (generated) from the password and the SALT
paramSpec
private javax.crypto.spec.PBEParameterSpec paramSpec
Cryptography
public Cryptography(java.lang.String strPassword,
java.lang.String strSalt)
throws java.lang.Exception
- Constructor.
This class has to be initialized to be able to either
Encrypt
or Decrypt
.
- Parameters:
strPassword
- Password used in creating the SecretKey
.strSalt
- the Salt used in in creating the SecretKey
.
- Throws:
java.lang.Exception
Encrypt
public java.lang.String Encrypt(java.lang.String strValue)
throws java.lang.Exception
- Encrypts the given
strValue
using the instantiated object of Password and Salt
- Parameters:
strValue
- the value to Encrypt
- Returns:
- the encrpted
String
- Throws:
java.lang.Exception
Decrypt
public java.lang.String Decrypt(java.lang.String strValue)
throws java.lang.Exception
- Decrypts the given
strValue
using the instantiated object of Password and Salt
- Parameters:
strValue
- the value to Decrypt
- Returns:
- the decrpted
String
- Throws:
java.lang.Exception
toHexString
protected static java.lang.String toHexString(byte[] b)
- Converts a
String
to its equivalent Hexadecimal representation.
- Parameters:
b
- the byte[]
to be converted into Hexadecimal String
- Returns:
- The Hexadecimal representation.
toBinArray
protected static byte[] toBinArray(java.lang.String hexStr)
- Converts a Hexadecimal
String
into a binary array.
- Parameters:
hexStr
- The Hexadecimal String
to be converted.
- Returns:
- a
byte[]
representing the binary array.