Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hivelogic2018/a1cb8423f6301dd1f84363415f18a897 to your computer and use it in GitHub Desktop.
Save hivelogic2018/a1cb8423f6301dd1f84363415f18a897 to your computer and use it in GitHub Desktop.
Cryptology - Java
package com.domain.modulo;
import javax.annotation.PostConstruct;
import org.apache.commons.dbcp.BasicDataSource; // optional
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.properties.PropertyValueEncryptionUtils;
public class Cryptology extends BasicDataSource {
// private DBConfig dbConfig;
private static final String KEY = "p13as3Shutd0wnth1sc0mputer";
// @PostConstruct
// void init() {
// setDriverClassName(dbConfig.getDriverClass());
// setUrl(dbConfig.getDbUrl());
// setUsername(dbConfig.getUserName());
// setPassword((decrypt(dbConfig.getPassword())));
// setInitialSize(dbConfig.getInitialSize());
// setMaxActive(dbConfig.getMaxActive());
// setValidationQuery(dbConfig.getValidationQuery());
// setTestOnBorrow(dbConfig.isTestOnBorrow());
// }
/**
* Decrypts the encrypted value. The encrypted value must be enclosed in
* ENC(...)
*
* @param value
* @return
*/
public static String decrypt(String value) {
StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
standardPBEStringEncryptor.setPassword(KEY);
return PropertyValueEncryptionUtils.decrypt(value, standardPBEStringEncryptor);
}
public static void main(String[] args) {
StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
standardPBEStringEncryptor.setPassword(KEY);
String encrypt = PropertyValueEncryptionUtils.encrypt("webappdbconn", standardPBEStringEncryptor);
System.out.println(encrypt);
System.out.println(PropertyValueEncryptionUtils.decrypt(encrypt, standardPBEStringEncryptor));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment