Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * =============================================================================
   * 
   *   Copyright (c) 2007, 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;
 

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

This class internally holds a org.jasypt.encryption.pbe.StandardPBEByteEncryptor configured this way:

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

The required steps to use it are:

  1. Create an instance (using new).
  2. Set a password (using setPassword(java.lang.String)).
  3. Perform the desired encrypt(byte[]) or decrypt(byte[]) operations.

This class is thread-safe.

Author(s):
Daniel Fernández Garrido
Since:
1.2
 
 public final class BasicBinaryEncryptor implements BinaryEncryptor {
 
 
     // The internal encryptor 
     private StandardPBEByteEncryptor encryptor = null;
    
    
    
Creates a new instance of BasicBinaryEncryptor.
 
     public BasicBinaryEncryptor() {
         super();
         this. = new StandardPBEByteEncryptor();
         this..setAlgorithm("PBEWithMD5AndDES");
     }

    
    
Sets a password.

Parameters:
password the password to be set.
 
     public void setPassword(String password) {
         .setPassword(password);
     }

    
    
Encrypts a byte array

Parameters:
binary the byte array to be encrypted.
See also:
org.jasypt.encryption.pbe.StandardPBEByteEncryptor.encrypt(byte[])
 
     public byte[] encrypt(byte[] binary) {
         return .encrypt(binary);
     }

    
    
Decrypts a byte array.

Parameters:
encryptedBinary the byte array to be decrypted.
See also:
org.jasypt.encryption.pbe.StandardPBEByteEncryptor.decrypt(byte[])
 
    public byte[] decrypt(byte[] encryptedBinary) {
        return .decrypt(encryptedBinary);
    }
    
New to GrepCode? Check out our FAQ X