Just make a java class and call it in your jsp-page (or better struts-action).
If you are using this or older java versions than "JavaTM 2 SDK v 1.4", you can download the "JavaTM Cryptography Extension (JCE)".
In newer versions, these classes are already inside, see Java security classes
This is a code snippet randomly taken from the java API documentation:
-
Cipher aesCipher;
-
-
// Create the cipher
-
aesCipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
-
-
We use the generated aesKey from above to initialize the Cipher object for encryption:
-
-
// Initialize the cipher for encryption
-
aesCipher.init(Cipher.ENCRYPT_MODE, aesKey);
-
-
// Our cleartext
-
byte[] cleartext = "This is just an example".getBytes();
-
-
// Encrypt the cleartext
-
byte[] ciphertext = aesCipher.doFinal(cleartext);
-
-
// Initialize the same cipher for decryption
-
aesCipher.init(Cipher.DECRYPT_MODE, aesKey);
-
-
// Decrypt the ciphertext
-
byte[] cleartext1 = aesCipher.doFinal(ciphertext);