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

The following examples show how to use org.jasypt.encryption.pbe.StandardPBEStringEncryptor#setAlgorithm() . 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 vote down vote up
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: TestHibernateTypes.java    From jasypt with Apache License 2.0 6 votes vote down vote up
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 3
Source File: JasyptUnitTest.java    From tutorials with 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 4
Source File: HistoryServiceImpl.java    From JuniperBot with GNU General Public License v3.0 6 votes vote down vote up
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 5
Source File: HibernatePBEStringEncryptor.java    From jasypt with Apache License 2.0 5 votes vote down vote up
/**
 * 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 6
Source File: HibernatePBEStringEncryptor.java    From jasypt with Apache License 2.0 5 votes vote down vote up
/**
 * 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 7
Source File: TestHibernateTypes.java    From jasypt with Apache License 2.0 5 votes vote down vote up
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 8
Source File: CryptoV1_1.java    From azkaban-plugins with Apache License 2.0 5 votes vote down vote up
/**
 * 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 9
Source File: HibernatePBEStringEncryptor.java    From jasypt with Apache License 2.0 5 votes vote down vote up
/**
 * 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 10
Source File: EncryptProperty.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
 * 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 11
Source File: TestHibernateTypes.java    From jasypt with Apache License 2.0 5 votes vote down vote up
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: StringEncryptor.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private StringEncryptor(final String aglorithm, final String provider, final String key) {
    encryptor = new StandardPBEStringEncryptor();
    encryptor.setAlgorithm(aglorithm);
    encryptor.setProviderName(provider);
    encryptor.setPassword(key);
    encryptor.setStringOutputType("hexadecimal");
    encryptor.initialize();
}
 
Example 13
Source File: EncryptionSecretKeyChanger.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
private void initEncryptor(StandardPBEStringEncryptor encryptor, String secretKey) {
    encryptor.setAlgorithm("PBEWithMD5AndDES");
    SimpleStringPBEConfig stringConfig = new SimpleStringPBEConfig();
    stringConfig.setPassword(secretKey);
    encryptor.setConfig(stringConfig);
}
 
Example 14
Source File: TestSpringConfiguration.java    From jasypt with Apache License 2.0 4 votes vote down vote up
public void testNamespace() throws Exception {
    
    StandardPBEByteEncryptor standardPBEByteEncryptor = 
           new StandardPBEByteEncryptor();
    standardPBEByteEncryptor.setPassword("jasypt");
    standardPBEByteEncryptor.setAlgorithm("PBEWithMD5AndDES");
       
    ByteEncryptor byteEncryptor = 
           (ByteEncryptor) ctx.getBean(BYTE_ENCRYPTOR_BEAN_NAME);
       assertTrue(ArrayUtils.isEquals(new byte[] {5, 7, 13}, 
               standardPBEByteEncryptor.decrypt(byteEncryptor.encrypt(new byte[] {5, 7, 13}))));
       
       
       
       
    StandardPBEStringEncryptor standardPBEStringEncryptor = 
           new StandardPBEStringEncryptor();
       standardPBEStringEncryptor.setPassword("jasypt");
       standardPBEStringEncryptor.setAlgorithm("PBEWithMD5AndDES");
       standardPBEStringEncryptor.setStringOutputType("hexadecimal");
       
    StringEncryptor stringEncryptor = 
           (StringEncryptor) ctx.getBean(STRING_ENCRYPTOR_BEAN_NAME);
       assertEquals("jasypt", 
               standardPBEStringEncryptor.decrypt(stringEncryptor.encrypt("jasypt")));
       
    
       
       StandardStringDigester standardStringDigester = 
           new StandardStringDigester();
       standardStringDigester.setAlgorithm("SHA-1");
       standardStringDigester.setStringOutputType("hexa");
       
       StringDigester stringDigester = 
           (StringDigester) ctx.getBean(STRING_DIGESTER_BEAN_NAME);
       assertTrue(stringDigester.matches("jasypt", 
               standardStringDigester.digest("jasypt")));
       assertTrue(standardStringDigester.matches("jasypt", 
               stringDigester.digest("jasypt")));
       
}
 
Example 15
Source File: EncryptionUtil.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
private static void initialize(String key) {
    StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
    standardPBEStringEncryptor.setAlgorithm("PBEWITHSHA1ANDDESEDE");
    standardPBEStringEncryptor.setPassword(key);
    encryptor = standardPBEStringEncryptor;
}
 
Example 16
Source File: EncryptionUtil.java    From cosmic with Apache License 2.0 4 votes vote down vote up
private static void initialize(final String key) {
    final StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
    standardPBEStringEncryptor.setAlgorithm("PBEWITHSHA1ANDDESEDE");
    standardPBEStringEncryptor.setPassword(key);
    encryptor = standardPBEStringEncryptor;
}
 
Example 17
Source File: AbstractEncryptedAsStringType.java    From jasypt with Apache License 2.0 4 votes vote down vote up
protected synchronized final void checkInitialization() {
    
    if (!this.initialized) {
        
        if (this.useEncryptorName) {

            final HibernatePBEEncryptorRegistry registry = 
                HibernatePBEEncryptorRegistry.getInstance();
            final PBEStringEncryptor pbeEncryptor = 
                registry.getPBEStringEncryptor(this.encryptorName);
            if (pbeEncryptor == null) {
                throw new EncryptionInitializationException(
                        "No string encryptor registered for hibernate " +
                        "with name \"" + this.encryptorName + "\"");
            }
            this.encryptor = pbeEncryptor;
            
        } else {
            
            final StandardPBEStringEncryptor newEncryptor = 
                new StandardPBEStringEncryptor();
            
            newEncryptor.setPassword(this.password);
            
            if (this.algorithm != null) {
                newEncryptor.setAlgorithm(this.algorithm);
            }
            
            if (this.providerName != null) {
                newEncryptor.setProviderName(this.providerName);
            }
            
            if (this.keyObtentionIterations != null) {
                newEncryptor.setKeyObtentionIterations(
                        this.keyObtentionIterations.intValue());
            }
            
            if (this.stringOutputType != null) {
                newEncryptor.setStringOutputType(this.stringOutputType);
            }
            
            newEncryptor.initialize();
            
            this.encryptor = newEncryptor;
            
        }
        
        this.initialized = true;
    }
    
}
 
Example 18
Source File: AbstractEncryptedAsStringType.java    From jasypt with Apache License 2.0 4 votes vote down vote up
protected synchronized final void checkInitialization() {
    
    if (!this.initialized) {
        
        if (this.useEncryptorName) {

            final HibernatePBEEncryptorRegistry registry = 
                HibernatePBEEncryptorRegistry.getInstance();
            final PBEStringEncryptor pbeEncryptor = 
                registry.getPBEStringEncryptor(this.encryptorName);
            if (pbeEncryptor == null) {
                throw new EncryptionInitializationException(
                        "No string encryptor registered for hibernate " +
                        "with name \"" + this.encryptorName + "\"");
            }
            this.encryptor = pbeEncryptor;
            
        } else {
            
            final StandardPBEStringEncryptor newEncryptor = 
                new StandardPBEStringEncryptor();
            
            newEncryptor.setPassword(this.password);
            
            if (this.algorithm != null) {
                newEncryptor.setAlgorithm(this.algorithm);
            }
            
            if (this.providerName != null) {
                newEncryptor.setProviderName(this.providerName);
            }
            
            if (this.keyObtentionIterations != null) {
                newEncryptor.setKeyObtentionIterations(
                        this.keyObtentionIterations.intValue());
            }
            
            if (this.stringOutputType != null) {
                newEncryptor.setStringOutputType(this.stringOutputType);
            }
            
            newEncryptor.initialize();
            
            this.encryptor = newEncryptor;
            
        }
        
        this.initialized = true;
    }
    
}
 
Example 19
Source File: AbstractEncryptedAsStringType.java    From jasypt with Apache License 2.0 4 votes vote down vote up
protected synchronized final void checkInitialization() {
    
    if (!this.initialized) {
        
        if (this.useEncryptorName) {

            final HibernatePBEEncryptorRegistry registry = 
                HibernatePBEEncryptorRegistry.getInstance();
            final PBEStringEncryptor pbeEncryptor = 
                registry.getPBEStringEncryptor(this.encryptorName);
            if (pbeEncryptor == null) {
                throw new EncryptionInitializationException(
                        "No string encryptor registered for hibernate " +
                        "with name \"" + this.encryptorName + "\"");
            }
            this.encryptor = pbeEncryptor;
            
        } else {
            
            final StandardPBEStringEncryptor newEncryptor = 
                new StandardPBEStringEncryptor();
            
            newEncryptor.setPassword(this.password);
            
            if (this.algorithm != null) {
                newEncryptor.setAlgorithm(this.algorithm);
            }
            
            if (this.providerName != null) {
                newEncryptor.setProviderName(this.providerName);
            }
            
            if (this.keyObtentionIterations != null) {
                newEncryptor.setKeyObtentionIterations(
                        this.keyObtentionIterations.intValue());
            }
            
            if (this.stringOutputType != null) {
                newEncryptor.setStringOutputType(this.stringOutputType);
            }
            
            newEncryptor.initialize();
            
            this.encryptor = newEncryptor;
            
        }
        
        this.initialized = true;
    }
    
}
 
Example 20
Source File: AbstractEncryptedAsStringType.java    From jasypt with Apache License 2.0 4 votes vote down vote up
protected synchronized final void checkInitialization() {
    
    if (!this.initialized) {
        
        if (this.useEncryptorName) {

            final HibernatePBEEncryptorRegistry registry = 
                HibernatePBEEncryptorRegistry.getInstance();
            final PBEStringEncryptor pbeEncryptor = 
                registry.getPBEStringEncryptor(this.encryptorName);
            if (pbeEncryptor == null) {
                throw new EncryptionInitializationException(
                        "No string encryptor registered for hibernate " +
                        "with name \"" + this.encryptorName + "\"");
            }
            this.encryptor = pbeEncryptor;
            
        } else {
            
            final StandardPBEStringEncryptor newEncryptor = 
                new StandardPBEStringEncryptor();
            
            newEncryptor.setPassword(this.password);
            
            if (this.algorithm != null) {
                newEncryptor.setAlgorithm(this.algorithm);
            }
            
            if (this.providerName != null) {
                newEncryptor.setProviderName(this.providerName);
            }
            
            if (this.keyObtentionIterations != null) {
                newEncryptor.setKeyObtentionIterations(
                        this.keyObtentionIterations.intValue());
            }
            
            if (this.stringOutputType != null) {
                newEncryptor.setStringOutputType(this.stringOutputType);
            }
            
            newEncryptor.initialize();
            
            this.encryptor = newEncryptor;
            
        }
        
        this.initialized = true;
    }
    
}