Package org.jasypt.encryption.pbe

Examples of org.jasypt.encryption.pbe.StandardPBEStringEncryptor


    public JasyptPasswordEncryptor(CallbackHandler callbackHandler) {
        this(callbackHandler, DEFAULT_ALGORITHM);
    }
   
    public JasyptPasswordEncryptor(CallbackHandler callbackHandler, String algorithm) {
        passwordEncryptor = new StandardPBEStringEncryptor();
        passwordEncryptor.setAlgorithm(algorithm);
       
        WSPasswordCallback pwCb =
            new WSPasswordCallback("", WSPasswordCallback.Usage.PASSWORD_ENCRYPTOR_PASSWORD);
        try {
View Full Code Here


    public synchronized StandardPBEStringEncryptor getEncryptor() {
        if (encryptor == null) {
            // password is mandatory
            ObjectHelper.notEmpty("password", getPassword());

            encryptor = new StandardPBEStringEncryptor();
            encryptor.setPassword(getPassword());
            if (algorithm != null) {
                encryptor.setAlgorithm(getAlgorithm());
            }
        }
View Full Code Here

    @Before
    public void setUp() throws Exception {

        // Configure Jasypt
        enc = new StandardPBEStringEncryptor();
        env = new EnvironmentStringPBEConfig();
        env.setAlgorithm("PBEWithMD5AndDES");
        env.setPassword("password");
        enc.setConfig(env);
View Full Code Here

    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.osgi.framework.storage", "target/osgi/" + System.currentTimeMillis());
        System.setProperty("karaf.name", "root");
View Full Code Here

  public void testPropertiesFilePropertiesEncryption() throws Exception {
    FileOutputStream fos = null;
    FileInputStream fis = null;
    try {
      // Create a encryptor
      StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
      // Configure it
      encryptor.setAlgorithm("PBEWithMD5AndDES");
      encryptor.setPassword(PASSWORD_FOR_ENCRYPTION);
      encryptor.setStringOutputType("base64");
      encryptor.setKeyObtentionIterations(5);
      // Create a properties file accessor that will use encryptor defined
      // above to decrypt value. Note that this class do not encrypt value
      // when we use setProperty() method, we must encrypt ourself the
      // property value an put
      // encrypted property value using the syntax "ENC(encrypted_value)"
      // in the property container. If the encrypted value is not surrounded
      // by "ENC()" the EncryptableProperties object assume that the value isn't
      // encrypted and read it as is...
      Properties properties = new EncryptableProperties(encryptor);
      // Fill properties container
      // --Encrypt value
      String encryptedValue = encryptor.encrypt(TEXT_TO_ENCRYPT);
      // --Add value to the properties container
      properties.setProperty("PASSWORD", "ENC(" + encryptedValue + ")");
      // --Add a non encrypted propety
      properties.setProperty("LOGIN", "MY_LOGIN");
      // Save properties to a file
View Full Code Here

      throws SysCryptoException {

    logger.debug("entering decryptString");

    try {
      StandardPBEStringEncryptor encryptor = initCypher();
      encryptor.setPassword(password);
      String output = encryptor.decrypt(cypher);

      logger.debug("exiting decryptString");
      return output;

    } catch (EncryptionOperationNotPossibleException ex) {
View Full Code Here

   */
  public static String encryptString(String plaintext, String password)
      throws SysCryptoException {
    logger.debug("entering encryptString");
    try {
      StandardPBEStringEncryptor encryptor = initCypher();
      encryptor.setPassword(password);
      String output = encryptor.encrypt(plaintext);

      logger.debug("exiting encryptString");
      return output;

    } catch (EncryptionOperationNotPossibleException ex) {
View Full Code Here

   *
   * @return a standard password based string encryptor
   */
  private static StandardPBEStringEncryptor initCypher() {
    logger.debug("entering initCypher");
    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
    encryptor.setProvider(new BouncyCastleProvider());
    encryptor.setAlgorithm(CRYPTO_ALGORITHM);
    logger.debug("exiting initCypher");
    return encryptor;
  }
View Full Code Here

  static public String encryptPropertyValue(final String text,
      final TYPE_ENCRYP type) throws EncryptDecryptUtilException {
    LOG.info("Starting encryption operation");
    String encryptedPassword = null;
    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
    if (TYPE_ENCRYP.PBES.equals(type)) {
      // Encrypt
      encryptor.setPassword(SEED_PBES);
      encryptedPassword = encryptor.encrypt(text);
    } else if (TYPE_ENCRYP.BC.equals(type)) {
      encryptor.setProvider(new BouncyCastleProvider());
      encryptor.setPassword(SEED_BC);
      encryptor.setAlgorithm("PBEWITHSHA256AND128BITAES-CBC-BC");
      encryptedPassword = encryptor.encrypt(text);
    } else {
      throw new EncryptDecryptUtilException(
          "Error can not determine the type of encryption algorithm to use");
    }
    LOG.info("Encryption done and encrypted password is : "
View Full Code Here

  static public String decryptPropertyValue(final String text,
      final TYPE_ENCRYP type) throws EncryptDecryptUtilException {
    LOG.info("Starting decryption");
    String decrypted = null;
    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
    if (TYPE_ENCRYP.PBES.equals(type)) {
      encryptor.setPassword(SEED_PBES);
      decrypted = encryptor.decrypt(text);
      LOG.info(decrypted);
    } else if (TYPE_ENCRYP.BC.equals(type)) {
      encryptor.setProvider(new BouncyCastleProvider());
      encryptor.setPassword(SEED_BC);
      encryptor.setAlgorithm("PBEWITHSHA256AND128BITAES-CBC-BC");
      decrypted = encryptor.decrypt(text);
      LOG.info(decrypted);
    } else {
      throw new EncryptDecryptUtilException(
          "Error can not determine the type of encryption algorithm to use");
    }
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.