|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.softabar.crypt.SoftaCrypt
SoftaCrypt is a single class implementation for common encryption and message digest algorithms. This class implements following encryption algorithms:
and following digest algorithms: This class implements also: SoftaCrypt class requires JDK 1.1 or later.
| Field Summary | |
static int |
AES
Constant for AES (Advanced Encryption Standard) block cipher algorithm. |
static int |
TWOFISH
Constant for TwoFish block cipher algorithm. |
static int |
XTEA
Constant for XTEA (eXtended Tiny Encryption Algorithm) block cipher algorithm. |
| Constructor Summary | |
SoftaCrypt()
Empty constructor. |
|
| Method Summary | |
boolean |
areEqual(byte[] a,
byte[] b)
Convenience method to check byte array equality. |
void |
base64Decode(java.io.InputStream inputStream,
java.io.OutputStream outputStream)
Decodes inputStream to outputStream using Base64. |
void |
base64Encode(java.io.InputStream inputStream,
java.io.OutputStream outputStream)
Encodes inputStream to outputStream using Base64. |
int |
crc32(java.io.InputStream inputStream)
Calculates Cyclic Redundancy Check, CRC32, from inputStream. |
void |
decrypt(java.io.InputStream inputStream,
java.io.OutputStream outputStream)
Decrypts inputStream to outputStream using operation specified by setAlgorithm(int) and key
specified by setKey(byte[]). |
void |
encrypt(java.io.InputStream inputStream,
java.io.OutputStream outputStream)
Encrypts inputStream to outputStream using operation specified by setAlgorithm(int) and key
specified by setKey(byte[]). |
int |
getAlgorithm()
Returns current algorithm. |
byte[] |
getKey()
Returns current key. |
int |
getXTEARounds()
|
boolean |
isCloseStreams()
|
void |
reset()
Resets instance for use in other operation. |
void |
setAlgorithm(int algorithm)
Sets encryption/decryption algorithm for this instance. |
void |
setCloseStreams(boolean closeStreams)
Specify whether or not to close stream after operation (encrypt/decrypt, hash or base64). |
void |
setKey(byte[] key)
Sets key for encryption/decryption. |
void |
setXTEARounds(int rounds)
Set rounds for XTEA operation. |
byte[] |
sha1(java.io.InputStream inputStream)
Calculates 160-bit message digest using SHA-1 from inputStream. |
byte[] |
sha224(java.io.InputStream inputStream)
Calculates 224-bit message digest using SHA-224 from inputStream. |
byte[] |
sha256(java.io.InputStream inputStream)
Calculates 256-bit message digest using SHA-256 from inputStream. |
byte[] |
sha384(java.io.InputStream inputStream)
Calculates 384-bit message digest using SHA-384 from inputStream. |
byte[] |
sha512(java.io.InputStream inputStream)
Calculates 512-bit message digest using SHA-512 from inputStream. |
byte[] |
to16Bytes(byte[] bytes)
Modifies array to 16 bytes. |
byte[] |
to32Bytes(byte[] bytes)
Modifies array to 32 bytes. |
java.lang.String |
toHexString(byte[] b)
Convenience method to print byte array as hexadecimal string. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int TWOFISH
public static final int AES
public static final int XTEA
| Constructor Detail |
public SoftaCrypt()
setKey(byte[])
and setAlgorithm(int).
| Method Detail |
public void setKey(byte[] key)
key - Key as byte array.
java.lang.IllegalArgumentException - If key length is not 16 or 32 bytes.public byte[] getKey()
public void setAlgorithm(int algorithm)
AES, TWOFISH or XTEA.AES.
algorithm - Algorithm to use in encryption/decryption.
java.lang.IllegalArgumentException - If algorithm is not AES, TWOFISH or XTEA.public int getAlgorithm()
public void setCloseStreams(boolean closeStreams)
closeStreams - True to close streams after operation. False otherwise.public boolean isCloseStreams()
public void reset()
public void encrypt(java.io.InputStream inputStream,
java.io.OutputStream outputStream)
throws java.io.IOException
setAlgorithm(int) and key
specified by setKey(byte[]). Data is read from inputStream and encrypted to outputStream.
inputStream - Data to encrypt.outputStream - Encrypted data.
java.io.IOException - If error occurred while reading from inputStream or writing to outputStream.
java.lang.IllegalStateException - If key is not specified or if using 256-bit key for XTEA algorithm.
public void decrypt(java.io.InputStream inputStream,
java.io.OutputStream outputStream)
throws java.io.IOException
setAlgorithm(int) and key
specified by setKey(byte[]). Encrypted data is read from inputStream and decrypted to outputStream.
inputStream - Data to decrypt.outputStream - Decrypted data.
java.io.IOException - If error occurred while reading from inputStream or writing to outputStream.
java.lang.IllegalStateException - If key is not specified or if using 256-bit key for XTEA algorithm.
public byte[] sha1(java.io.InputStream inputStream)
throws java.io.IOException
inputStream - Calculates SHA-1 from this InputStream.
java.io.IOException - If error occurred while reading from inputStream.
public byte[] sha224(java.io.InputStream inputStream)
throws java.io.IOException
inputStream - Calculates SHA-224 from this InputStream.
java.io.IOException - If error occurred while reading from inputStream.
public byte[] sha256(java.io.InputStream inputStream)
throws java.io.IOException
inputStream - Calculates SHA-256 from this InputStream.
java.io.IOException - If error occurred while reading from inputStream.
public byte[] sha384(java.io.InputStream inputStream)
throws java.io.IOException
inputStream - Calculates SHA-384 from this InputStream.
java.io.IOException - If error occurred while reading from inputStream.
public byte[] sha512(java.io.InputStream inputStream)
throws java.io.IOException
inputStream - Calculates SHA-512 from this InputStream.
java.io.IOException - If error occurred while reading from inputStream.
public int crc32(java.io.InputStream inputStream)
throws java.io.IOException
X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0Start value of calculation is 0xffffffff and result is XORed with 0xffffffff.
inputStream - Data to calculate CRC32.
java.io.IOException - If error occurred while reading from inputStream.
public void base64Encode(java.io.InputStream inputStream,
java.io.OutputStream outputStream)
throws java.io.IOException
inputStream - Data to encode.outputStream - Decoded data.
java.io.IOException - If error occurred while reading from inputStream or writing to outputStream.
public void base64Decode(java.io.InputStream inputStream,
java.io.OutputStream outputStream)
throws java.io.IOException
inputStream - Data to decode.outputStream - Decoded data.
java.io.IOException - If error occurred while reading from inputStream or writing to outputStream.public void setXTEARounds(int rounds)
rounds - Rounds for XTEA operation.public int getXTEARounds()
public java.lang.String toHexString(byte[] b)
b - Byte array to print.
public boolean areEqual(byte[] a,
byte[] b)
a - Byte array a.b - Byte array b.
public byte[] to16Bytes(byte[] bytes)
bytes - Byte array to modify.
public byte[] to32Bytes(byte[] bytes)
bytes - Byte array to modify.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||