Search in sources :

Example 6 with StandardPBEStringEncryptor

use of org.jasypt.encryption.pbe.StandardPBEStringEncryptor in project divide by HiddenStage.

the class AuthTokenUtils method encrypt.

private static String encrypt(String string, String key) {
    StandardPBEStringEncryptor encryptor = getEncryptor(key);
    String encrypted = encryptor.encrypt(string);
    return Base64.encode(encrypted);
}
Also used : StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor)

Example 7 with StandardPBEStringEncryptor

use of org.jasypt.encryption.pbe.StandardPBEStringEncryptor in project divide by HiddenStage.

the class AuthTokenUtils method getEncryptor.

private static StandardPBEStringEncryptor getEncryptor(String key) {
    StandardPBEStringEncryptor encryptor;
    if (encryptors.containsKey(key))
        encryptor = encryptors.get(key);
    else {
        encryptor = new StandardPBEStringEncryptor();
        encryptor.setPassword(key);
    }
    return encryptor;
}
Also used : StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor)

Example 8 with StandardPBEStringEncryptor

use of org.jasypt.encryption.pbe.StandardPBEStringEncryptor in project CloudStack-archive by CloudStack-extras.

the class DBEncryptionUtil method initialize.

private static void initialize() {
    final File dbPropsFile = PropertiesUtil.findConfigFile("db.properties");
    final Properties dbProps;
    if (EncryptionSecretKeyChecker.useEncryption()) {
        StandardPBEStringEncryptor encryptor = EncryptionSecretKeyChecker.getEncryptor();
        dbProps = new EncryptableProperties(encryptor);
        try {
            dbProps.load(new FileInputStream(dbPropsFile));
        } catch (FileNotFoundException e) {
            throw new CloudRuntimeException("db.properties file not found while reading DB secret key", e);
        } catch (IOException e) {
            throw new CloudRuntimeException("Erroe while reading DB secret key from db.properties", e);
        }
        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");
    }
}
Also used : StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor) EncryptableProperties(org.jasypt.properties.EncryptableProperties) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) EncryptableProperties(org.jasypt.properties.EncryptableProperties) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 9 with StandardPBEStringEncryptor

use of org.jasypt.encryption.pbe.StandardPBEStringEncryptor in project CloudStack-archive by CloudStack-extras.

the class EncryptionSecretKeyChanger method migrateProperties.

private boolean migrateProperties(File dbPropsFile, Properties dbProps, String newMSKey, String newDBKey) {
    System.out.println("Migrating db.properties..");
    StandardPBEStringEncryptor msEncryptor = new StandardPBEStringEncryptor();
    ;
    initEncryptor(msEncryptor, newMSKey);
    try {
        PropertiesConfiguration newDBProps = new PropertiesConfiguration(dbPropsFile);
        if (newDBKey != null && !newDBKey.isEmpty()) {
            newDBProps.setProperty("db.cloud.encrypt.secret", "ENC(" + msEncryptor.encrypt(newDBKey) + ")");
        }
        String prop = dbProps.getProperty("db.cloud.password");
        if (prop != null && !prop.isEmpty()) {
            newDBProps.setProperty("db.cloud.password", "ENC(" + msEncryptor.encrypt(prop) + ")");
        }
        prop = dbProps.getProperty("db.usage.password");
        if (prop != null && !prop.isEmpty()) {
            newDBProps.setProperty("db.usage.password", "ENC(" + msEncryptor.encrypt(prop) + ")");
        }
        newDBProps.save(dbPropsFile.getAbsolutePath());
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    System.out.println("Migrating db.properties Done.");
    return true;
}
Also used : StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) EncryptionOperationNotPossibleException(org.jasypt.exceptions.EncryptionOperationNotPossibleException)

Example 10 with StandardPBEStringEncryptor

use of org.jasypt.encryption.pbe.StandardPBEStringEncryptor in project fb-botmill by BotMill.

the class AnnotatedTemplateTest method main.

public static void main(String[] args) {
    StandardPBEStringEncryptor enc = new StandardPBEStringEncryptor();
    // can be sourced out
    enc.setPassword("password");
    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();
    }
}
Also used : BotDefinition(co.aurasphere.botmill.core.BotDefinition) StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor) ArrayList(java.util.ArrayList) MessageEnvelope(co.aurasphere.botmill.fb.model.incoming.MessageEnvelope) AnnotatedTemplatedBehaviourTest(co.aurasphere.botmill.fb.test.autoreply.template.AnnotatedTemplatedBehaviourTest)

Aggregations

StandardPBEStringEncryptor (org.jasypt.encryption.pbe.StandardPBEStringEncryptor)16 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 IOException (java.io.IOException)6 Properties (java.util.Properties)6 FileNotFoundException (java.io.FileNotFoundException)5 EncryptableProperties (org.jasypt.properties.EncryptableProperties)5 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 SQLException (java.sql.SQLException)4 ConfigurationException (org.apache.commons.configuration.ConfigurationException)4 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)4 EncryptionOperationNotPossibleException (org.jasypt.exceptions.EncryptionOperationNotPossibleException)4 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 PojoServiceRegistryFactoryImpl (org.apache.felix.connect.PojoServiceRegistryFactoryImpl)2 BundleDescriptor (org.apache.felix.connect.launch.BundleDescriptor)2 ClasspathScanner (org.apache.felix.connect.launch.ClasspathScanner)2 PojoServiceRegistry (org.apache.felix.connect.launch.PojoServiceRegistry)2 EnvironmentStringPBEConfig (org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig)2