org.jasypt.encryption.pbe.StandardPBEStringEncryptor Java Examples
The following examples show how to use
org.jasypt.encryption.pbe.StandardPBEStringEncryptor.
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: DBEncryptionUtil.java From cosmic with Apache License 2.0 | 12 votes |
private static void initialize() { final Properties dbProps = DbProperties.getDbProperties(); if (EncryptionSecretKeyChecker.useEncryption()) { final String dbSecretKey = dbProps.getProperty("db.cloud.encrypt.secret"); if (dbSecretKey == null || dbSecretKey.isEmpty()) { throw new CloudRuntimeException("Empty DB secret key in db.properties"); } s_encryptor = new StandardPBEStringEncryptor(); s_encryptor.setAlgorithm("PBEWithMD5AndDES"); s_encryptor.setPassword(dbSecretKey); } else { throw new CloudRuntimeException("Trying to encrypt db values when encrytion is not enabled"); } }
Example #2
Source File: DBEncryptionUtil.java From cloudstack with Apache License 2.0 | 7 votes |
private static void initialize() { final Properties dbProps = DbProperties.getDbProperties(); if (EncryptionSecretKeyChecker.useEncryption()) { String dbSecretKey = dbProps.getProperty("db.cloud.encrypt.secret"); if (dbSecretKey == null || dbSecretKey.isEmpty()) { throw new CloudRuntimeException("Empty DB secret key in db.properties"); } s_encryptor = new StandardPBEStringEncryptor(); s_encryptor.setAlgorithm("PBEWithMD5AndDES"); s_encryptor.setPassword(dbSecretKey); } else { throw new CloudRuntimeException("Trying to encrypt db values when encrytion is not enabled"); } }
Example #3
Source File: StringEncryptorTests.java From vividus with Apache License 2.0 | 6 votes |
@Test public void testDecryptProperties() { StandardPBEStringEncryptor standardPBEStringEncryptor = mock(StandardPBEStringEncryptor.class); Properties properties = new Properties(); properties.setProperty(PROPERTY_KEY_FIRST, PROPERTY_VALUE_FIRST); properties.setProperty(PROPERTY_KEY_SECOND, PROPERTY_VALUE_SECOND_ENCRYPTED); when(standardPBEStringEncryptor.decrypt(PROPERTY_VALUE_SECOND)).thenReturn(PROPERTY_VALUE_SECOND); Properties propertiesDecrypted = StringEncryptor.decryptProperties(standardPBEStringEncryptor, properties); assertEquals(properties.getProperty(PROPERTY_KEY_FIRST), propertiesDecrypted.getProperty(PROPERTY_KEY_FIRST)); assertEquals(PROPERTY_VALUE_SECOND, propertiesDecrypted.getProperty(PROPERTY_KEY_SECOND)); }
Example #4
Source File: TestHibernateTypes.java From jasypt with Apache License 2.0 | 6 votes |
private void registerEncryptors() { StandardPBEStringEncryptor stringEncryptor = new StandardPBEStringEncryptor(); stringEncryptor.setAlgorithm("PBEWithMD5AndDES"); stringEncryptor.setPassword("jasypt-hibernate5-test"); StandardPBEByteEncryptor byteEncryptor = new StandardPBEByteEncryptor(); byteEncryptor.setAlgorithm("PBEWithMD5AndDES"); byteEncryptor.setPassword("jasypt-hibernate5-test"); StandardPBEBigIntegerEncryptor bigIntegerEncryptor = new StandardPBEBigIntegerEncryptor(); bigIntegerEncryptor.setAlgorithm("PBEWithMD5AndDES"); bigIntegerEncryptor.setPassword("jasypt-hibernate5-test"); StandardPBEBigDecimalEncryptor bigDecimalEncryptor = new StandardPBEBigDecimalEncryptor(); bigDecimalEncryptor.setAlgorithm("PBEWithMD5AndDES"); bigDecimalEncryptor.setPassword("jasypt-hibernate5-test"); HibernatePBEEncryptorRegistry registry = HibernatePBEEncryptorRegistry.getInstance(); registry.registerPBEStringEncryptor("hibernateStringEncryptor", stringEncryptor); registry.registerPBEByteEncryptor("hibernateByteEncryptor", byteEncryptor); registry.registerPBEBigIntegerEncryptor("hibernateBigIntegerEncryptor", bigIntegerEncryptor); registry.registerPBEBigDecimalEncryptor("hibernateBigDecimalEncryptor", bigDecimalEncryptor); }
Example #5
Source File: HistoryServiceImpl.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
private StringEncryptor getEncryptor(TextChannel channel, String iv) { StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor(); encryptor.setAlgorithm("PBEWithHMACSHA512AndAES_256"); encryptor.setPassword(String.format("%s:%s", channel.getGuild().getId(), channel.getId())); encryptor.setIvGenerator(new StringFixedIvGenerator(iv)); return encryptor; }
Example #6
Source File: AnnotatedTemplateTest.java From fb-botmill with MIT License | 6 votes |
public static void main(String[] args) { StandardPBEStringEncryptor enc = new StandardPBEStringEncryptor(); enc.setPassword("password"); // can be sourced out ConfigurationUtils.loadEncryptedConfigurationFile(enc, "botmill.properties"); List<BotDefinition> botDef = new ArrayList<BotDefinition>(); botDef.add(new AnnotatedTemplatedBehaviourTest()); ConfigurationUtils.loadBotConfig(); ConfigurationUtils.setBotDefinitionInstance(botDef); for(int i=0;i<10;i++) { new Thread(new Runnable() { String json = "{\"sender\":{\"id\":\"1158621824216736\"},\"recipient\":{\"id\":\"1226565047419159\"},\"timestamp\":1490832021661,\"message\":{\"mid\":\"mid.$cAAUPCFn4ymdhTcignVbHH3rzpKd_\",\"seq\":844819,\"text\":\"Hi!\"}}"; MessageEnvelope envelope = FbBotMillJsonUtils.fromJson(json, MessageEnvelope.class); @Override public void run() { try { IncomingToOutgoingMessageHandler.getInstance().process(envelope); }catch(Exception e) { e.printStackTrace(); } } }).start(); } }
Example #7
Source File: StringEncryptor.java From vividus with Apache License 2.0 | 6 votes |
public static Properties decryptProperties(StandardPBEStringEncryptor standardPBEStringEncryptor, Properties properties) { for (Map.Entry<Object, Object> entry : properties.entrySet()) { String value = (String) entry.getValue(); Matcher matcher = ENCRYPTED_PROPERTY_PATTERN.matcher(value); if (matcher.matches()) { entry.setValue(standardPBEStringEncryptor.decrypt(matcher.group(1))); } } return properties; }
Example #8
Source File: HibernatePBEStringEncryptor.java From jasypt with Apache License 2.0 | 6 votes |
/** * Sets the password to be used by the internal encryptor, if a specific * encryptor has not been set with <tt>setEncryptor(...)</tt>. * * @param password the password to be set for the internal encryptor */ public void setPassword(final String password) { 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.setPassword(password); }
Example #9
Source File: HibernatePBEStringEncryptor.java From jasypt with Apache License 2.0 | 5 votes |
/** * Sets the IV generator to be used by the internal encryptor, * if a specific encryptor has not been set with <tt>setEncryptor(...)</tt>. * * @param ivGenerator the IV generator to be set for the internal * encryptor. */ public void setIvGenerator(final IvGenerator ivGenerator) { 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.setIvGenerator(ivGenerator); }
Example #10
Source File: BaseWebApplicationTests.java From hdw-dubbo with Apache License 2.0 | 5 votes |
/** * 加密 * @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 #11
Source File: TestHibernateTypes.java From jasypt with Apache License 2.0 | 5 votes |
private void registerEncryptors() { StandardPBEStringEncryptor stringEncryptor = new StandardPBEStringEncryptor(); stringEncryptor.setAlgorithm("PBEWithMD5AndDES"); stringEncryptor.setPassword("jasypt-hibernate3-test"); StandardPBEByteEncryptor byteEncryptor = new StandardPBEByteEncryptor(); byteEncryptor.setAlgorithm("PBEWithMD5AndDES"); byteEncryptor.setPassword("jasypt-hibernate3-test"); HibernatePBEEncryptorRegistry registry = HibernatePBEEncryptorRegistry.getInstance(); registry.registerPBEStringEncryptor("hibernateStringEncryptor", stringEncryptor); registry.registerPBEByteEncryptor("hibernateByteEncryptor", byteEncryptor); }
Example #12
Source File: DataUtil.java From framework with Apache License 2.0 | 5 votes |
/** * 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 #13
Source File: EncryptProperty.java From cia with Apache License 2.0 | 5 votes |
/** * Gets the encryptor. * * @param symmetricKey * the symmetric key * @return the encryptor */ private static StandardPBEStringEncryptor getEncryptor(final String symmetricKey) { Security.addProvider(new BouncyCastleProvider()); final StandardPBEStringEncryptor mySecondEncryptor = new StandardPBEStringEncryptor(); mySecondEncryptor.setProviderName(BC_PROVIDER_NAME); mySecondEncryptor.setAlgorithm(PBEWITHSHA256AND128BITAES_CBC_BC); mySecondEncryptor.setPassword(symmetricKey); return mySecondEncryptor; }
Example #14
Source File: ApplicationProperties.java From mycollab with GNU Affero General Public License v3.0 | 5 votes |
public static void loadProps() { StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor(); encryptor.setPassword(DECRYPT_PASS); properties = new EncryptableProperties(encryptor); try { File configFile = getAppConfigFile(); if (configFile != null) { try (InputStreamReader isr = new InputStreamReader(new FileInputStream(configFile), "UTF-8")) { properties.load(isr); } } else { InputStream propStreams = Thread.currentThread().getContextClassLoader().getResourceAsStream(RESOURCE_PROPERTIES); if (propStreams == null) { // Probably we are running testing InputStream propStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("default-mycollab-test.properties"); if (propStream != null) { try (InputStreamReader isr = new InputStreamReader(propStream, "UTF-8")) { properties.load(isr); } } } } } catch (Exception e) { throw new MyCollabException(e); } }
Example #15
Source File: EncryptionConfig.java From bearchoke with Apache License 2.0 | 5 votes |
@Bean public StandardPBEStringEncryptor standardPBEStringEncryptor() { StandardPBEStringEncryptor sse = new StandardPBEStringEncryptor(); sse.setConfig(environmentStringPBEConfig()); return sse; }
Example #16
Source File: MrGeoPropertiesTest.java From mrgeo with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { MrGeoProperties.resetProperties(); StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor(); encryptor.setPassword(TEST_MASTER_PASSWORD); encryptedValue = "ENC(" + encryptor.encrypt(decryptedValue) + ")"; }
Example #17
Source File: CryptoV1_1.java From azkaban-plugins with Apache License 2.0 | 5 votes |
/** * AES algorithm * @param passphrase * @return */ private PBEStringEncryptor newEncryptor(String passphrase) { StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor(); encryptor.setPassword(passphrase); encryptor.setProvider(PROVIDER); encryptor.setAlgorithm(CRYPTO_ALGO); return encryptor; }
Example #18
Source File: DataUtil.java From framework with Apache License 2.0 | 5 votes |
/** * 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 #19
Source File: HibernatePBEStringEncryptor.java From jasypt with Apache License 2.0 | 5 votes |
/** * Sets the JCE provider to be used by the internal encryptor, * if a specific encryptor has not been set with <tt>setEncryptor(...)</tt>. * * @since 1.3 * * @param provider the JCE provider to be used */ public void setProvider(final Provider provider) { 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.setProvider(provider); }
Example #20
Source File: HibernatePBEStringEncryptor.java From jasypt with Apache License 2.0 | 5 votes |
/** * Sets the name of the JCE provider to be used by the internal encryptor, * if a specific encryptor has not been set with <tt>setEncryptor(...)</tt>. * * @since 1.3 * * @param providerName the name of the JCE provider (already registered) */ public void setProviderName(final String providerName) { 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.setProviderName(providerName); }
Example #21
Source File: HibernatePBEStringEncryptor.java From jasypt with Apache License 2.0 | 5 votes |
/** * Sets the JCE provider to be used by the internal encryptor, * if a specific encryptor has not been set with <tt>setEncryptor(...)</tt>. * * @since 1.3 * * @param provider the JCE provider to be used */ public void setProvider(final Provider provider) { 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.setProvider(provider); }
Example #22
Source File: HibernatePBEStringEncryptor.java From jasypt with Apache License 2.0 | 5 votes |
/** * Sets the key obtention iterations to be used by the internal encryptor, * if a specific encryptor has not been set with <tt>setEncryptor(...)</tt>. * * @param keyObtentionIterations to be set for the internal encryptor */ public void setKeyObtentionIterations(final int keyObtentionIterations) { 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.setKeyObtentionIterations( keyObtentionIterations); }
Example #23
Source File: HibernatePBEStringEncryptor.java From jasypt with Apache License 2.0 | 5 votes |
/** * Sets the key obtention iterations to be used by the internal encryptor, * if a specific encryptor has not been set with <tt>setEncryptor(...)</tt>. * * @param keyObtentionIterations to be set for the internal encryptor */ public void setKeyObtentionIterations(final int keyObtentionIterations) { 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.setKeyObtentionIterations( keyObtentionIterations); }
Example #24
Source File: HibernatePBEStringEncryptor.java From jasypt with Apache License 2.0 | 5 votes |
/** * Sets the type of String output ("base64" (default), "hexadecimal") to * be used by the internal encryptor, * if a specific encryptor has not been set with <tt>setEncryptor(...)</tt>. * * @since 1.3 * * @param stringOutputType the type of String output */ public void setStringOutputType(final String stringOutputType) { 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.setStringOutputType(stringOutputType); }
Example #25
Source File: HibernatePBEStringEncryptor.java From jasypt with Apache License 2.0 | 5 votes |
/** * Sets the algorithm to be used by the internal encryptor, if a specific * encryptor has not been set with <tt>setEncryptor(...)</tt>. * * @param algorithm the algorithm to be set for the internal encryptor */ public void setAlgorithm(final String algorithm) { 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.setAlgorithm(algorithm); }
Example #26
Source File: HibernatePBEStringEncryptor.java From jasypt with Apache License 2.0 | 5 votes |
/** * Sets the password to be used by the internal encryptor (as a char[]), if a specific * encryptor has not been set with <tt>setEncryptor(...)</tt>. * * @since 1.8 * @param password the password to be set for the internal encryptor */ public void setPasswordCharArray(final char[] password) { 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.setPasswordCharArray(password); }
Example #27
Source File: HibernatePBEStringEncryptor.java From jasypt with Apache License 2.0 | 5 votes |
/** * Sets the salt generator to be used by the internal encryptor, * if a specific encryptor has not been set with <tt>setEncryptor(...)</tt>. * * @param saltGenerator the salt generator to be set for the internal * encryptor. */ public void setSaltGenerator(final SaltGenerator saltGenerator) { 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.setSaltGenerator(saltGenerator); }
Example #28
Source File: HibernatePBEStringEncryptor.java From jasypt with Apache License 2.0 | 5 votes |
/** * Sets the name of the JCE provider to be used by the internal encryptor, * if a specific encryptor has not been set with <tt>setEncryptor(...)</tt>. * * @since 1.3 * * @param providerName the name of the JCE provider (already registered) */ public void setProviderName(final String providerName) { 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.setProviderName(providerName); }
Example #29
Source File: HibernatePBEStringEncryptor.java From jasypt with Apache License 2.0 | 5 votes |
/** * Sets the password to be used by the internal encryptor, if a specific * encryptor has not been set with <tt>setEncryptor(...)</tt>. * * @param password the password to be set for the internal encryptor */ public void setPassword(final String password) { 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.setPassword(password); }
Example #30
Source File: HibernatePBEStringEncryptor.java From jasypt with Apache License 2.0 | 5 votes |
/** * 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); }