Cryptography

Functions in this section simplify the usage of Java Cryptography Extension. Sun JCE1.2 or compatible software is required.

getSecretKey( String algorithm )

getSecretKey() creates a javax.crypto.SecretKey object with the specified algorithm.

e.g.
key = getSecretKey("DES")
key.getEncoded()    ==> [#DE, #A0, .... ]
encrypt( SecretKey secretkey , InputStream input {, OutputStream output } ) or
( String password , InputStream input {, OutputStream output } )

If secretkey is specified as the first parameter, encrypt() reads data from input and encrypts them with the secretkey. If password is specified as the first parameter, encrypt() creates a secret key based on the password and encrypts the inputstream.

If output is specified, the encrypted data is written to the stream. Otherwise, encrypt() returns a java.io.PipedInputStream object which can be read with read() function.

e.g.
encrypt(key, open("plain.txt"), open("encrypted.dat", "w"))
decrypt( SecretKey secretkey , InputStream input {, OutputStream output } ) or
( String password , InputStream input {, OutputStream output } )

If secretkey is specified as the first parameter, decrypt() reads data from input and decrypts them with the secretkey. If password is specified as the first parameter, decrypt() creates a secret key based on the password and decrypts the input.

If output is specified, the decrypted data is written to the stream. Otherwise, decrypt() returns a java.io.PipedInputStream object which can be read with read() function.

e.g.
decrypt(key, open("encrypted.dat"), open("plain.txt", "w"))
sealObject( SecretKey secretkey , Serializable object ) or
( String password , Serializable object )
unsealObject( SecretKey secretkey , Serializable object ) or
( String password , Serializable object )

If secretkey is specified as the first parameter, sealObject() returns a SealedObject created by encrypting object with the secretkey. If password is specified as the first paramter, sealObject() creates a secret key based on the password and encrypts the object.

unsealObject() retrieves the original object from a sealed object.

e.g.
sealed = sealObject(key, "something secret")
unsealObject(key, sealed)

Back