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;
}
use of org.jasypt.encryption.pbe.StandardPBEStringEncryptor in project cloudstack by apache.
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;
}
use of org.jasypt.encryption.pbe.StandardPBEStringEncryptor in project cloudstack by apache.
the class EncryptionUtil method initialize.
private static void initialize(String key) {
StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
standardPBEStringEncryptor.setAlgorithm("PBEWITHSHA1ANDDESEDE");
standardPBEStringEncryptor.setPassword(key);
encryptor = standardPBEStringEncryptor;
}
use of org.jasypt.encryption.pbe.StandardPBEStringEncryptor in project cloudstack by apache.
the class DbProperties method getDbProperties.
public static synchronized Properties getDbProperties() {
if (!loaded) {
Properties dbProps = new Properties();
InputStream is = null;
try {
File props = PropertiesUtil.findConfigFile("db.properties");
if (props != null && props.exists()) {
is = new FileInputStream(props);
}
if (is == null) {
is = PropertiesUtil.openStreamFromURL("db.properties");
}
if (is == null) {
System.err.println("Failed to find db.properties");
log.error("Failed to find db.properties");
}
if (is != null) {
dbProps.load(is);
}
EncryptionSecretKeyChecker checker = new EncryptionSecretKeyChecker();
checker.check(dbProps);
if (EncryptionSecretKeyChecker.useEncryption()) {
StandardPBEStringEncryptor encryptor = EncryptionSecretKeyChecker.getEncryptor();
EncryptableProperties encrDbProps = new EncryptableProperties(encryptor);
encrDbProps.putAll(dbProps);
dbProps = encrDbProps;
}
} catch (IOException e) {
throw new IllegalStateException("Failed to load db.properties", e);
} finally {
IOUtils.closeQuietly(is);
}
properties = dbProps;
loaded = true;
}
return properties;
}
use of org.jasypt.encryption.pbe.StandardPBEStringEncryptor in project cloudstack by apache.
the class DBEncryptionUtil method initialize.
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");
}
}
Aggregations