org.jasypt.encryption.pbe.config.SimpleStringPBEConfig Java Examples
The following examples show how to use
org.jasypt.encryption.pbe.config.SimpleStringPBEConfig.
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: JasyptConfig.java From spring-boot-vue-admin with Apache License 2.0 | 6 votes |
@Bean public StringEncryptor myStringEncryptor() throws Exception { // Base64 + RSA 加密的密码 final byte[] passwordEncryptedByRSA = Base64Utils.decodeFromString(this.passwordEncryptedByBase64AndRSA); final String password = new String(this.rsaUtils.decrypt(passwordEncryptedByRSA)); // 配置 final SimpleStringPBEConfig config = new SimpleStringPBEConfig() { { this.setPassword(password); // 加密算法 this.setAlgorithm("PBEWithMD5AndDES"); this.setKeyObtentionIterations("1000"); this.setPoolSize("1"); this.setProviderName("SunJCE"); this.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator"); this.setStringOutputType("base64"); } }; final PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor(); encryptor.setConfig(config); return encryptor; }
Example #2
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 #3
Source File: EncryptorConfigBeanDefinitionParser.java From jasypt with Apache License 2.0 | 5 votes |
private static Class<?> computeConfigClass(final Element element) { boolean isSimpleConfig = false; boolean isStringConfig = false; boolean isEnvironmentConfig = false; boolean isStringEnvironmentConfig = false; final NamedNodeMap attributesMap = element.getAttributes(); final int attributesLen = attributesMap.getLength(); for (int i = 0; i < attributesLen; i++) { final Node attribute = attributesMap.item(i); final String attributeName = attribute.getNodeName(); if (!isSimpleConfig && PARAMS_SIMPLE.contains(attributeName)) { isSimpleConfig = true; } if (!isStringConfig && PARAMS_STRING.contains(attributeName)) { isStringConfig = true; } if (!isEnvironmentConfig && PARAMS_ENVIRONMENT.contains(attributeName)) { isEnvironmentConfig = true; } if (!isStringEnvironmentConfig && PARAMS_STRING_ENVIRONMENT.contains(attributeName)) { isStringEnvironmentConfig = true; } } if (isStringEnvironmentConfig || (isEnvironmentConfig && isStringConfig)) { return EnvironmentStringPBEConfig.class; } if (isEnvironmentConfig) { return EnvironmentPBEConfig.class; } if (isStringConfig) { return SimpleStringPBEConfig.class; } return SimplePBEConfig.class; }
Example #4
Source File: EncryptorConfigBeanDefinitionParser.java From jasypt with Apache License 2.0 | 5 votes |
private static Class<?> computeConfigClass(final Element element) { boolean isSimpleConfig = false; boolean isStringConfig = false; boolean isEnvironmentConfig = false; boolean isStringEnvironmentConfig = false; final NamedNodeMap attributesMap = element.getAttributes(); final int attributesLen = attributesMap.getLength(); for (int i = 0; i < attributesLen; i++) { final Node attribute = attributesMap.item(i); final String attributeName = attribute.getNodeName(); if (!isSimpleConfig && PARAMS_SIMPLE.contains(attributeName)) { isSimpleConfig = true; } if (!isStringConfig && PARAMS_STRING.contains(attributeName)) { isStringConfig = true; } if (!isEnvironmentConfig && PARAMS_ENVIRONMENT.contains(attributeName)) { isEnvironmentConfig = true; } if (!isStringEnvironmentConfig && PARAMS_STRING_ENVIRONMENT.contains(attributeName)) { isStringEnvironmentConfig = true; } } if (isStringEnvironmentConfig || (isEnvironmentConfig && isStringConfig)) { return EnvironmentStringPBEConfig.class; } if (isEnvironmentConfig) { return EnvironmentPBEConfig.class; } if (isStringConfig) { return SimpleStringPBEConfig.class; } return SimplePBEConfig.class; }
Example #5
Source File: EncryptorConfigBeanDefinitionParser.java From jasypt with Apache License 2.0 | 5 votes |
private static Class<?> computeConfigClass(final Element element) { boolean isSimpleConfig = false; boolean isStringConfig = false; boolean isEnvironmentConfig = false; boolean isStringEnvironmentConfig = false; final NamedNodeMap attributesMap = element.getAttributes(); final int attributesLen = attributesMap.getLength(); for (int i = 0; i < attributesLen; i++) { final Node attribute = attributesMap.item(i); final String attributeName = attribute.getNodeName(); if (!isSimpleConfig && PARAMS_SIMPLE.contains(attributeName)) { isSimpleConfig = true; } if (!isStringConfig && PARAMS_STRING.contains(attributeName)) { isStringConfig = true; } if (!isEnvironmentConfig && PARAMS_ENVIRONMENT.contains(attributeName)) { isEnvironmentConfig = true; } if (!isStringEnvironmentConfig && PARAMS_STRING_ENVIRONMENT.contains(attributeName)) { isStringEnvironmentConfig = true; } } if (isStringEnvironmentConfig || (isEnvironmentConfig && isStringConfig)) { return EnvironmentStringPBEConfig.class; } if (isEnvironmentConfig) { return EnvironmentPBEConfig.class; } if (isStringConfig) { return SimpleStringPBEConfig.class; } return SimplePBEConfig.class; }
Example #6
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 #7
Source File: EncryptionSecretKeyChecker.java From cosmic with Apache License 2.0 | 5 votes |
public static void initEncryptorForMigration(final String secretKey) { s_encryptor.setAlgorithm("PBEWithMD5AndDES"); final SimpleStringPBEConfig stringConfig = new SimpleStringPBEConfig(); stringConfig.setPassword(secretKey); s_encryptor.setConfig(stringConfig); s_useEncryption = true; }
Example #8
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 #9
Source File: EncryptionSecretKeyChecker.java From cloudstack with Apache License 2.0 | 5 votes |
public static void initEncryptorForMigration(String secretKey) { s_encryptor.setAlgorithm("PBEWithMD5AndDES"); SimpleStringPBEConfig stringConfig = new SimpleStringPBEConfig(); stringConfig.setPassword(secretKey); s_encryptor.setConfig(stringConfig); s_useEncryption = true; }
Example #10
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; }
Example #11
Source File: EncryptionSecretKeyChanger.java From cloudstack with Apache License 2.0 | 4 votes |
private void initEncryptor(StandardPBEStringEncryptor encryptor, String secretKey) { encryptor.setAlgorithm("PBEWithMD5AndDES"); SimpleStringPBEConfig stringConfig = new SimpleStringPBEConfig(); stringConfig.setPassword(secretKey); encryptor.setConfig(stringConfig); }