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

The following examples show how to use org.jasypt.encryption.pbe.StandardPBEStringEncryptor#encrypt() . 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 Project: tutorials   File: JasyptUnitTest.java    License: 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
/**
 * 加密
 * @throws Exception
 */
@Test
public void testEncrypt() throws Exception {
    StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
    EnvironmentPBEConfig config = new EnvironmentPBEConfig();
    //TODO: 加密的算法,这个算法是默认的
    config.setAlgorithm("PBEWithMD5AndDES");
    //TODO: 加密的密钥
    config.setPassword(CommonConstant.JWT_DEFAULT_ISSUER);
    standardPBEStringEncryptor.setConfig(config);
    //[email protected]
    String plainText = "abc123";
    String encryptedText = standardPBEStringEncryptor.encrypt(plainText);
    System.out.println(encryptedText);
}
 
Example 3
@Test
public  void test(){
    StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
    EnvironmentPBEConfig config = new EnvironmentPBEConfig();
    config.setAlgorithm("PBEWithMD5AndDES");          // 加密的算法,这个算法是默认的
    config.setPassword("ueboot");                        // 加密的密钥
    standardPBEStringEncryptor.setConfig(config);
    String plainText = "";
    String encryptedText = standardPBEStringEncryptor.encrypt(plainText);
    System.out.println(encryptedText);
}
 
Example 4
Source Project: framework   File: DataUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Description: 可以解密的加密<br>
 * 
 * @author 王伟<br>
 * @taskId <br>
 * @param password
 * @return <br>
 */
public static String encrypt(final String password) {
    // 加密工具
    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
    // 加密配置
    EnvironmentStringPBEConfig config = new EnvironmentStringPBEConfig();
    config.setAlgorithm(ALGORITHM);
    // 自己在用的时候更改此密码
    config.setPassword(SITE_WIDE_SECRET);
    // 应用配置
    encryptor.setConfig(config);
    // 加密
    return encryptor.encrypt(password);
}
 
Example 5
Source Project: mrgeo   File: MrGeoPropertiesTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception
{
  MrGeoProperties.resetProperties();

  StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
  encryptor.setPassword(TEST_MASTER_PASSWORD);
  encryptedValue = "ENC(" + encryptor.encrypt(decryptedValue) + ")";

}
 
Example 6
/**
 * 加密
 * @param text 明文
 * @return     密文
 */
public static String encrypt(String text) {
    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
    encryptor.setPassword(KEY);
    return encryptor.encrypt(text);
}
 
Example 7
Source Project: divide   File: AuthTokenUtils.java    License: Apache License 2.0 4 votes vote down vote up
private static String encrypt(String string, String key){
    StandardPBEStringEncryptor encryptor = getEncryptor(key);
    String encrypted = encryptor.encrypt(string);
    return Base64.encode(encrypted);
}