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

The following examples show how to use org.jasypt.encryption.pbe.StandardPBEStringEncryptor#setPassword() . 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: DBEncryptionUtil.java    From cloudstack with Apache License 2.0 7 votes vote down vote up
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: HibernatePBEStringEncryptor.java    From jasypt with Apache License 2.0 6 votes vote down vote up
/**
 * 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 4
Source File: AnnotatedTemplateTest.java    From fb-botmill with MIT License 6 votes vote down vote up
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 5
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 6
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 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: HibernatePBEStringEncryptor.java    From jasypt with Apache License 2.0 5 votes vote down vote up
/**
 * 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 vote down vote up
/**
 * 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 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: 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 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: ApplicationProperties.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
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 14
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 15
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 16
Source File: Jasypt.java    From spring-boot-api-project-seed with Apache License 2.0 4 votes vote down vote up
/**
 * 加密
 * @param text 明文
 * @return     密文
 */
public static String encrypt(String text) {
    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
    encryptor.setPassword(KEY);
    return encryptor.encrypt(text);
}
 
Example 17
Source File: Jasypt.java    From spring-boot-api-project-seed with Apache License 2.0 4 votes vote down vote up
/**
 * 解密
 * @param ciphertext 密文
 * @return           明文
 */
public static String decrypt(String ciphertext) {
    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
    encryptor.setPassword(KEY);
    return encryptor.decrypt(ciphertext);
}
 
Example 18
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 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: CryptoV1.java    From azkaban-plugins with Apache License 2.0 4 votes vote down vote up
/**
 * DES algorithm
 * @param passphrase
 * @return
 */
private PBEStringEncryptor newEncryptor(String passphrase) {
  StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
  encryptor.setPassword(passphrase);
  return encryptor;
}