1 package org.kuali.common.util.encrypt.openssl;
2
3 import static java.lang.String.format;
4 import static org.junit.Assert.assertEquals;
5 import static org.kuali.common.util.log.Loggers.newLogger;
6
7 import org.junit.Test;
8 import org.kuali.common.util.encrypt.Encryptor;
9 import org.kuali.common.util.encrypt.openssl.OpenSSLEncryptor;
10 import org.slf4j.Logger;
11
12 public class OpenSSLEncryptorTest {
13
14 private static final Logger logger = newLogger();
15
16 @Test
17 public void testEncryption() {
18 String password = "foo";
19 String plaintext = "bar";
20 Encryptor encryptor = new OpenSSLEncryptor(password);
21 String encrypted = encryptor.encrypt(plaintext);
22 String decrypted = encryptor.decrypt(encrypted);
23 assertEquals(plaintext, decrypted);
24 info("password=%s", password);
25 info("plaintext=%s", plaintext);
26 info("encrypted=%s", encrypted);
27 info("decrypted=%s", decrypted);
28 }
29
30 protected static void info(String msg, Object... args) {
31 if (args == null) {
32 logger.info(msg);
33 } else {
34 logger.info(format(msg, args));
35 }
36 }
37 }