Java Code Examples for org.jasypt.encryption.pbe.config.SimpleStringPBEConfig#setSaltGeneratorClassName()
The following examples show how to use
org.jasypt.encryption.pbe.config.SimpleStringPBEConfig#setSaltGeneratorClassName() .
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: BootTest.java From seed with Apache License 2.0 | 6 votes |
/** * Jasypt加解密屬性文件 */ @Test public void jasyptTest(){ PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor(); SimpleStringPBEConfig config = new SimpleStringPBEConfig(); config.setPassword("https://jadyer.cn/"); config.setAlgorithm("PBEWithMD5AndDES"); config.setKeyObtentionIterations("1000"); config.setPoolSize("1"); config.setProviderName("SunJCE"); config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator"); config.setStringOutputType("hexadecimal"); encryptor.setConfig(config); String encryptStr = encryptor.encrypt("xuanyu"); System.out.println("encryptStr=" + encryptStr); String decryptStr = encryptor.decrypt(encryptStr); Assert.assertEquals("xuanyu", decryptStr); }
Example 2
Source File: JasyptConfiguration.java From seed with Apache License 2.0 | 5 votes |
/** * <p> * BeanPostProcessorBeanFactoryPostProcessor區別可參考http://www.shouce.ren/api/spring2.5/ch03s07.html<br/> * 大致就是BeanFactoryPostProcessor用於Spring註冊BeanDefinition之後,實例化BeanDefinition之前,可修改Bean配置<br/> * 比如常見的配置數據庫連接池dataSource,用戶名和密碼放在獨立的一個配置文件中,然後用${jdbc.name}引用裏面的配置 * </p> */ @Bean public BeanFactoryPostProcessor propertySourcesPostProcessor(){ PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor(); SimpleStringPBEConfig config = new SimpleStringPBEConfig(); //Master Password used for Encryption/Decryption of properties. config.setPassword(this.getProperty(this.environment, "jasypt.encryptor.password", "https://jadyer.cn/")); //Encryption/Decryption Algorithm to be used by Jasypt. //For more info on how to get available algorithms visit: <a href="http://www.jasypt.org/cli.html"/>Jasypt CLI Tools Page</a>. config.setAlgorithm(this.getProperty(this.environment, "jasypt.encryptor.algorithm", "PBEWithMD5AndDES")); //Number of hashing iterations to obtain the signing key. config.setKeyObtentionIterations(this.getProperty(this.environment, "jasypt.encryptor.keyObtentionIterations", "1000")); //The size of the pool of encryptors to be created. config.setPoolSize(this.getProperty(this.environment, "jasypt.encryptor.poolSize", "1")); //The name of the {@link java.security.Provider} implementation to be used by the encryptor for obtaining the encryption algorithm. config.setProviderName(this.getProperty(this.environment, "jasypt.encryptor.providerName", "SunJCE")); //A {@link org.jasypt.salt.SaltGenerator} implementation to be used by the encryptor. config.setSaltGeneratorClassName(this.getProperty(this.environment, "jasypt.encryptor.saltGeneratorClassname", "org.jasypt.salt.RandomSaltGenerator")); //Specify the form in which String output will be encoded. {@code "base64"} or {@code "hexadecimal"}. config.setStringOutputType(this.getProperty(this.environment, "jasypt.encryptor.stringOutputType", "hexadecimal")); encryptor.setConfig(config); return new EnableEncryptablePropertySourcesPostProcessor(encryptor); }
Example 3
Source File: StringEncryptorBuilder.java From jasypt-spring-boot with MIT License | 5 votes |
private StringEncryptor createPBEDefault() { PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor(); SimpleStringPBEConfig config = new SimpleStringPBEConfig(); config.setPassword(getRequired(configProps::getPassword, propertyPrefix + ".password")); config.setAlgorithm(get(configProps::getAlgorithm, propertyPrefix + ".algorithm", "PBEWITHHMACSHA512ANDAES_256")); config.setKeyObtentionIterations(get(configProps::getKeyObtentionIterations, propertyPrefix + ".key-obtention-iterations", "1000")); config.setPoolSize(get(configProps::getPoolSize, propertyPrefix + ".pool-size", "1")); config.setProviderName(get(configProps::getProviderName, propertyPrefix + ".provider-name", null)); config.setProviderClassName(get(configProps::getProviderClassName, propertyPrefix + ".provider-class-name", null)); config.setSaltGeneratorClassName(get(configProps::getSaltGeneratorClassname, propertyPrefix + ".salt-generator-classname", "org.jasypt.salt.RandomSaltGenerator")); config.setIvGeneratorClassName(get(configProps::getIvGeneratorClassname, propertyPrefix + ".iv-generator-classname", "org.jasypt.iv.RandomIvGenerator")); config.setStringOutputType(get(configProps::getStringOutputType, propertyPrefix + ".string-output-type", "base64")); encryptor.setConfig(config); return encryptor; }
Example 4
Source File: Main.java From tutorials with MIT License | 5 votes |
@Bean(name = "encryptorBean") public StringEncryptor stringEncryptor() { PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor(); SimpleStringPBEConfig config = new SimpleStringPBEConfig(); config.setPassword("password"); config.setAlgorithm("PBEWithMD5AndDES"); config.setKeyObtentionIterations("1000"); config.setPoolSize("1"); config.setProviderName("SunJCE"); config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator"); config.setStringOutputType("base64"); encryptor.setConfig(config); return encryptor; }