SafeAPI v1.20

com.safeapi
Class CryptoAsym

java.lang.Object
  extended bycom.safeapi.CryptoCommon
      extended bycom.safeapi.CryptoAsym

public final class CryptoAsym
extends CryptoCommon

Asymmetric Cryptography APIs Module


Constructor Summary
CryptoAsym()
          Loads an instance of CryptoAsym.
 
Method Summary
 boolean addRecipient(String sListName, String sKeyID)
          Adds a new recipient to the list.
 void createRecipients(String sListName)
          Creates a new recipient list for RSA file encryption.
 void createRecipientsTune(String sListName, int nInitialCapacity, int nCapacityIncrement)
          Create a new recipient list for RSA file encryption.
 int decryptAndVerify(String sKeyID, char[] caPassphrase, String sSignKeyId, String sInputPath, String sOutputPath)
          Decrypts a file with an asymmetric cipher for the specified secret key and verify signature
 byte[] decryptBuffer(String sKeyID, char[] caPassphrase, byte[] bBuffer)
          Decrypts a buffer with the specified private key for this Key ID
 void decryptFile(String sKeyID, char[] caPassphrase, String sInputPath, String sOutputPath)
          Decrypts a file with an asymmetric cipher for the specified private key
 void encryptAndSign(String sKeyID, char[] caPassphrase, String sListName, String sInputPath, String sOutputPath)
          Signs the specified file and encrypt it with an asymmetric cipher to recipients in the specified list

NOTE : sListName is for further release.
 byte[] encryptBuffer(String sKeyID, byte[] bBuffer)
          Encrypts a buffer with the specified public key for this Key ID
