com.asiapeak.ezpgp4j
Class PGP4j

java.lang.Object
  extended by com.asiapeak.ezpgp4j.PGP4j

public class PGP4j
extends java.lang.Object

PGP Class for PGP Encryption

If the method needs a file, you should specify it to the full path file name, otherwise it is treated as relative to current folder
This class uses ezpgp.ini as configuration file, you should specify it in constructor, or use default ezpgp.ini in user profile folder.
This class also needs a log4j configuration file. you can specify it with "ezConf" variable in JVM, or it is ezpgpc.conf in current directory

Author:
www.asiapeak.com

Constructor Summary
PGP4j()
          Constructor Use "%USERPROFILE%\\ezpgp.ini" as configuration file
PGP4j(java.lang.String iniFile)
          Constructor
 
Method Summary
 int ezChangePass(java.lang.String keyName, java.lang.String oldPass, java.lang.String newPass)
          Change password of a key
 int ezClearSign(java.lang.String inFile, java.lang.String outFile, java.lang.String signKey, java.lang.String passWord)
          Sign a file then output a signature file
 int ezDecryptFile(java.lang.String inFile, java.lang.StringBuilder outName, java.lang.String pass, java.lang.String outDir)
          Decrypt a file and get its original file name
 int ezDecryptFile(java.lang.String inFile, java.lang.String outFile, java.lang.String pass)
          Decrypt a file (and verify it if it was signed)
 int ezEncryptFile(java.lang.String inFile, java.lang.String outFile, java.lang.String keys)
          Encrypt a file
 int ezEncryptSign(java.lang.String inFile, java.lang.String outFile, java.lang.String keys, java.lang.String signKey, java.lang.String passWord)
          Encrypt and sign a file
 java.lang.String ezGetErrMsg(int rc)
          Get error message
 int ezKeyDelete(java.lang.String keyFpr)
          Delete a key
 int ezKeyExport(java.lang.String keyName, java.lang.String fileName, java.lang.Boolean keyPair)
          Export a PGP key
 int ezKeyGen(java.lang.String usrName, java.lang.String eMail, java.lang.String keyType, int keyLen, int days, java.lang.String pwd)
          generate a PGP key pair
 int ezKeyImport(java.lang.String keyFile)
          Import a key file
 java.util.List<PGPkeys> ezListKeys(java.lang.String keyName, java.lang.Boolean bPub)
          List PGP keys
 int ezListKeys(java.lang.StringBuffer allkeys)
          List all keys
 int ezVerify(java.lang.String signFile, java.lang.String inFile)
          Verify the signature file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PGP4j

public PGP4j()
Constructor

Use "%USERPROFILE%\\ezpgp.ini" as configuration file


PGP4j

public PGP4j(java.lang.String iniFile)
Constructor

Parameters:
iniFile - configuration file

The confifuration file has the windows ini file format, the below examples are needed
keydir=C:\\test\\ezpgp\\keys
logfile=C:\\test\\ezpgp\\logs\\ezpgplog.txt
license=7D6791DACFDE1A9FDA17A38B66FBA014 (You should get valid license and put it here)

Method Detail

ezGetErrMsg

public java.lang.String ezGetErrMsg(int rc)
Get error message

Parameters:
rc - return code of your last command
Returns:
error message

ezEncryptFile

public int ezEncryptFile(java.lang.String inFile,
                         java.lang.String outFile,
                         java.lang.String keys)
Encrypt a file

Parameters:
inFile - input file to encrypt
outFile - output file of the encrypted file
keys - PGP keys, separated by ";" if multiple keys
Returns:
0 success
others failed

ezEncryptSign

public int ezEncryptSign(java.lang.String inFile,
                         java.lang.String outFile,
                         java.lang.String keys,
                         java.lang.String signKey,
                         java.lang.String passWord)
Encrypt and sign a file

Parameters:
inFile - input file to encrypt and sign
outFile - output file of the encrypted and signed file
keys - PGP keys, separated by ";" if multiple keys
signKey - signing key
passWord - password of the signing key
Returns:
0 success
others failed

ezClearSign

public int ezClearSign(java.lang.String inFile,
                       java.lang.String outFile,
                       java.lang.String signKey,
                       java.lang.String passWord)
Sign a file then output a signature file

Parameters:
inFile - input file to sign
outFile - output signature file
signKey - signing key
passWord - password of the signing key
Returns:
0 success
others failed

ezDecryptFile

public int ezDecryptFile(java.lang.String inFile,
                         java.lang.String outFile,
                         java.lang.String pass)
Decrypt a file (and verify it if it was signed)

Parameters:
inFile - input file to decrypt
outFile - output file of the decryption file
pass - password of the decryption key (private key)
Returns:
0 success
others failed

ezDecryptFile

public int ezDecryptFile(java.lang.String inFile,
                         java.lang.StringBuilder outName,
                         java.lang.String pass,
                         java.lang.String outDir)
Decrypt a file and get its original file name

Parameters:
inFile - input file to decrypt
outName - output file name (the orignal name of the input file before it was encrypted)
pass - password of the decryption key (private key)
outDir - output directory to save the output file
Returns:
0 success
others failed

ezVerify

public int ezVerify(java.lang.String signFile,
                    java.lang.String inFile)
Verify the signature file. This function is opposite of ezClearSign

Parameters:
signFile - input signature file
inFile - input file to verify its signature file
Returns:
0 success
others failed

ezKeyExport

public int ezKeyExport(java.lang.String keyName,
                       java.lang.String fileName,
                       java.lang.Boolean keyPair)
Export a PGP key

Parameters:
keyName - key name
fileName - the file name to store the key content
keyPair - true if export key pair, false if export public key only.
Returns:
0 success
others failed

ezKeyImport

public int ezKeyImport(java.lang.String keyFile)
Import a key file

Parameters:
keyFile - key file
Returns:
0 success
others failed

ezChangePass

public int ezChangePass(java.lang.String keyName,
                        java.lang.String oldPass,
                        java.lang.String newPass)
Change password of a key

Parameters:
keyName - key name
oldPass - old password
newPass - new password
Returns:
0 success
others failed

ezKeyDelete

public int ezKeyDelete(java.lang.String keyFpr)
Delete a key

Parameters:
keyFpr - key finger print, with 40 bytes of hex string
Returns:
0 success
others failed

ezKeyGen

public int ezKeyGen(java.lang.String usrName,
                    java.lang.String eMail,
                    java.lang.String keyType,
                    int keyLen,
                    int days,
                    java.lang.String pwd)
generate a PGP key pair

Parameters:
usrName - user name
eMail - eMail
keyType - key type, must be "RSA" or "DSA"
keyLen - key length (in bits, e.g 1024,2048)
days - expired days, 0 is never expired
pwd - password of the key
Returns:
0 success
others failed

ezListKeys

public int ezListKeys(java.lang.StringBuffer allkeys)
List all keys

Parameters:
allkeys - the buffer to keep all keys
Returns:
0 success
others failed

ezListKeys

public java.util.List<PGPkeys> ezListKeys(java.lang.String keyName,
                                          java.lang.Boolean bPub)
List PGP keys

Parameters:
keyName - key name, if null it is to list all keys
bPub - true for list public keys, false for list private keys
Returns:
0 success
others failed