01: package org.dbbrowser.security;
02:
03: import infrastructure.logging.Log;
04: import junit.framework.TestCase;
05:
06: public class AsymmetricEncryptionEngineTest extends TestCase {
07: public AsymmetricEncryptionEngineTest(String name) {
08: super (name);
09: }
10:
11: /**
12: * Uses asymmetric encryption to encrypt clearText into cypherText. Base64 Encodes
13: * the cypherText and returns the base 64 encoded string
14: * @param clearText
15: * @param passPhrase
16: * @throws EncryptionEngineException - if there is an error during encryption
17: * @return
18: */
19: public void testEncryptionEngine() {
20: try {
21: String clearText = "Hello";
22: String password = "password";
23: Log.getInstance().debugMessage(
24: "Starting encryption using clearText " + clearText
25: + "...", this .getClass().getName());
26: String encryptedAndBASE64EncodedString = AsymmetricEncryptionEngine
27: .encrypt(clearText, password);
28:
29: Log.getInstance().debugMessage(
30: "encryptedAndBASE64EncodedString is: "
31: + encryptedAndBASE64EncodedString,
32: this .getClass().getName());
33:
34: Log.getInstance().debugMessage("Starting decryption...",
35: this .getClass().getName());
36:
37: String decryptedString = AsymmetricEncryptionEngine
38: .decrypt(encryptedAndBASE64EncodedString, password);
39:
40: Log.getInstance().debugMessage(
41: "Clear text is: " + decryptedString,
42: this .getClass().getName());
43:
44: assertEquals(
45: "AsymmetricEncryptionEngineTest.testEncryptionEngine failed",
46: clearText, decryptedString);
47: } catch (EncryptionEngineException exc) {
48: fail(exc.getMessage());
49: }
50: }
51: }
|