Java Code Examples for org.jasypt.encryption.pbe.StandardPBEStringEncryptor#decrypt()

The following examples show how to use org.jasypt.encryption.pbe.StandardPBEStringEncryptor#decrypt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JasyptUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
@Ignore("should have installed local_policy.jar")
public void givenTextPrivateData_whenDecrypt_thenCompareToEncryptedWithCustomAlgorithm() {
    // given
    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
    String privateData = "secret-data";
    encryptor.setPassword("some-random-data");
    encryptor.setAlgorithm("PBEWithMD5AndTripleDES");

    // when
    String encryptedText = encryptor.encrypt("secret-pass");
    assertNotSame(privateData, encryptedText);

    // then
    String plainText = encryptor.decrypt(encryptedText);
    assertEquals(plainText, privateData);
}
 
Example 2
Source File: BaseWebApplicationTests.java    From hdw-dubbo with Apache License 2.0 5 votes vote down vote up
/**
 * 解密
 * @throws Exception
 */
@Test
public void testDecrypt() throws Exception {
    StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
    EnvironmentPBEConfig config = new EnvironmentPBEConfig();
    //TODO: 加密的算法,这个算法是默认的
    config.setAlgorithm("PBEWithMD5AndDES");
    //TODO: 加密的密钥
    config.setPassword(CommonConstant.JWT_DEFAULT_ISSUER);
    standardPBEStringEncryptor.setConfig(config);
    String encryptedText = "xRL1CVgzfFKBnPxCr+xjkg==";
    String plainText = standardPBEStringEncryptor.decrypt(encryptedText);
    System.out.println(plainText);
}
 
Example 3
Source File: DataUtil.java    From framework with Apache License 2.0 5 votes vote down vote up
/**
 * Description: 解密 <br>
 * 
 * @author 王伟<br>
 * @taskId <br>
 * @param password
 * @return <br>
 */
public static String decrypt(final String password) {
    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
    // 加密配置
    EnvironmentStringPBEConfig config = new EnvironmentStringPBEConfig();
    config.setAlgorithm(ALGORITHM);
    // 自己在用的时候更改此密码
    config.setPassword(SITE_WIDE_SECRET);
    // 应用配置
    encryptor.setConfig(config);
    // 解密
    return encryptor.decrypt(password);
}
 
Example 4
Source File: Jasypt.java    From spring-boot-api-project-seed with Apache License 2.0 4 votes vote down vote up
/**
 * 解密
 * @param ciphertext 密文
 * @return           明文
 */
public static String decrypt(String ciphertext) {
    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
    encryptor.setPassword(KEY);
    return encryptor.decrypt(ciphertext);
}
 
Example 5
Source File: AuthTokenUtils.java    From divide with Apache License 2.0 4 votes vote down vote up
private static String decrypt(String string, String key){
    StandardPBEStringEncryptor encryptor = getEncryptor(key);
    String decoded = Base64.decode(string);
    return encryptor.decrypt(decoded);
}