Package au.net.causal.projo.prefs.security.windows

Source Code of au.net.causal.projo.prefs.security.windows.WindowsDpApiEncrypter

package au.net.causal.projo.prefs.security.windows;

import org.jasypt.encryption.ByteEncryptor;
import org.jasypt.exceptions.EncryptionOperationNotPossibleException;

import com.sun.jna.platform.win32.Crypt32Util;
import com.sun.jna.platform.win32.Win32Exception;

/**
* Uses the Windows API to encrypt data using the local user's account's credentials.
*
* @author prunge
*/
public class WindowsDpApiEncrypter implements ByteEncryptor
{
  @Override
  public byte[] encrypt(byte[] binary)
  {
    if (binary == null)
      throw new NullPointerException("binary == null");
   
    try
    {
      byte[] encryptedBinary = Crypt32Util.cryptProtectData(binary);
      return(encryptedBinary);
    }
    catch (Win32Exception e)
    {
      throw new EncryptionOperationNotPossibleException(e);
    }
  }

  @Override
  public byte[] decrypt(byte[] encryptedBinary)
  {
    if (encryptedBinary == null)
      throw new NullPointerException("encryptedBinary == null");
   
    try
    {
      byte[] binary = Crypt32Util.cryptUnprotectData(encryptedBinary);
      return(binary);
    }
    catch (Win32Exception e)
    {
      throw new EncryptionOperationNotPossibleException(e);
    }
  }
}
TOP

Related Classes of au.net.causal.projo.prefs.security.windows.WindowsDpApiEncrypter

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.