org.jasypt.util.text.BasicTextEncryptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of activemq-osgi Show documentation
Show all versions of activemq-osgi Show documentation
Puts together an ActiveMQ OSGi bundle
/*
* =============================================================================
*
* Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* =============================================================================
*/
package org.jasypt.util.text;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
/**
*
* Utility class for easily performing normal-strength encryption of texts.
*
*
* This class internally holds a {@link StandardPBEStringEncryptor}
* configured this way:
*
* - Algorithm: PBEWithMD5AndDES.
* - Key obtention iterations: 1000.
*
*
*
* The required steps to use it are:
*
* - Create an instance (using new).
* - Set a password (using {@link #setPassword(String)} or
* {@link #setPasswordCharArray(char[])}).
* - Perform the desired {@link #encrypt(String)} or
* {@link #decrypt(String)} operations.
*
*
*
* This class is thread-safe.
*
*
* @since 1.2 (class existed as org.jasypt.util.TextEncryptor since 1.0)
*
* @author Daniel Fernández
*
*/
public final class BasicTextEncryptor implements TextEncryptor {
// The internal encryptor
private final StandardPBEStringEncryptor encryptor;
/**
* Creates a new instance of BasicTextEncryptor.
*/
public BasicTextEncryptor() {
super();
this.encryptor = new StandardPBEStringEncryptor();
this.encryptor.setAlgorithm("PBEWithMD5AndDES");
}
/**
* Sets a password.
*
* @param password the password to be set.
*/
public void setPassword(final String password) {
this.encryptor.setPassword(password);
}
/**
* Sets a password, as a char[]
*
* @since 1.8
* @param password the password to be set.
*/
public void setPasswordCharArray(final char[] password) {
this.encryptor.setPasswordCharArray(password);
}
/**
* Encrypts a message.
*
* @param message the message to be encrypted.
* @see StandardPBEStringEncryptor#encrypt(String)
*/
public String encrypt(final String message) {
return this.encryptor.encrypt(message);
}
/**
* Decrypts a message.
*
* @param encryptedMessage the message to be decrypted.
* @see StandardPBEStringEncryptor#decrypt(String)
*/
public String decrypt(final String encryptedMessage) {
return this.encryptor.decrypt(encryptedMessage);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy