BAEL-311 add jasyp module

This commit is contained in:
Tomasz Lelek 2017-02-27 19:06:34 +01:00
parent 8617faf9cf
commit a23eaf3323
3 changed files with 62 additions and 0 deletions

34
jasypt/pom.xml Normal file
View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>parent-modules</artifactId>
<groupId>com.baeldung</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jasypt</artifactId>
<dependencies>
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt</artifactId>
<version>${jasypt.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<jasypt.version>1.9.2</jasypt.version>
<junit.version>4.12</junit.version>
</properties>
</project>

View File

@ -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");
}
}

View File

@ -61,6 +61,7 @@
<module>javaslang</module>
<module>javax-servlets</module>
<module>javaxval</module>
<module>jasypt</module>
<module>jaxb</module>
<module>jee7</module>
<module>jjwt</module>