WARNING: Buffer length must be less than 128 bits!
 void encryptFile(String sListName, String sInputPath, String sOutputPath)
          Encrypts a file with an asymmetric cipher to recipients in the specified list NOTE : sListName is for further release.
 void genKeyPair(String sAlgorithm, char[] caPassphrase, int nSize, byte[] bSeed, String sEmailSign, int nIndex)
          Generates a key pair and store keys separately
 String getRecipients(String sListName)
          Gets the recipients list.
 byte[] getSignKeyIdDigest(String sInputPath)
          Gets the ID digest of the key used to sign the file (check if it is signed before!
 boolean isFileSigned(String sInputPath)
          Checks if an encrypted file contains a signature
 byte[] rawSignFile(String sKeyID, char[] caPassphrase, String sFilePath)
          Returns the signature computed for the file with provided private key for this Key ID using the required algorithm.
 boolean rawVerifyFile(String sKeyID, String sFilePath, byte[] bSignature)
          Check the validity of the file signature with the provided public key
 boolean removeRecipient(String sListName, String sKeyID)
          Removes a recipient from the list.
 void removeRecipients(String sListName)
          Deletes the recipients list.
 byte[] signBuffer(String sKeyID, char[] caPassphrase, byte[] bBufferToSign)
          Signs the buffer with the private key for this Key ID using the required algorithm
 void signFile(String sKeyID, char[] caPassphrase, String sFilePath, String sSigFilePath)
          Computes a signature for the file with provided private key Key ID using the required algorithm.
 boolean verifyBuffer(String sKeyID, byte[] bBufferToVerify, byte[] bSignature)
          Verifies the signature of the buffer with the public key for this Key ID using the required algorithm
 boolean verifyFile(String sKeyID, String sFilePath, String sSigFilePath)
          Verifies the validity of the file signature with the provided public key
 
Methods inherited from class com.safeapi.CryptoCommon
createSeedFile, getParameter, getRandomBytes, getRawError, getRegisteredError, getVersion, isOperationOK, setParameter, wipe
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CryptoAsym

public CryptoAsym()
Loads an instance of CryptoAsym.

Method Detail

createRecipients

public void createRecipients(String sListName)
Creates a new recipient list for RSA file encryption.

NOTE : parameter ListName is for later use.

Parameters:
sListName - The name for this list

createRecipientsTune

public void createRecipientsTune(String sListName,
                                 int nInitialCapacity,
                                 int nCapacityIncrement)
Create a new recipient list for RSA file encryption.

NOTE : parameter ListName is for later use.

Parameters:
sListName - The name for this list
nInitialCapacity - The initial capacity of the vector
nCapacityIncrement - The amount by which the capacity is increased when the vector overflows

addRecipient

public boolean addRecipient(String sListName,
                            String sKeyID)
Adds a new recipient to the list.

NOTE : parameter ListName is for later use.

Parameters:
sListName - The name for this list
sKeyID - The key ID for this recipient
Returns:
True if added successfully, false otherwise

removeRecipient

public boolean removeRecipient(String sListName,
                               String sKeyID)
Removes a recipient from the list.

NOTE : parameter ListName is for later use.

Parameters:
sListName - The name for this list
sKeyID - The key ID or file path for this recipient
Returns:
True if removed successfully, false otherwise

removeRecipients

public void removeRecipients(String sListName)
Deletes the recipients list.

NOTE : parameter ListName is for later use.

Parameters:
sListName - The name for this list
Returns:
True if removed successfully, false otherwise

getRecipients

public String getRecipients(String sListName)
Gets the recipients list.

Parameters:
sListName - The name for this list
Returns:
the recipients list

genKeyPair

public void genKeyPair(String sAlgorithm,
                       char[] caPassphrase,
                       int nSize,
                       byte[] bSeed,
                       String sEmailSign,
                       int nIndex)
Generates a key pair and store keys separately

Parameters:
sAlgorithm - The algorithm with which the keys will be used
caPassphrase - The passphrase used to save the private key
nSize - The key size
bSeed - The seed used to generate the key
sEmailSign - The email of the owner
nIndex - The index for this keypair

encryptBuffer

public byte[] encryptBuffer(String sKeyID,
                            byte[] bBuffer)
Encrypts a buffer with the specified public key for this Key ID
WARNING: Buffer length must be less than 128 bits!

Parameters:
sKeyID - The Key ID
bBuffer - The buffer to encrypt, maximum 128 bits length
Returns:
The encrypted buffer

decryptBuffer

public byte[] decryptBuffer(String sKeyID,
                            char[] caPassphrase,
                            byte[] bBuffer)
Decrypts a buffer with the specified private key for this Key ID

Parameters:
sKeyID - The Key ID of the public key to use
caPassphrase - The passphrase protection of the private key
bBuffer - The buffer to decrypt
Returns:
The decrypted buffer

signBuffer

public byte[] signBuffer(String sKeyID,
                         char[] caPassphrase,
                         byte[] bBufferToSign)
Signs the buffer with the private key for this Key ID using the required algorithm

Parameters:
sKeyID - The Key ID of the private key to use
caPassphrase - The passphrase for the private key
bBufferToSign - The buffer to be signed
Returns:
a buffer containing the signature

verifyBuffer

public boolean verifyBuffer(String sKeyID,
                            byte[] bBufferToVerify,
                            byte[] bSignature)
Verifies the signature of the buffer with the public key for this Key ID using the required algorithm

Parameters:
sKeyID - The Key ID of the public key to use
bBufferToVerify - The buffer to be verified
bSignature - The signature for the specified buffer
Returns:
true if the signature is verified, false if not

rawSignFile

public byte[] rawSignFile(String sKeyID,
                          char[] caPassphrase,
                          String sFilePath)
Returns the signature computed for the file with provided private key for this Key ID using the required algorithm.

Parameters:
sKeyID - The Key ID of the private key to use
caPassphrase - The passphrase of the private key
sFilePath - The file to sign
Returns:
The signature of the file

rawVerifyFile

public boolean rawVerifyFile(String sKeyID,
                             String sFilePath,
                             byte[] bSignature)
Check the validity of the file signature with the provided public key

Parameters:
sKeyID - The ID of the RSA public key used for signature
sFilePath - The file to sign
bSignature - The signature to verify
Returns:
true if signature is verified successfully, false if not

signFile

public void signFile(String sKeyID,
                     char[] caPassphrase,
                     String sFilePath,
                     String sSigFilePath)
Computes a signature for the file with provided private key Key ID using the required algorithm. Then it is stored in a file.

Note: If the store path is empty (null), the signed file path is used by adding the extension : Parms.SIGNATURE_FILE_EXTENSION

Parameters:
sKeyID - The Key ID of the RSA private key to use for signature
caPassphrase - The passphrase of the private key
sFilePath - The file to sign
sSigFilePath - The file to store signature

verifyFile

public boolean verifyFile(String sKeyID,
                          String sFilePath,
                          String sSigFilePath)
Verifies the validity of the file signature with the provided public key

Parameters:
sKeyID - The ID of the RSA public key used for signature
sFilePath - The file to sign
sSigFilePath - The file containing the signature
Returns:
true if signature is verified successfully, false if not

encryptFile

public void encryptFile(String sListName,
                        String sInputPath,
                        String sOutputPath)
Encrypts a file with an asymmetric cipher to recipients in the specified list NOTE : sListName is for further release.

Parameters:
sListName - The recipients list name. May contain a KeyId for unique recipient
sInputPath - The full name of the file to encrypt
sOutputPath - The destination file

decryptFile

public void decryptFile(String sKeyID,
                        char[] caPassphrase,
                        String sInputPath,
                        String sOutputPath)
Decrypts a file with an asymmetric cipher for the specified private key

Parameters:
sKeyID - The ID of the RSA private key
caPassphrase - The passphrase which protects this private key
sInputPath - The file to decrypt
sOutputPath - The destination (decrypted) file

encryptAndSign

public void encryptAndSign(String sKeyID,
                           char[] caPassphrase,
                           String sListName,
                           String sInputPath,
                           String sOutputPath)
Signs the specified file and encrypt it with an asymmetric cipher to recipients in the specified list

NOTE : sListName is for further release.

Parameters:
sKeyID - The Key ID of the private key to use for signature
caPassphrase - The passphrase for the signing private key
sListName - The recipients list name
sInputPath - The file to encrypt
sOutputPath - The destination file

decryptAndVerify

public int decryptAndVerify(String sKeyID,
                            char[] caPassphrase,
                            String sSignKeyId,
                            String sInputPath,
                            String sOutputPath)
Decrypts a file with an asymmetric cipher for the specified secret key and verify signature

Parameters:
sKeyID - The Key ID of the private key to use
caPassphrase - The passphrase which protects this private key
sSignKeyId - The Key ID of the private key used for signature
sInputPath - The file to encrypt
sOutputPath - The destination file
Returns:
0 if not signed, 1 if signed & verified, -1 if signed & not verified

isFileSigned

public boolean isFileSigned(String sInputPath)
Checks if an encrypted file contains a signature

Parameters:
sInputPath - the path of the file to check
Returns:
true if it's signed, false if not

getSignKeyIdDigest

public byte[] getSignKeyIdDigest(String sInputPath)
Gets the ID digest of the key used to sign the file (check if it is signed before! :) )

Parameters:
sInputPath - the file of the encrypted file
Returns:
the digested ID of the signer key

SafeAPI v1.20

Copyright © SafeLogic 2005