All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jasypt.util.binary.BasicBinaryEncryptor Maven / Gradle / Ivy

There is a newer version: 6.1.4
Show 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.binary;

import org.jasypt.encryption.pbe.StandardPBEByteEncryptor;


/**
 * 

* Utility class for easily performing normal-strength encryption of * binaries (byte arrays). *

*

* This class internally holds a {@link StandardPBEByteEncryptor} * configured this way: *

    *
  • Algorithm: PBEWithMD5AndDES.
  • *
  • Key obtention iterations: 1000.
  • *
*

*

* The required steps to use it are: *

    *
  1. Create an instance (using new).
  2. *
  3. Set a password (using {@link #setPassword(String)} or * {@link #setPasswordCharArray(char[])}).
  4. *
  5. Perform the desired {@link #encrypt(byte[])} or * {@link #decrypt(byte[])} operations.
  6. *
*

*

* This class is thread-safe. *

* * @since 1.2 * * @author Daniel Fernández * */ public final class BasicBinaryEncryptor implements BinaryEncryptor { // The internal encryptor private final StandardPBEByteEncryptor encryptor; /** * Creates a new instance of BasicBinaryEncryptor. */ public BasicBinaryEncryptor() { super(); this.encryptor = new StandardPBEByteEncryptor(); 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 byte array * * @param binary the byte array to be encrypted. * @see StandardPBEByteEncryptor#encrypt(byte[]) */ public byte[] encrypt(final byte[] binary) { return this.encryptor.encrypt(binary); } /** * Decrypts a byte array. * * @param encryptedBinary the byte array to be decrypted. * @see StandardPBEByteEncryptor#decrypt(byte[]) */ public byte[] decrypt(final byte[] encryptedBinary) { return this.encryptor.decrypt(encryptedBinary); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy