From a23eaf33235ee70476b8ea96c4b57028d2723615 Mon Sep 17 00:00:00 2001 From: Tomasz Lelek Date: Mon, 27 Feb 2017 19:06:34 +0100 Subject: [PATCH] BAEL-311 add jasyp module --- jasypt/pom.xml | 34 +++++++++++++++++++ .../java/org/baeldung/jasypt/JasyptTest.java | 27 +++++++++++++++ pom.xml | 1 + 3 files changed, 62 insertions(+) create mode 100644 jasypt/pom.xml create mode 100644 jasypt/src/test/java/org/baeldung/jasypt/JasyptTest.java diff --git a/jasypt/pom.xml b/jasypt/pom.xml new file mode 100644 index 0000000000..7e0c51f0b9 --- /dev/null +++ b/jasypt/pom.xml @@ -0,0 +1,34 @@ + + + + parent-modules + com.baeldung + 1.0.0-SNAPSHOT + + 4.0.0 + + jasypt + + + + org.jasypt + jasypt + ${jasypt.version} + + + junit + junit + ${junit.version} + test + + + + + 1.9.2 + 4.12 + + + + \ No newline at end of file diff --git a/jasypt/src/test/java/org/baeldung/jasypt/JasyptTest.java b/jasypt/src/test/java/org/baeldung/jasypt/JasyptTest.java new file mode 100644 index 0000000000..c81d605e50 --- /dev/null +++ b/jasypt/src/test/java/org/baeldung/jasypt/JasyptTest.java @@ -0,0 +1,27 @@ +package org.baeldung.jasypt; + + +import org.jasypt.util.text.BasicTextEncryptor; +import org.junit.Test; + +import static junit.framework.Assert.assertNotSame; +import static junit.framework.TestCase.assertEquals; + +public class JasyptTest { + + @Test + public void givenTextPassword_whenDecrypt_shouldCompareToEncrypted() { + //given + BasicTextEncryptor textEncryptor = new BasicTextEncryptor(); + String password = "secret-pass"; + textEncryptor.setPasswordCharArray(password.toCharArray()); + + //when + String myEncryptedText = textEncryptor.encrypt("secret-pass"); + assertNotSame("secret-pass", myEncryptedText); //myEncryptedText can be save in db + + //then + String plainText = textEncryptor.decrypt(myEncryptedText); + assertEquals(plainText, "secret-pass"); + } +} diff --git a/pom.xml b/pom.xml index 014e4016c5..d42c184993 100644 --- a/pom.xml +++ b/pom.xml @@ -61,6 +61,7 @@ javaslang javax-servlets javaxval + jasypt jaxb jee7 jjwt