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

The following examples show how to use org.jasypt.encryption.pbe.StandardPBEStringEncryptor#setConfig() . These examples are extracted from open source projects. 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
/**
 * Sets the PBEConfig to be used by the internal encryptor, 
 * if a specific encryptor has not been set with <tt>setEncryptor(...)</tt>.
 * 
 * @param config the PBEConfig to be set for the internal encryptor
 */
public void setConfig(final PBEConfig config) {
    if (this.encryptorSet) {
        throw new EncryptionInitializationException(
                "An encryptor has been already set: no " +
                "further configuration possible on hibernate wrapper");
    }
    final StandardPBEStringEncryptor standardPBEStringEncryptor =
        (StandardPBEStringEncryptor) this.encryptor;
    standardPBEStringEncryptor.setConfig(config);
}
 
Example 2
/**
 * Sets the PBEConfig to be used by the internal encryptor, 
 * if a specific encryptor has not been set with <tt>setEncryptor(...)</tt>.
 * 
 * @param config the PBEConfig to be set for the internal encryptor
 */
public void setConfig(final PBEConfig config) {
    if (this.encryptorSet) {
        throw new EncryptionInitializationException(
                "An encryptor has been already set: no " +
                "further configuration possible on hibernate wrapper");
    }
    final StandardPBEStringEncryptor standardPBEStringEncryptor =
        (StandardPBEStringEncryptor) this.encryptor;
    standardPBEStringEncryptor.setConfig(config);
}
 
Example 3
/**
 * Sets the PBEConfig to be used by the internal encryptor, 
 * if a specific encryptor has not been set with <tt>setEncryptor(...)</tt>.
 * 
 * @param config the PBEConfig to be set for the internal encryptor
 */
public void setConfig(final PBEConfig config) {
    if (this.encryptorSet) {
        throw new EncryptionInitializationException(
                "An encryptor has been already set: no " +
                "further configuration possible on hibernate wrapper");
    }
    final StandardPBEStringEncryptor standardPBEStringEncryptor =
        (StandardPBEStringEncryptor) this.encryptor;
    standardPBEStringEncryptor.setConfig(config);
}
 
Example 4
/**
 * Sets the PBEConfig to be used by the internal encryptor, 
 * if a specific encryptor has not been set with <tt>setEncryptor(...)</tt>.
 * 
 * @param config the PBEConfig to be set for the internal encryptor
 */
public void setConfig(final PBEConfig config) {
    if (this.encryptorSet) {
        throw new EncryptionInitializationException(
                "An encryptor has been already set: no " +
                "further configuration possible on hibernate wrapper");
    }
    final StandardPBEStringEncryptor standardPBEStringEncryptor =
        (StandardPBEStringEncryptor) this.encryptor;
    standardPBEStringEncryptor.setConfig(config);
}
 
Example 5
/**
 * 加密
 * @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 6
/**
 * 解密
 * @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 7
@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 8
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 9
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 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 10
Source Project: bearchoke   File: EncryptionConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public StandardPBEStringEncryptor standardPBEStringEncryptor() {
    StandardPBEStringEncryptor sse = new StandardPBEStringEncryptor();
    sse.setConfig(environmentStringPBEConfig());

    return sse;
}
 
Example 11
private void initEncryptor(StandardPBEStringEncryptor encryptor, String secretKey) {
    encryptor.setAlgorithm("PBEWithMD5AndDES");
    SimpleStringPBEConfig stringConfig = new SimpleStringPBEConfig();
    stringConfig.setPassword(secretKey);
    encryptor.setConfig(stringConfig);
}