BAEL-311 two tests that works when installed legal_policy.jar
This commit is contained in:
parent
a23eaf3323
commit
29fb2b339b
@ -1,7 +1,10 @@
|
|||||||
package org.baeldung.jasypt;
|
package org.baeldung.jasypt;
|
||||||
|
|
||||||
|
|
||||||
|
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
|
||||||
|
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
|
||||||
import org.jasypt.util.text.BasicTextEncryptor;
|
import org.jasypt.util.text.BasicTextEncryptor;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static junit.framework.Assert.assertNotSame;
|
import static junit.framework.Assert.assertNotSame;
|
||||||
@ -17,11 +20,49 @@ public class JasyptTest {
|
|||||||
textEncryptor.setPasswordCharArray(password.toCharArray());
|
textEncryptor.setPasswordCharArray(password.toCharArray());
|
||||||
|
|
||||||
//when
|
//when
|
||||||
String myEncryptedText = textEncryptor.encrypt("secret-pass");
|
String myEncryptedText = textEncryptor.encrypt(password);
|
||||||
assertNotSame("secret-pass", myEncryptedText); //myEncryptedText can be save in db
|
assertNotSame(password, myEncryptedText); //myEncryptedText can be save in db
|
||||||
|
|
||||||
//then
|
//then
|
||||||
String plainText = textEncryptor.decrypt(myEncryptedText);
|
String plainText = textEncryptor.decrypt(myEncryptedText);
|
||||||
assertEquals(plainText, "secret-pass");
|
assertEquals(plainText, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
public void givenTextPassword_whenDecrypt_shouldCompareToEncryptedWithCustomAlgorithm() {
|
||||||
|
//given
|
||||||
|
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
|
||||||
|
String password = "secret-pass";
|
||||||
|
encryptor.setPassword("secret-pass");
|
||||||
|
encryptor.setAlgorithm("PBEWithMD5AndTripleDES");
|
||||||
|
|
||||||
|
//when
|
||||||
|
String encryptedText = encryptor.encrypt("secret-pass");
|
||||||
|
assertNotSame(password, encryptedText);
|
||||||
|
|
||||||
|
//then
|
||||||
|
String plainText = encryptor.decrypt(encryptedText);
|
||||||
|
assertEquals(plainText, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
public void givenTextPassword_whenDecryptOnHighPerformance_shouldDecrypt(){
|
||||||
|
//given
|
||||||
|
String password = "secret-pass";
|
||||||
|
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
|
||||||
|
encryptor.setPoolSize(4);
|
||||||
|
encryptor.setPassword(password);
|
||||||
|
encryptor.setAlgorithm("PBEWithMD5AndTripleDES");
|
||||||
|
|
||||||
|
//when
|
||||||
|
String encryptedText = encryptor.encrypt(password);
|
||||||
|
assertNotSame(password, encryptedText);
|
||||||
|
|
||||||
|
//then
|
||||||
|
String plainText = encryptor.decrypt(encryptedText);
|
||||||
|
assertEquals(plainText, password);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user