Package org.jasypt.encryption.pbe

Examples of org.jasypt.encryption.pbe.StandardPBEStringEncryptor


    private BundleContext bundleContext;

    @Before
    public void setUp() throws Exception {

        StandardPBEStringEncryptor enc = new StandardPBEStringEncryptor();
        EnvironmentStringPBEConfig env = new EnvironmentStringPBEConfig();
        env.setAlgorithm("PBEWithMD5AndDES");
        env.setPassword("password");
        enc.setConfig(env);
        String val = enc.encrypt("bar");
        System.setProperty("foo", val);

        System.setProperty("org.bundles.framework.storage", "target/bundles/" + System.currentTimeMillis());
        System.setProperty("karaf.name", "root");
View Full Code Here


    }

    final File dbPropsFile = PropertiesUtil.findConfigFile("db.properties");
    final Properties dbProps;
    EncryptionSecretKeyChanger keyChanger = new EncryptionSecretKeyChanger();
    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
    keyChanger.initEncryptor(encryptor, oldMSKey);
    dbProps = new EncryptableProperties(encryptor);
    PropertiesConfiguration backupDBProps = null;

    System.out.println("Parsing db.properties file");
View Full Code Here

    }
  }
 
  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;
View Full Code Here

    public static void initDataSource(String propsFileName) {
        try {
            File dbPropsFile = PropertiesUtil.findConfigFile(propsFileName);
            final Properties dbProps;
            if (EncryptionSecretKeyChecker.useEncryption()) {
                StandardPBEStringEncryptor encryptor = EncryptionSecretKeyChecker.getEncryptor();
                dbProps = new EncryptableProperties(encryptor);
            } else {
                dbProps = new Properties();
            }
            try {
View Full Code Here

    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");
        }
View Full Code Here

   *
   * @return the plaintext as string
   */
  public static String decryptString(String cypher, String password) {

    StandardPBEStringEncryptor encryptor = initCypher();
    encryptor.setPassword(password);
    String output = encryptor.decrypt(cypher);
    return output;
  }
View Full Code Here

   *
   * @return the cyphertext
   */
  public static String encryptString(String plaintext, String password) {

    StandardPBEStringEncryptor encryptor = initCypher();
    encryptor.setPassword(password);
    String output = encryptor.encrypt(plaintext);
    return output;
  }
View Full Code Here

   * Inits the cypher, using the our CRYPTO_ALGORITM.
   *
   * @return a standard password based string encryptor
   */
  private static StandardPBEStringEncryptor initCypher() {
    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
    encryptor.setProvider(new BouncyCastleProvider());
    encryptor.setAlgorithm(CRYPTO_ALGORITHM);
    return encryptor;
  }
View Full Code Here

    private static StringEncryptor getStringEncryptor() {
        if (stringEncryptor == null) {
            synchronized (EncryptionUtils.class) {
                if (stringEncryptor == null) {
                    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
                    encryptor.setPassword(new String(new byte[] { 74, 97, 104, 105, 97, 32, 120,
                            67, 77, 32, 54, 46, 53 }));
                    // encryptor.setAlgorithm("PBEWithMD5AndTripleDES");
                    stringEncryptor = encryptor;
                }
            }
View Full Code Here

    public JasyptPasswordEncryptor(String masterPassword) {
        this(masterPassword, DEFAULT_ALGORITHM);
    }
   
    public JasyptPasswordEncryptor(String masterPassword, String algorithm) {
        passwordEncryptor = new StandardPBEStringEncryptor();
        passwordEncryptor.setPassword(masterPassword);
        passwordEncryptor.setAlgorithm(algorithm);
    }
View Full Code Here

TOP

Related Classes of org.jasypt.encryption.pbe.StandardPBEStringEncryptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.