
org.jasypt.util.numeric.StrongIntegerNumberEncryptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jasypt Show documentation
Show all versions of jasypt Show documentation
Java library which enables encryption in java apps with minimum effort.
The newest version!
/*
* =============================================================================
*
* 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.numeric;
import java.math.BigInteger;
import org.jasypt.encryption.pbe.StandardPBEBigIntegerEncryptor;
/**
*
* Utility class for easily performing normal-strength encryption of
* BigInteger objects.
*
*
* This class internally holds a {@link StandardPBEBigIntegerEncryptor}
* configured this way:
*
* - Algorithm: PBEWithMD5AndTripleDES.
* - 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(BigInteger)} or
* {@link #decrypt(BigInteger)} operations.
*
*
*
* This class is thread-safe.
*
*
* @since 1.2
*
* @author Daniel Fernández
*
*/
public final class StrongIntegerNumberEncryptor implements IntegerNumberEncryptor {
// The internal encryptor
private final StandardPBEBigIntegerEncryptor encryptor;
/**
* Creates a new instance of StrongIntegerNumberEncryptor.
*/
public StrongIntegerNumberEncryptor() {
super();
this.encryptor = new StandardPBEBigIntegerEncryptor();
this.encryptor.setAlgorithm("PBEWithMD5AndTripleDES");
}
/**
* 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 number
*
* @param number the number to be encrypted.
* @see StandardPBEBigIntegerEncryptor#encrypt(BigInteger)
*/
public BigInteger encrypt(final BigInteger number) {
return this.encryptor.encrypt(number);
}
/**
* Decrypts a number.
*
* @param encryptedNumber the number to be decrypted.
* @see StandardPBEBigIntegerEncryptor#decrypt(BigInteger)
*/
public BigInteger decrypt(final BigInteger encryptedNumber) {
return this.encryptor.decrypt(encryptedNumber);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy