Package net.sourceforge.javautil.common.dsl

Source Code of net.sourceforge.javautil.common.dsl.EncryptionDSL

package net.sourceforge.javautil.common.dsl;

import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

import net.sourceforge.javautil.common.encryption.impl.SimpleEncryptionKey;
import net.sourceforge.javautil.common.encryption.impl.SimpleEncryptionProvider;
import net.sourceforge.javautil.common.encryption.impl.SimpleEncryptionKey.Strength;
import net.sourceforge.javautil.common.exception.ThrowableManagerRegistry;

/**
* Encryption related DSL functionality.
*
* @author elponderador
* @author $Author: ponderator $
* @version $Id: EncryptionDSL.java 2712 2011-01-03 00:32:01Z ponderator $
*/
public class EncryptionDSL {
 
  /**
   * Uses the bytes of the string data for the real data.
   *
   * @see #aesEncrypt(byte[], String)
   */
  public static byte[] aesEncrypt (String data, String key) { return aesEncrypt(data.getBytes(), key.getBytes()); }
 
  /**
   * Uses the bytes of the string key for the real key
   *
   * @see #aesEncrypt(byte[], byte[])
   */
  public static byte[] aesEncrypt (byte[] data, String key) { return aesEncrypt(data, key.getBytes()); }

  /**
   * @param data The data to encrypt
   * @param key The key to use
   * @return The encrypted data
   */
  public static byte[] aesEncrypt (byte[] data, byte[] key) {
    try {
      return new SimpleEncryptionProvider(SimpleEncryptionKey.createUsing(Strength.STRONG, "AES", key)).encrypt(data);
    } catch (InvalidKeyException e) {
      throw ThrowableManagerRegistry.caught(e);
    }
  }
 
}
TOP

Related Classes of net.sourceforge.javautil.common.dsl.EncryptionDSL

TOP
Copyright © 2018 www.massapi.com. 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.