com.didisoft.pgp
Class PGPLib

java.lang.Object
  extended by com.didisoft.pgp.bc.BaseLib
      extended by com.didisoft.pgp.PGPLib

public class PGPLib
extends com.didisoft.pgp.bc.BaseLib

OpenPGP Library for Java.
The library provides methods that can work with or without an OpenPGP KeyStore
(Note that the OpenPGP Key Store format this library uses, is different from the JDK Key Store format which is X.509 based.)
Supported JDK versions: 1.4, 1.5, 1.6, 1.7, 1.8


Copyright DidiSoft Inc Eood
www.didisoft.com/java-openpgp/


Field Summary
 
Fields inherited from class com.didisoft.pgp.bc.BaseLib
BOUNCY_CASTLE_PROVIDER
 
Constructor Summary
PGPLib()
          The default constructor of the library.
 
Method Summary
 void clearSignFile(java.lang.String inputFileName, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String hashingAlgorithm, java.lang.String outputFileName)
          OpenPGP clear signs a file.
 void clearSignFileVersion3(java.lang.String inputFileName, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String hashingAlgorithm, java.lang.String outputFileName)
          OpenPGP clear signs a file, using OpenPGP version 3 signature format (old format used by PGP 2.x)

Use when needed compatibility with PGP 2.x

GPG equivalent command: gpg --force-v3-sigs --clearsign inputFileName

Example:

 java.lang.String clearSignString(java.lang.String stringToSign, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String hashingAlgorithm)
          OpenPGP clear signs a String

Example usage:

 java.lang.String clearSignStringVersion3(java.lang.String stringToSign, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String hashingAlgorithm)
          OpenPGP clear signs a String, using OpenPGP version 3 signature format (the old format)

Use when needed compatibility with PGP 2.x and PGP 5.x systems.
 SignatureCheckResult decryptAndVerify(java.io.InputStream encryptedStream, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword, java.io.InputStream publicKeyStream, java.io.OutputStream outputStream)
          Decrypts and verifies OpenPGP encrypted and signed stream.
 SignatureCheckResult decryptAndVerify(java.io.InputStream encryptedStream, KeyStore keyStore, java.lang.String privateKeyPassword, java.io.OutputStream outputStream)
          Decrypts and verifies OpenPGP encrypted and signed stream.
 SignatureCheckResult decryptAndVerify(java.lang.String encryptedFileName, KeyStore keyStore, java.lang.String privateKeyPassword, java.lang.String outputFileName)
          Decrypts and verifies one pass encrypted and signed OpenPGP file
Supports OpenPGP version 3 format too (used by PGP 6.5 and below).
 SignatureCheckResult decryptAndVerify(java.lang.String encryptedFileName, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String publicKeyFile, java.lang.String outputFileName)
          Decrypts and verifies an OpenPGP encrypted and signed file
Supports OpenPGP version 3 format too (used by PGP(r) 5 and below).
 SignatureCheckResult decryptAndVerify(java.lang.String message, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String publicKeyFileName, java.lang.StringBuffer decryptedString)
          Decrypts and verifies an OpenPGP one pass signed end encrypted message.
 SignatureCheckResult decryptAndVerify(java.lang.String message, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String publicKeyFileName, java.lang.StringBuffer decryptedString, java.lang.String charsetName)
          Decrypts and verifies an OpenPGP one pass signed end encrypted message.
 boolean decryptAndVerifyFile(java.lang.String encryptedFileName, KeyStore keyStore, java.lang.String privateKeyPassword, java.lang.String outputFileName)
          Deprecated. Due to misleading return value. Please use decryptAndVerify(String, KeyStore, String, String) instead
 boolean decryptAndVerifyFile(java.lang.String encryptedFileName, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String publicKeyFile, java.lang.String outputFileName)
          Deprecated. Due to misleading return value. Please use decryptAndVerifyFile(String, String, String, String, String) instead
 boolean decryptAndVerifyFileTo(java.lang.String encryptedFileName, KeyStore keyStore, java.lang.String privateKeyPassword, java.lang.String outputFolder)
          Deprecated. Due to misleading return value. Please use decryptAndVerify(String, KeyStore, String, String) instead
 boolean decryptAndVerifyFileTo(java.lang.String encryptedFileName, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String publicKeyFile, java.lang.String outputFolder)
          Deprecated. Due to misleading return value. Please use decryptAndVerifyTo(String, String, String, String, String) instead
 boolean decryptAndVerifyStream(java.io.InputStream encryptedStream, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword, java.io.InputStream publicKeyStream, java.io.OutputStream outputStream)
          Deprecated. Due to misleading return value. Please use decryptAndVerify(InputStream, InputStream, String, InputStream, OutputStream) instead
 boolean decryptAndVerifyStream(java.io.InputStream encryptedStream, KeyStore keyStore, java.lang.String privateKeyPassword, java.io.OutputStream outputStream)
          Deprecated. Due to misleading return value. Please use decryptAndVerifyStream(InputStream, KeyStore, String, OutputStream) instead
 boolean decryptAndVerifyStreamTo(java.io.InputStream encryptedStream, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword, java.io.InputStream publicKeyStream, java.lang.String outputFolder)
          Deprecated. Due to misleading return value. Please use decryptAndVerifyTo(InputStream, InputStream, String, InputStream, String) instead
 boolean decryptAndVerifyStreamTo(java.io.InputStream encryptedStream, KeyStore keyStore, java.lang.String privateKeyPassword, java.lang.String outputFolder)
          Deprecated. Due to misleading return value. Please use decryptAndVerifyTo(InputStream, KeyStore, String, String) instead
 boolean decryptAndVerifyString(java.lang.String message, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword, java.io.InputStream publicKeyStream, java.lang.StringBuffer decryptedString, java.lang.String charsetName)
          Deprecated. Due to misleading return value. Please use decryptAndVerify(String, String, String, String, StringBuffer, String) instead
 boolean decryptAndVerifyString(java.lang.String message, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String publicKeyFileName, java.lang.StringBuffer decryptedString)
          Deprecated. Due to misleading return value. Please use decryptAndVerify(String, String, String, String, StringBuffer) instead
 boolean decryptAndVerifyString(java.lang.String message, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String publicKeyFileName, java.lang.StringBuffer decryptedString, java.lang.String charsetName)
          Deprecated. Due to misleading return value. Please use decryptAndVerify(String, String, String, String, StringBuffer, String) instead
 SignatureCheckResult decryptAndVerifyTo(java.io.InputStream encryptedStream, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword, java.io.InputStream publicKeyStream, java.lang.String outputFolder)
          Verifies the signature and decrypts an OpenPGP encrypted and signed stream contents into a folder
Supports OpenPGP version 3 format too (used by PGP 6.5 and below).
 SignatureCheckResult decryptAndVerifyTo(java.io.InputStream encryptedStream, KeyStore keyStore, java.lang.String privateKeyPassword, java.lang.String outputFolder)
          Decrypts and verifies OpenPGP encrypted and signed stream.
 SignatureCheckResult decryptAndVerifyTo(java.lang.String encryptedFileName, KeyStore keyStore, java.lang.String privateKeyPassword, java.lang.String outputFolder)
          Verifies the signature and decrypts a one pass signed and encrypted OpenPGP file into a folder
Supports OpenPGP version 3 format too (used by PGP 6.5 and below).
 SignatureCheckResult decryptAndVerifyTo(java.lang.String encryptedFileName, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String publicKeyFile, java.lang.String outputFolder)
          Decrypts and verifies an OpenPGP encrypted and signed file to a folder
This methods is very suitable for multi file PGP archives.
 java.lang.String decryptFile(java.lang.String encryptedFileName, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword, java.lang.String outputFileName)
          Decrypts an OpenPGP encrypted file using Private key input stream.
 java.lang.String decryptFile(java.lang.String encryptedFileName, KeyStore pgpKeyStore, java.lang.String privateKeyPassword, java.lang.String outputFileName)
          Decrypts an OpenPGP encrypted file using key from a OpenPGP key store.
 java.lang.String decryptFile(java.lang.String encryptedFileName, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String outputFileName)
          Decrypts an OpenPGP encrypted file using Private key file.
 java.lang.String decryptFilePBE(java.lang.String encryptedFileName, java.lang.String decryptionPassword, java.lang.String outputFileName)
          Decrypts an OpenPGP file that was encrypted with password (PBE, symmetric key encrypted).
 java.lang.String[] decryptFileTo(java.lang.String encryptedFileName, KeyStore keyStore, java.lang.String privateKeyPassword, java.lang.String outputFolder)
          Decrypts the content of an OpenPGP encrypted file into a folder.
 java.lang.String[] decryptFileTo(java.lang.String encryptedFileName, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String outputFolder)
          Decrypts the content of an OpenPGP encrypted file into a folder.
 java.lang.String decryptStream(java.io.InputStream encryptedStream, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword, java.io.OutputStream outputStream)
          Decrypts an OpenPGP encrypted stream using Private key input stream.
 java.lang.String decryptStream(java.io.InputStream encryptedStream, KeyStore pgpKeyStore, java.lang.String privateKeyPassword, java.io.OutputStream outputStream)
          Decrypts an OpenPGP encrypted stream using a private key supplied as an input stream.
 java.lang.String decryptStreamPBE(java.io.InputStream encryptedStream, java.lang.String decryptionPassword, java.io.OutputStream outputStream)
          Decrypts an OpenPGP stream that was encrypted with a password (PBE, symmetric key encrypted).
 java.lang.String[] decryptStreamTo(java.io.InputStream encryptedStream, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword, java.lang.String outputFolder)
          Decrypts an OpenPGP encrypted stream to a specified folder.
 java.lang.String[] decryptStreamTo(java.io.InputStream encryptedStream, KeyStore keyStore, java.lang.String privateKeyPassword, java.lang.String outputFolder)
          Decrypts an OpenPGP encrypted stream to a specified folder.
 java.lang.String decryptString(java.lang.String message, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword)
          Decrypts an OpenPGP encrypted UTF-8 string message.
 java.lang.String decryptString(java.lang.String message, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword, java.lang.String charsetName)
          Decrypts an OpenPGP encrypted string message.
 java.lang.String decryptString(java.lang.String message, KeyStore keyStore, java.lang.String privateKeyPassword)
          Decrypts an OpenPGP encrypted UTF-8 string message.
 java.lang.String decryptString(java.lang.String message, KeyStore keyStore, java.lang.String privateKeyPassword, java.lang.String charsetName)
          Decrypts an OpenPGP encrypted string message.
 java.lang.String decryptString(java.lang.String message, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword)
          Decrypts an OpenPGP encrypted UTF-8 string message

Example:
 java.lang.String decryptString(java.lang.String message, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String charsetName)
          Decrypts an OpenPGP encrypted string message.
 java.lang.String decryptStringPBE(java.lang.String message, java.lang.String decryptionPassword)
          Decrypts an OpenPGP password encrypted UTF-8 string message.
 java.lang.String decryptStringPBE(java.lang.String message, java.lang.String decryptionPassword, java.lang.String charsetName)
          Decrypts an OpenPGP password encrypted string message.
 void detachedSignFile(java.lang.String dataFileName, KeyStore keyStore, long privateKeyId, java.lang.String privateKeyPassword, java.lang.String detachedSignatureFileName, boolean asciiArmor)
          Creates an OpenPGP detached signature for a given file.
 void detachedSignFile(java.lang.String dataFileName, KeyStore keyStore, java.lang.String privateKeyUserId, java.lang.String privateKeyPassword, java.lang.String detachedSignatureFileName, boolean asciiArmor)
          Creates an OpenPGP detached signature for a given file.
 void detachedSignFile(java.lang.String dataFileName, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String detachedSignatureFileName, boolean asciiArmor)
          Creates an OpenPGP detached signature for a given file.
 void detachedSignStream(java.io.InputStream dataStream, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword, java.io.OutputStream outStream, boolean asciiArmor)
          Creates an OpenPGP detached signature for a given data stream contents.
 void detachedSignStream(java.io.InputStream dataStream, KeyStore keyStore, long keyId, java.lang.String privateKeyPassword, java.io.OutputStream outStream, boolean asciiArmor)
          Creates an OpenPGP detached signature for a given data stream contents.
 void detachedSignStream(java.io.InputStream dataStream, KeyStore keyStore, java.lang.String userId, java.lang.String privateKeyPassword, java.io.OutputStream outStream, boolean asciiArmor)
          Creates an OpenPGP detached signature for a given data stream contents.
 SignatureCheckResult detachedVerify(java.io.InputStream dataFileStream, java.io.InputStream detachedSignatureStream, java.io.InputStream publicKeyStream)
          Verifies that an OpenPGP detached signature is signed from a trusted sender.
 SignatureCheckResult detachedVerify(java.io.InputStream dataFileStream, java.io.InputStream detachedSignatureStream, KeyStore keyStore)
          Verifies that an OpenPGP detached signature is signed from a trusted sender.
 SignatureCheckResult detachedVerify(java.lang.String message, java.lang.String detachedSignature, KeyStore keyStore)
          Verifies that an OpenPGP detached signature is signed from a trusted sender.
 SignatureCheckResult detachedVerify(java.lang.String message, java.lang.String detachedSignature, java.lang.String publicKeyFile)
          Verifies that an OpenPGP detached signature is signed from a trusted sender.
 boolean detachedVerifyStream(java.io.InputStream dataFileStream, java.io.InputStream detachedSignatureStream, java.io.InputStream publicKeyStream)
          Verifies that an OpenPGP detached signature is signed from a trusted sender.
 boolean detachedVerifyStream(java.io.InputStream dataFileStream, java.io.InputStream detachedSignatureStream, KeyStore keyStore)
          Verifies that an OpenPGP detached signature is signed from a trusted sender.
 void encryptFile(java.lang.String dataFileName, java.io.InputStream publicKeyStream, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP encrypts given file using the first available public key from a key ring input stream

Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:

 void encryptFile(java.lang.String dataFileName, KeyStore keyStore, long[] recipientsKeyIds, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP encrypts a file for multiple recipients.


Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:
 void encryptFile(java.lang.String dataFileName, KeyStore keyStore, long keyId, java.lang.String outputFileName)
          OpenPGP encrypts given file using specified public key, stored in specified OpenPGP key store.
 void encryptFile(java.lang.String dataFileName, KeyStore keyStore, long keyId, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP encrypts given file using specified public key, stored in specified OpenPGP key store.
 void encryptFile(java.lang.String dataFileName, KeyStore keyStore, java.lang.String[] recipientsUserIds, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP encrypts a file for multiple recipients.


Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:

 void encryptFile(java.lang.String dataFileName, KeyStore keyStore, java.lang.String userId, java.lang.String outputFileName)
          OpenPGP encrypts given file using specified public key, stored in specified OpenPGP key store.
 void encryptFile(java.lang.String dataFileName, KeyStore keyStore, java.lang.String userId, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP encrypts given file using specified public key, stored in specified OpenPGP key store.
 void encryptFile(java.lang.String dataFileName, java.lang.String[] publicKeysFileNames, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP encrypts a file for multiple recipients.


Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example usage:

 void encryptFile(java.lang.String dataFileName, java.lang.String publicKeyFileName, java.lang.String outputFileName, boolean asciiArmor)
          OpenPGP encrypts given file using the public key of the recipient.
 void encryptFile(java.lang.String dataFileName, java.lang.String publicKeyFileName, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP encrypts given file using the public key of the recipient.
 int encryptFileByKeyId(KeyStore keyStore, java.lang.String dataFileName, java.lang.String keyIdHex, java.lang.String outputFileName)
          Deprecated. Use instead
 int encryptFileByUserId(KeyStore keyStore, java.lang.String dataFileName, java.lang.String userID, java.lang.String outputFileName)
          Deprecated. Use instead
 void encryptFilePBE(java.lang.String dataFileName, java.lang.String password, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck)
          Encrypts a file with a passphrase.
The same passphrase is used to decrypt the file

Equivalent GnuPG command:
gpg -c -e [dataFileName]

Compression algorithm used is the one specified with setCompression(String) if supported by the public key, otherwise the first supported by the key algorithm is used.
 void encryptFilePBE(java.lang.String dataFileName, java.lang.String publicKeyFileName, java.lang.String alternativePassword, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck)
          Encrypts a file with a public key and a passphrase.
The passphrase can be used to decrypt the file if the corresponding private key is lost.
 void encryptFiles(java.lang.String[] dataFileNames, KeyStore keyStore, long[] recipientsKeyIds, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP encrypts multiple files into one OpenPGP archive

Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example usage:

 void encryptFiles(java.lang.String[] dataFileNames, KeyStore keyStore, java.lang.String[] recipientsUserIds, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP encrypts multiple files into one OpenPGP archive

Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:

 void encryptFiles(java.lang.String[] dataFileNames, java.lang.String[] publicKeysFileNames, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP encrypts multiple files into one OpenPGP archive.
 void encryptFiles(java.lang.String[] dataFileNames, java.lang.String publicKeyFileName, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP encrypts multiple files into one OpenPGP archive.
 void encryptStream(java.io.InputStream dataStream, java.lang.String fileName, java.io.InputStream[] publicKeyStreams, java.io.OutputStream outputStream, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP encrypts an input stream using the first available Public key from a Key ring input stream

Compression algorithm used is the one specified with #setCompression(CompressionAlgorithm) if supported by the public key, otherwise the first supported by the key algorithm is used.
 void encryptStream(java.io.InputStream dataStream, java.lang.String fileName, java.io.InputStream publicKeyStream, java.io.OutputStream outputStream, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP encrypts an input stream using the first available Public key from a Key ring input stream

Compression algorithm used is the one specified with setCompression(String) if supported by the public key, otherwise the first supported by the key algorithm is used.
 void encryptStream(java.io.InputStream dataStream, java.lang.String fileName, KeyStore keyStore, long[] keyIds, java.io.OutputStream out, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP encrypts input stream using recipients' public keys located in a KeyStore

Compression algorithm used is the one specified with #setCompression(CompressionAlgorithm) if supported by the public key, otherwise the first supported by the key algorithm is used.
 void encryptStream(java.io.InputStream dataStream, java.lang.String fileName, KeyStore keyStore, long keyId, java.io.OutputStream out, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP encrypts input stream using a recipient public key located in a KeyStore

Compression algorithm used is the one specified with setCompression(String) if supported by the public key, otherwise the first supported by the key algorithm is used.
 void encryptStream(java.io.InputStream dataStream, java.lang.String fileName, KeyStore keyStore, java.lang.String[] userIds, java.io.OutputStream out, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP Encrypts Input Stream using a Public key located in a KeyStore

Compression algorithm used is the one specified with #setCompression(CompressionAlgorithm) if supported by the public key, otherwise the first supported by the key algorithm is used.
 void encryptStream(java.io.InputStream dataStream, java.lang.String fileName, KeyStore keyStore, java.lang.String userId, java.io.OutputStream out, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP Encrypts Input Stream using a Public key located in a KeyStore

Compression algorithm used is the one specified with setCompression(String) if supported by the public key, otherwise the first supported by the key algorithm is used.
 void encryptStream(java.io.InputStream dataStream, java.lang.String fileName, long streamLength, java.io.InputStream publicKeyStream, java.io.OutputStream out, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP encrypts an input stream using the first available public key supplied as an input stream

Compression algorithm used is the one specified with setCompression(String) if supported by the public key, otherwise the first supported by the key algorithm is used.
 void encryptStream(java.io.InputStream dataStream, java.lang.String fileName, long streamLength, java.lang.String publicKeyFileName, java.io.OutputStream out, boolean asciiArmor)
          OpenPGP encrypts stream using the first available public key from a key ring file.
 void encryptStream(java.io.InputStream dataStream, java.lang.String fileName, long streamLength, java.lang.String publicKeyFileName, java.io.OutputStream out, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP encrypts stream using the first available public key from a key ring file.
 void encryptStream(java.io.InputStream dataStream, java.lang.String fileName, PGPKeyPair publicKey, java.io.OutputStream outputStream, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP encrypts an input stream using the first available Public key from a Key ring input stream

Compression algorithm used is the one specified with setCompression(String) if supported by the public key, otherwise the first supported by the key algorithm is used.
 void encryptStreamPBE(java.io.InputStream dataStream, java.lang.String fileNameLabel, java.lang.String password, java.io.OutputStream out, boolean asciiArmor, boolean withIntegrityCheck)
          Encrypts an input stream with a password based OpenPGP encryption (PBE)

Compression algorithm used is the one specified with setCompression(String) if supported by the public key, otherwise the first supported by the key algorithm is used.
 java.lang.String encryptString(java.lang.String stringToEncrypt, java.io.InputStream publicEncryptionKeyStream)
          OpenPGP encrypts a String UTF-8 message
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:
 java.lang.String encryptString(java.lang.String stringToEncrypt, java.io.InputStream publicEncryptionKeyStream, java.lang.String charsetName)
          OpenPGP encrypts a String message
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:
 java.lang.String encryptString(java.lang.String stringToEncrypt, KeyStore keyStore, long keyId)
          OpenPGP encrypts a UTF-8 String message

Example:
 java.lang.String encryptString(java.lang.String stringToEncrypt, KeyStore keyStore, long[] keyIds, java.lang.String charsetName)
          OpenPGP encrypts a String message for multiple recipients

Example:
 java.lang.String encryptString(java.lang.String stringToEncrypt, KeyStore keyStore, long keyId, java.lang.String charsetName)
          OpenPGP encrypts a String message

Example:
 java.lang.String encryptString(java.lang.String stringToEncrypt, KeyStore keyStore, java.lang.String userId)
          OpenPGP encrypts a UTF-8 String message

Example:
 java.lang.String encryptString(java.lang.String stringToEncrypt, KeyStore keyStore, java.lang.String[] keyIdOrUserIds, java.lang.String charsetName)
          OpenPGP encrypts a String message for multiple recipients

Example:
 java.lang.String encryptString(java.lang.String stringToEncrypt, KeyStore keyStore, java.lang.String userId, java.lang.String charsetName)
          OpenPGP encrypts a String message

Example:
 java.lang.String encryptString(java.lang.String stringToEncrypt, java.lang.String publicKeyFileName)
          OpenPGP encrypts a UTF-8 encoded string message
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:
 java.lang.String encryptString(java.lang.String stringToEncrypt, java.lang.String[] publicKeyFileNames, java.lang.String charsetName)
          OpenPGP encrypts a String message
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:
 java.lang.String encryptString(java.lang.String stringToEncrypt, java.lang.String publicKeyFileName, java.lang.String charsetName)
          OpenPGP encrypts a String message
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:
 java.lang.String encryptStringPBE(java.lang.String stringToEncrypt, java.lang.String encryptionPassword)
          OpenPGP encrypts a UTF-8 String message with a password
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:
 java.lang.String encryptStringPBE(java.lang.String stringToEncrypt, java.lang.String encryptionPassword, java.lang.String charsetName)
          OpenPGP encrypts a String message with a password
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:
 java.lang.String getAsciiCommentHeader()
          Returns the Comment text that is printed in ASCII armored output
 java.lang.String getAsciiVersionHeader()
          Returns the Version comment text that is printed in ASCII armored output
 java.lang.String getCompression()
          Returns the preferred compression algorithm used by all methods that produce OpenPGP messages (e.g Encrypt, Sign, etc.)
Default is ZIP
 char getContentType()
          Returns the content data type for archives created afterwards
 java.lang.String getCypher()
          Returns the preferred symmetric key algorithm used by all methods that produce OpenPGP messages (e.g Encrypt, Sign, etc.)
Default is CAST5
 java.util.logging.Level getDebugLevel()
          Returns the current debug level.
 boolean isExtractTarFiles()
          Checks is the library set to extract embedded TAR files
 boolean isOverrideKeyAlgorithmPreferences()
          returns will the algorithms choosed with setCompression(String), setCypher(String), setHash(String) override the used key preferences
 boolean isPgp2Compatible()
          Checks is PGP 2.x encryption and signing compatibility mode enabled
 boolean isTrialVersion()
          Checks is this an evaluation instance of the library
 boolean isUseExpiredKeys()
          Returns should expired keys still be used
Default is false
 boolean isUseRevokedKeys()
          Returns should revoked keys still be used
Default is false
 void setAsciiVersionHeader(java.lang.String creator)
          Sets the Version comment text that is printed in ASCII armored output

Example usage:
 void setCompression(java.lang.String compression)
          Sets the preferred compression algorithm used by all methods that produce OpenPGP messages (e.g Encrypt, Sign, etc.)
 void setContentType(char type)
          Sets the content data type for archives created afterwards
 void setCypher(java.lang.String cypher)
          Sets the preferred symmetric key algorithm used by all methods that produce OpenPGP messages (e.g Encrypt, Sign, etc.)
 void setDebuglevel(java.util.logging.Level level)
          Sets the current debug information log level
 void setExtractTarFiles(boolean extractTarFiles)
          Sets should the library extract embedded TAR files
 void setHash(java.lang.String hash)
          Sets the preferred hashing algorithm used by all methods that produce OpenPGP signature (all Sign and SigneAndEncrypt methods)
 void setOverrideKeyAlgorithmPreferences(boolean overrideKeyAlgorithmPreferences)
          Sets will the algorithms choosed with setCompression(String), setCypher(String), setHash(String) override the used key preferences
 void setPgp2Compatible(boolean pgp2Compatible)
          Sets PGP 2.x encryption and signing compatibility mode
 void setUseExpiredKeys(boolean value)
          Sets should expired keys still be used
 void setUseRevokedKeys(boolean value)
          Sets should revoked keys still be used
 void signAndEncryptFile(java.lang.String fileName, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword, java.io.InputStream publicKeyStream, java.io.OutputStream outputStream, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP signs and encrypts a file in one pass.
 void signAndEncryptFile(java.lang.String fileName, KeyStore keyStore, long signKeyId, java.lang.String privateKeyPassword, long[] encKeyIds, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP signs and encrypts a file in one pass for multiple recipients.
 void signAndEncryptFile(java.lang.String fileName, KeyStore keyStore, long signKeyId, java.lang.String privateKeyPassword, long encKeyId, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP signs and encrypts a file in one pass.
 void signAndEncryptFile(java.lang.String fileName, KeyStore keyStore, java.lang.String signUserId, java.lang.String privateKeyPassword, java.lang.String[] encUserIds, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP signs and encrypts a file in one pass for multiple recipients.
 void signAndEncryptFile(java.lang.String fileName, KeyStore keyStore, java.lang.String signUserId, java.lang.String privateKeyPassword, java.lang.String encUserId, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP signs and encrypts a file in one pass.
 void signAndEncryptFile(java.lang.String dataFileName, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String[] publicKeyFiles, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP signs and encrypts a file in one pass.
 void signAndEncryptFile(java.lang.String dataFileName, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String publicKeyFile, java.lang.String outputFileName, boolean asciiArmor)
          OpenPGP signs and encrypts a file in one pass.
 void signAndEncryptFile(java.lang.String dataFileName, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String publicKeyFile, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP signs and encrypts a file in one pass.
 void signAndEncryptFileVersion3(java.lang.String dataFileName, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String publicKeyFile, java.lang.String outputFileName, boolean asciiArmor)
          OpenPGP signs and encrypts a file in one pass, using OpenPGP version 3 signature format (compatible with PGP 6.5 and below)

(Note that this is not the same as first encrypt and then sign a file, because in that case a double compression is performed.)
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 void signAndEncryptFileVersion3(java.lang.String dataFileName, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String publicKeyFile, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP signs and encrypts a file in one pass, using OpenPGP version 3 signature format (compatible with PGP 6.5 and below)

(Note that this is not the same as first encrypt and then sign a file, because in that case a double compression is performed.)
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 void signAndEncryptStream(java.io.InputStream dataStream, java.lang.String internalFileName, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword, java.io.InputStream[] publicKeyStreams, java.io.OutputStream outputStream, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP signs and encrypts a stream in one pass.
 void signAndEncryptStream(java.io.InputStream dataStream, java.lang.String internalFileName, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword, java.io.InputStream publicKeyStream, java.io.OutputStream outputStream, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP signs and encrypts a stream in one pass.
 void signAndEncryptStream(java.io.InputStream dataFileStream, java.lang.String internalFileName, KeyStore keyStore, java.lang.String signUserId, java.lang.String privateKeyPassword, long[] encKeyIds, java.io.OutputStream outputStream, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP signs and encrypts a file in one pass for multiple recipients

(Note that this is not the same as first encrypt and then sign a file, because in that case a double compression is performed.)
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 void signAndEncryptStream(java.io.InputStream dataFileStream, java.lang.String internalFileName, KeyStore keyStore, java.lang.String signUserId, java.lang.String privateKeyPassword, java.lang.String[] encUserIds, java.io.OutputStream outputStream, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP signs and encrypts a file in one pass for multiple recipients

(Note that this is not the same as first encrypt and then sign a file, because in that case a double compression is performed.)
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 void signAndEncryptStream(java.io.InputStream dataFileStream, java.lang.String internalFileName, KeyStore keyStore, java.lang.String signUserId, java.lang.String privateKeyPassword, java.lang.String encUserId, java.io.OutputStream outputStream, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP signs and encrypts a file in one pass.
 void signAndEncryptStreamVersion3(java.io.InputStream dataFileStream, java.lang.String internalFileName, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword, java.io.InputStream publicKeyStream, java.io.OutputStream outputStream, boolean asciiArmor)
          OpenPGP signs and encrypts a file in one pass, using OpenPGP version 3 signature format (compatible with PGP 6.5 and below)
(Note that this is not the same as first encrypt and then sign a file, because in that case a double compression is performed.)
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 void signAndEncryptStreamVersion3(java.io.InputStream dataFileStream, java.lang.String internalFileName, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword, java.io.InputStream publicKeyStream, java.io.OutputStream outputStream, boolean asciiArmor, boolean withIntegrityCheck)
          OpenPGP signs and encrypts a file in one pass, using OpenPGP version 3 signature format (compatible with older PGP 2.x systems)
(Note that this is not the same as first encrypt and then sign a file, because in that case a double compression is performed.)
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 void signAndEncryptStreamVersion3(java.io.InputStream dataFileStream, java.lang.String internalFileName, KeyStore keyStore, long signingKeyId, java.lang.String privateKeyPassword, long encryptionKeyId, java.io.OutputStream outputStream, boolean asciiArmor)
          OpenPGP signs and encrypts a file in one pass, using OpenPGP version 3 signature format (compatible with PGP 6.5 and below)
(Note that this is not the same as first encrypt and then sign a file, because in that case a double compression is performed.)
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 void signAndEncryptStreamVersion3(java.io.InputStream dataFileStream, java.lang.String internalFileName, KeyStore keyStore, java.lang.String signingKeyUserId, java.lang.String privateKeyPassword, java.lang.String encryptionKeyUserId, java.io.OutputStream outputStream, boolean asciiArmor)
          OpenPGP signs and encrypts a file in one pass, using OpenPGP version 3 signature format (compatible with PGP 6.5 and below)
(Note that this is not the same as first encrypt and then sign a file, because in that case a double compression is performed.)
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 java.lang.String signAndEncryptString(java.lang.String stringToEncrypt, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String publicKeyFileName)
          OpenPGP signs and encrypts a String message in one pass
The input String is assumed to be UTF-8 encoded.
 java.lang.String signAndEncryptString(java.lang.String stringToEncrypt, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String publicKeyFileName, java.lang.String charsetName)
          OpenPGP signs and encrypts a String message in one pass
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 java.lang.String signAndEncryptStringVersion3(java.lang.String stringToEncrypt, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String publicKeyFileName)
          OpenPGP signs and encrypts a String message in one pass with OpenPGP version 3 signatures
The input String is assumed to be UTF-8 encoded.
 java.lang.String signAndEncryptStringVersion3(java.lang.String stringToEncrypt, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String publicKeyFileName, java.lang.String charsetName)
          OpenPGP signs and encrypts a String message in one pass creating OpenPGP version 3 signatures
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 void signFile(KeyStore keyStore, java.lang.String dataFileName, long privateKeyId, java.lang.String privateKeyPassword, java.lang.String outputFileName)
          OpenPGP signs given file using specified Private Key, using OpenPGP Key Store.
 void signFile(KeyStore keyStore, java.lang.String dataFileName, java.lang.String keyIdHex, java.lang.String privateKeyPassword, java.lang.String outputFileName)
          OpenPGP signs given file using specified Private Key, using OpenPGP Key Store.
 void signFile(java.lang.String fileName, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword, java.io.OutputStream out, boolean asciiArmor)
          OpenPGP signs a file.
 void signFile(java.lang.String dataFileName, KeyStore keyStore, long privateKeyId, java.lang.String privateKeyPassword, java.lang.String outputFileName, boolean asciiArmor)
          OpenPGP signs a file, with private key stored in a KeyStore object.
 void signFile(java.lang.String dataFileName, KeyStore keyStore, java.lang.String privateKeyUserId, java.lang.String privateKeyPassword, java.lang.String outputFileName, boolean asciiArmor)
          OpenPGP signs a file, with private key stored in a KeyStore object.
 void signFile(java.lang.String inputFileName, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String outputFileName, boolean asciiArmor)
          OpenPGP signs a file.
 void signFileVersion3(java.lang.String fileName, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, java.lang.String outputFileName, boolean asciiArmor)
          Signs a file in OpenPGP version 3 format (compatible with PGP 2.x systems)

Optional settings:
Compression algorithm used is the one specified with setCompression(String)
Hashing algorithm used is the one specified with setHash(String)

Example usage:

 void signStream(java.io.InputStream dataInputStream, java.lang.String fileNameLabel, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword, java.io.OutputStream signedStream, boolean asciiArmor)
          OpenPGP signs a stream.
 void signStream(java.io.InputStream dataInputStream, java.lang.String fileNameLabel, KeyStore keyStore, long signingKeyId, java.lang.String privateKeyPassword, java.io.OutputStream signedStream, boolean asciiArmor)
          OpenPGP signs stream with a private key stored in a KeyStore.
 void signStream(java.io.InputStream dataInputStream, java.lang.String fileNameLabel, KeyStore keyStore, java.lang.String signingKeyUserId, java.lang.String privateKeyPassword, java.io.OutputStream signedStream, boolean asciiArmor)
          OpenPGP signs stream with a private key stored in a KeyStore.
 void signStreamVersion3(java.io.InputStream dataFileStream, java.lang.String internalFileName, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword, java.io.OutputStream out, boolean asciiArmor)
          Signs a stream using OpenPGP version 3 signatures format (compatible with PGP 2.x systems)

Optional settings:
Compression algorithm used is the one specified with setCompression(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 java.lang.String signString(java.lang.String message, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword, java.lang.String charsetName)
          OpenPGP signs a String message

Example:
 java.lang.String signString(java.lang.String message, KeyStore keyStore, long privateKeyId, java.lang.String privateKeyPassword, java.lang.String charsetName)
          OpenPGP signs a String message

Example:
 java.lang.String signString(java.lang.String message, KeyStore keyStore, java.lang.String privateKeyUserId, java.lang.String privateKeyPassword, java.lang.String charsetName)
          OpenPGP signs a String message

Example:
 java.lang.String signString(java.lang.String message, java.lang.String privateKeyFile, java.lang.String privateKeyPassword)
          OpenPGP signs a String message assuming the message is UTF-8 encoded

Example:
 java.lang.String signString(java.lang.String message, java.lang.String privateKeyFile, java.lang.String privateKeyPassword, java.lang.String charsetName)
          OpenPGP signs a String message

Example:
 SignatureCheckResult verifyAndExtract(java.io.File dataFile, java.io.File publicKeyFile, java.io.File outputFile)
          Verifies a file for being correctly OpenPGP signed and extracts the data

Example:
 SignatureCheckResult verifyAndExtract(java.io.File dataFile, KeyStore keyStore, java.io.File outputFile)
          Verifies a file for being correctly OpenPGP signed and extracts the data

Example:
 SignatureCheckResult verifyAndExtract(java.io.InputStream dataFileStream, java.io.InputStream publicKeyStream, java.io.OutputStream outputFileStream)
          Verifies a stream for being correctly OpenPGP signed and extracts its data

Example:
 SignatureCheckResult verifyAndExtract(java.io.InputStream dataFileStream, KeyStore keyStore, java.io.OutputStream outputFileStream)
          Verifies an incoming stream for being correctly OpenPGP signed and extracts its data

Example:
 SignatureCheckResult verifyAndExtract(java.lang.String dataFileName, KeyStore keyStore, java.lang.String outputFileName)
          Verifies a file for being correctly OpenPGP signed and extracts the data

Example:
 SignatureCheckResult verifyAndExtract(java.lang.String message, KeyStore keyStore, java.lang.StringBuffer decryptedString)
          Verifies an OpenPGP signed only message and extracts the contents

 SignatureCheckResult verifyAndExtract(java.lang.String message, KeyStore keyStore, java.lang.StringBuffer decryptedString, java.lang.String charsetName)
          Verifies an OpenPGP signed only message and extracts the contents

 SignatureCheckResult verifyAndExtract(java.lang.String dataFileName, java.lang.String publicKeyFileName, java.lang.String outputFileName)
          Verifies a file for being correctly OpenPGP signed and extracts the data

Example:
 SignatureCheckResult verifyAndExtract(java.lang.String message, java.lang.String publicKeyFile, java.lang.StringBuffer decryptedString)
          Verifies an OpenPGP signed only message and extracts the contents

 SignatureCheckResult verifyAndExtract(java.lang.String message, java.lang.String publicKeyFile, java.lang.StringBuffer decryptedString, java.lang.String charsetName)
          Verifies an OpenPGP signed only message and extracts the contents

 boolean verifyFile(java.io.InputStream dataFileStream, java.io.InputStream publicKeyStream)
          Deprecated. Use verifyStream(InputStream, InputStream)
 boolean verifyFile(java.lang.String dataFileName, KeyStore keyStore, java.lang.String outputFileName)
          Deprecated. Due to misleading return value. Please use {@link #verifyAndExtract(String, KeyStore, String) instead
 boolean verifyFile(java.lang.String dataFileName, java.lang.String publicKeyFileName)
          Deprecated. Due to misleading return value. Please use verifyWithoutExtracting(String, String) instead
 boolean verifyFile(java.lang.String dataFileName, java.lang.String publicKeyFileName, java.lang.String outputFileName)
          Deprecated. Due to misleading return value. Please use {@link #verifyAndExtract(String, String, String) instead
 boolean verifyStream(java.io.InputStream dataFileStream, java.io.InputStream publicKeyStream)
          Deprecated. Due to misleading return value. Please use verifyWithoutExtracting(InputStream, InputStream) instead
 boolean verifyStream(java.io.InputStream dataFileStream, java.io.InputStream publicKeyStream, java.io.OutputStream outputFileStream)
          Deprecated. Due to misleading return value. Please use verifyAndExtract(InputStream, InputStream, OutputStream) instead
 boolean verifyStream(java.io.InputStream dataFileStream, KeyStore keyStore, java.io.OutputStream outputFileStream)
          Deprecated. Due to misleading return value. Please use verifyAndExtract(InputStream, KeyStore, OutputStream) instead
 boolean verifyString(java.lang.String message, java.lang.String publicKeyFileName, java.lang.StringBuffer decryptedString)
          Deprecated. Due to misleading return value. Please use verifyAndExtract(String, String, StringBuffer) instead
 boolean verifyString(java.lang.String message, java.lang.String publicKeyFileName, java.lang.StringBuffer decryptedString, java.lang.String charsetName)
          Deprecated. Due to misleading return value. Please use verifyAndExtract(String, String, StringBuffer, String) instead
 SignatureCheckResult verifyWithoutExtracting(java.io.File dataFile, java.io.File publicKeyFile)
          Verifies a file for being correctly OpenPGP signed without extracting its data

Example:
 SignatureCheckResult verifyWithoutExtracting(java.io.File dataFile, java.io.File privateKeyFile, java.lang.String privateKeyPassword, java.io.File publicKeyFile)
          Verifies the signature of an OpenPGP signed and encrypted file, without extracting its data

Example:
 SignatureCheckResult verifyWithoutExtracting(java.io.File dataFile, KeyStore keyStore)
          Verifies a file for being correctly OpenPGP signed without extracting its data

Example:
 SignatureCheckResult verifyWithoutExtracting(java.io.File dataFile, KeyStore keyStore, java.lang.String privateKeyPassword)
          Verifies the signature of an OpenPGP signed and encrypted file, without extracting its data

Example:
 SignatureCheckResult verifyWithoutExtracting(java.io.InputStream dataFileStream, java.io.InputStream publicKeyStream)
          Verifies an incoming stream as being correctly OpenPGP signed without extracting its data

Example:
 SignatureCheckResult verifyWithoutExtracting(java.io.InputStream dataFileStream, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword, java.io.InputStream publicKeyStream)
          Verifies the signature of an OpenPGP signed and encrypted file, without extracting its data

Example:
 SignatureCheckResult verifyWithoutExtracting(java.io.InputStream dataStream, KeyStore keyStore)
          Verifies an incoming stream as being correctly OpenPGP signed without extracting its data

Example:
 SignatureCheckResult verifyWithoutExtracting(java.io.InputStream dataStream, KeyStore keyStore, java.lang.String privateKeyPassword)
          Verifies the signature of an OpenPGP signed and encrypted file, without extracting its data

Example:
 SignatureCheckResult verifyWithoutExtracting(java.lang.String message, KeyStore keyStore)
          Verifies an OpenPGP signed only message and extracts the contents

 SignatureCheckResult verifyWithoutExtracting(java.lang.String message, KeyStore keyStore, java.lang.String privateKeyPassword)
          Verifies an OpenPGP signed only message and extracts the contents

 SignatureCheckResult verifyWithoutExtracting(java.lang.String message, java.lang.String publicKeyFile)
          Verifies the signature of an OpenPGP signed only message without extracting its data

 SignatureCheckResult verifyWithoutExtracting(java.lang.String message, java.lang.String privateKeyFile, java.lang.String privateKeyPassword, java.lang.String publicKeyFile)
          Verifies the signature of an OpenPGP signed only message without extracting its data

 
Methods inherited from class com.didisoft.pgp.bc.BaseLib
cleanGnuPGBackupKeys, extractPrivateKey, extractPrivateKey, isForVerification, isHexId, replaceAll
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PGPLib

public PGPLib()
The default constructor of the library.

Method Detail

getContentType

public char getContentType()
Returns the content data type for archives created afterwards

Since:
2.6.1
See Also:
ContentDataType

setContentType

public void setContentType(char type)
Sets the content data type for archives created afterwards

Since:
2.6.1
See Also:
ContentDataType

getDebugLevel

public java.util.logging.Level getDebugLevel()
Returns the current debug level. Default is Level.FINE

Since:
2.6.5.3

setDebuglevel

public void setDebuglevel(java.util.logging.Level level)
Sets the current debug information log level

Since:
2.6.5.3

isUseExpiredKeys

public boolean isUseExpiredKeys()
Returns should expired keys still be used
Default is false

Since:
2.5.7

setUseExpiredKeys

public void setUseExpiredKeys(boolean value)
Sets should expired keys still be used

Since:
2.5.7

isUseRevokedKeys

public boolean isUseRevokedKeys()
Returns should revoked keys still be used
Default is false

Since:
2.5.7

setUseRevokedKeys

public void setUseRevokedKeys(boolean value)
Sets should revoked keys still be used

Since:
2.5.7

setHash

public void setHash(java.lang.String hash)
Sets the preferred hashing algorithm used by all methods that produce OpenPGP signature (all Sign and SigneAndEncrypt methods)

See Also:
HashAlgorithm

getCypher

public java.lang.String getCypher()
Returns the preferred symmetric key algorithm used by all methods that produce OpenPGP messages (e.g Encrypt, Sign, etc.)
Default is CAST5

See Also:
CypherAlgorithm

getAsciiCommentHeader

public java.lang.String getAsciiCommentHeader()
Returns the Comment text that is printed in ASCII armored output

Returns:
string of the form "Comment: XXX" or empty string if no comment is set

getAsciiVersionHeader

public java.lang.String getAsciiVersionHeader()
Returns the Version comment text that is printed in ASCII armored output

Returns:
string of the form "Version: XXX"

setAsciiVersionHeader

public void setAsciiVersionHeader(java.lang.String creator)
Sets the Version comment text that is printed in ASCII armored output

Example usage:
 PGPLib pgp = new PGPLib();
 pgp.setAsciiVersionHeader("My Application 1.1"); 
 // Now in ASCII armored output will be printed "Version: My Application 1.1"  
 

Parameters:
creator - Program name and version that will be written in ASCII armored output Version: field

setCypher

public void setCypher(java.lang.String cypher)
Sets the preferred symmetric key algorithm used by all methods that produce OpenPGP messages (e.g Encrypt, Sign, etc.)

Throws:
java.security.InvalidParameterException - if the specified algorithm is not suppored
See Also:
CypherAlgorithm

getCompression

public java.lang.String getCompression()
Returns the preferred compression algorithm used by all methods that produce OpenPGP messages (e.g Encrypt, Sign, etc.)
Default is ZIP

See Also:
CompressionAlgorithm

setCompression

public void setCompression(java.lang.String compression)
Sets the preferred compression algorithm used by all methods that produce OpenPGP messages (e.g Encrypt, Sign, etc.)

Throws:
java.security.InvalidParameterException - if the specified algorithm is not suppored
See Also:
CompressionAlgorithm

detachedVerifyStream

public boolean detachedVerifyStream(java.io.InputStream dataFileStream,
                                    java.io.InputStream detachedSignatureStream,
                                    java.io.InputStream publicKeyStream)
                             throws PGPException,
                                    java.io.IOException
Verifies that an OpenPGP detached signature is signed from a trusted sender.

Parameters:
dataFileStream - Input stream from the File to be verified
detachedSignatureStream - Detached signature as stream
publicKeyStream - Input stream from the Public key
Returns:
true if signed correctly, false if not signed with this public key
Throws:
java.io.IOException - I/O error
PGPException - OpenPGP encryption error
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message

detachedVerifyStream

public boolean detachedVerifyStream(java.io.InputStream dataFileStream,
                                    java.io.InputStream detachedSignatureStream,
                                    KeyStore keyStore)
                             throws PGPException,
                                    java.io.IOException
Verifies that an OpenPGP detached signature is signed from a trusted sender.

Parameters:
dataFileStream - Input stream from the File to be verified
detachedSignatureStream - Detached signature as stream
keyStore - KeyStore containing a public key that can verify the signature
Returns:
true if signed correctly, false if not signed with this public key
Throws:
java.io.IOException - I/O error
PGPException - OpenPGP encryption error
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message

detachedVerify

public SignatureCheckResult detachedVerify(java.lang.String message,
                                           java.lang.String detachedSignature,
                                           java.lang.String publicKeyFile)
                                    throws PGPException,
                                           java.io.IOException
Verifies that an OpenPGP detached signature is signed from a trusted sender.

Example:
 import java.io.*;
 import com.didisoft.pgp.PGPLib;
  
 public class DetachedVerify {
  public static void main(String[] args) throws Exception {
   PGPLib pgp = new PGPLib();
  
   String message = "Hello world"; // this could also be a file path location
   String senderPublicKey = "examples/DataFiles/sender_public_key.asc";
   String detachedSignature = "examples/DataFiles/INPUT.txt.sig"; // this could also be a signature in ASCII armored format
  
   SignatureCheckResult signatureCheck = pgp.detachedVerify(message, 
                                                detachedSignature,
                                                senderPublicKey);
   if (signatureCheck == SignatureCheckResult.SignatureVerified) {
         System.out.println("The signature is valid.");
   } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
         System.out.println("Message corrupted or signature forged");
   } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
         System.out.println("Signature not matching provided public key /it is from another sender/");
   } else {
          System.out.println("No signature found in message");
   }
 
   dataStream.close();
   senderPublicKeyStream.close();
   detachedSignatureStream.close();
  }
 }
 

Parameters:
message - File name or String message with the data for which the detached signature applies
detachedSignature - File name or String text of the Detached signature
publicKeyFile - OpenPGP public key file name or as ASCII armored String, used for signature verification
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - I/O error
PGPException - OpenPGP encryption error
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
Since:
3.1
See Also:
detachedSignFile(String, String, String, String, boolean), #detachedSignString(String, String, String)

detachedVerify

public SignatureCheckResult detachedVerify(java.lang.String message,
                                           java.lang.String detachedSignature,
                                           KeyStore keyStore)
                                    throws PGPException,
                                           java.io.IOException
Verifies that an OpenPGP detached signature is signed from a trusted sender.

Example:
 import java.io.*;
 import com.didisoft.pgp.PGPLib;
  
 public class DetachedVerify {
  public static void main(String[] args) throws Exception {
   PGPLib pgp = new PGPLib();
  
   String message = "Hello world"; // this could also be a file path location
   KeyStore keyStore = new KeyStore("examples/DataFiles/mykeys.keysore", "key store password");
   String detachedSignature = "examples/DataFiles/INPUT.txt.sig"; // this could also be a signature in ASCII armored format
  
   SignatureCheckResult signatureCheck = pgp.detachedVerify(message, 
                                                detachedSignature,
                                                senderPublicKey);
   if (signatureCheck == SignatureCheckResult.SignatureVerified) {
         System.out.println("The signature is valid.");
   } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
         System.out.println("Message corrupted or signature forged");
   } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
         System.out.println("No matching public key found in the KeyStore");
   } else {
          System.out.println("No signature found in message");
   }
 
   dataStream.close();
   senderPublicKeyStream.close();
   detachedSignatureStream.close();
  }
 }
 

Parameters:
message - File name or String message with the data for which the detached signature applies
detachedSignature - File name or String text of the Detached signature
keyStore - KeyStore object containing OpenPGP keys that will be used for signature verification
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - I/O error
PGPException - OpenPGP encryption error
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
Since:
3.1
See Also:
detachedSignFile(String, KeyStore, long, String, String, boolean), detachedSignFile(String, KeyStore, String, String, String, boolean), #detachedSignString(String, String, String)

detachedVerify

public SignatureCheckResult detachedVerify(java.io.InputStream dataFileStream,
                                           java.io.InputStream detachedSignatureStream,
                                           java.io.InputStream publicKeyStream)
                                    throws PGPException,
                                           java.io.IOException
Verifies that an OpenPGP detached signature is signed from a trusted sender.

Example:
 import java.io.*;
 import com.didisoft.pgp.PGPLib;
  
 public class DetachedVerifyStream {
  public static void main(String[] args) throws Exception {
   PGPLib pgp = new PGPLib();
  
   InputStream dataStream = new FileInputStream("examples/DataFiles/INPUT.txt");
   InputStream senderPublicKeyStream = new FileInputStream("examples/DataFiles/sender_public_key.asc");
   InputStream detachedSignatureStream = new FileInputStream("examples/DataFiles/INPUT.txt.sig");
  
   SignatureCheckResult signatureCheck = pgp.detachedVerify(dataStream, 
                                                detachedSignatureStream,
                                                senderPublicKeyStream);
   if (signatureCheck == SignatureCheckResult.SignatureVerified) {
         System.out.println("The signature is valid.");
   } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
         System.out.println("Message corrupted or signature forged");
   } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
         System.out.println("Signature not matching provided public key /it is from another sender/");
   } else {
          System.out.println("No signature found in message");
   }
 
   dataStream.close();
   senderPublicKeyStream.close();
   detachedSignatureStream.close();
  }
 }
 

Parameters:
dataFileStream - Input stream from the File to be verified
detachedSignatureStream - Detached signature as stream
publicKeyStream - Input stream from the Public key
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - I/O error
PGPException - OpenPGP encryption error
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
Since:
3.1
See Also:
detachedSignStream(InputStream, InputStream, String, OutputStream, boolean)

detachedVerify

public SignatureCheckResult detachedVerify(java.io.InputStream dataFileStream,
                                           java.io.InputStream detachedSignatureStream,
                                           KeyStore keyStore)
                                    throws PGPException,
                                           java.io.IOException
Verifies that an OpenPGP detached signature is signed from a trusted sender.

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
  
 public class DetachedVerifyStream {
  public static void main(String[] args) throws Exception {
   PGPLib pgp = new PGPLib();
  
   InputStream dataStream = new FileInputStream("examples/DataFiles/INPUT.txt");
   KeyStore keyStore = new KeyStore("examples/DataFiles/mykeys.keysore", "key store password");
   InputStream detachedSignatureStream = new FileInputStream("examples/DataFiles/INPUT.txt.sig");
  
   SignatureCheckResult signatureCheck = pgp.detachedVerify(dataStream, 
                                                detachedSignatureStream,
                                                keyStore);
   if (signatureCheck == SignatureCheckResult.SignatureVerified) {
         System.out.println("The signature is valid.");
   } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
         System.out.println("Message corrupted or signature forged");
   } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
         System.out.println("No matching public key found in the KeyStore");
   } else {
          System.out.println("No signature found in message");
   }
 
   dataStream.close();
   senderPublicKeyStream.close();
   detachedSignatureStream.close();
  }
 }
 

Parameters:
dataFileStream - Input stream from the File to be verified
detachedSignatureStream - Detached signature as stream
keyStore - KeyStore containing a public key that can verify the signature
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - I/O error
PGPException - general OpenPGP error
NonPGPDataException - if the input data is not a valid OpenPGP message
Since:
3.1
See Also:
detachedSignStream(InputStream, KeyStore, long, String, OutputStream, boolean)

detachedSignFile

public void detachedSignFile(java.lang.String dataFileName,
                             java.lang.String privateKeyFileName,
                             java.lang.String privateKeyPassword,
                             java.lang.String detachedSignatureFileName,
                             boolean asciiArmor)
                      throws PGPException,
                             java.io.IOException
Creates an OpenPGP detached signature for a given file.

Hash algorithm used is the one specified through setHash(String)

Example:
 import java.io;
 import com.didisoft.pgp.*;
 
 public class DetachedSignDemo
 {
    public void Demo() throws Exception
    {
        // initialize the library
        PGPLib pgp = new PGPLib();
        
        // should output be binary or ASCII armored 
        boolean asciiArmor = true;
        
        String dataFileName = "C:\\INPUT.txt"; 
        String privateKeyFileName = "C:\\private_key.asc";
        
        String detachedSignatureFile = "C:\\INPUT.txt.sig"; 
        
        pgp.detachedSignFile(dataFileName, 
                               privateKeyFileName, 
                               "private key password",
                               detachedSignatureFile, 
                               asciiArmor);              
    }
 }
 

Parameters:
dataFileName - File name for which an OpenPGP detached signature will be created (absolute or relative path)
privateKeyStream - Private key file (absolute or relative path) or the key as ASCII armored string
privateKeyPassword - Private key password
outStream - File name where the detached signature will be stored (absolute or relative path)
asciiArmor - if true, the output file is in ASCII armored format, when false the output will be in binary format
Throws:
PGPException - if an OpenPGP related error has occurred
java.io.IOException - if an I/O error has occurred
NoPrivateKeyFoundException - If privateKeyStream does not contain an OpenPGP private key. Extends PGPException
WrongPasswordException - If the specified password for the private key is incorrect

detachedSignFile

public void detachedSignFile(java.lang.String dataFileName,
                             KeyStore keyStore,
                             long privateKeyId,
                             java.lang.String privateKeyPassword,
                             java.lang.String detachedSignatureFileName,
                             boolean asciiArmor)
                      throws PGPException,
                             java.io.IOException
Creates an OpenPGP detached signature for a given file.

Hash algorithm used is the one specified through setHash(String)

Example:
 import java.io;
 import com.didisoft.pgp.*;
 
 public class DetachedSignDemo
 {
    public void Demo() throws Exception
    {
         // create an instance of the KeyStore
         KeyStore keyStore = new KeyStore("pgp.keystore", "changeit");
         
         // initialize the library 
         PGPLib pgp = new PGPLib();
 
         // The signing key is usually our private key
         long signKeyId = keyStore.getKeyIdForKeyIdHex("79AEAE03");
    
        // should output be binary or ASCII armored 
        boolean asciiArmor = true;
        
        String dataFileName = "C:\\INPUT.txt"; 
        String detachedSignatureFile = "C:\\INPUT.txt.sig"; 
        
        pgp.detachedSignFile(dataFileName, 
                               keyStore,
                               signKeyId, 
                               "private key password",
                               detachedSignatureFile, 
                               asciiArmor);              
    }
 }
 

Parameters:
dataFileName - File name for which an OpenPGP detached signature will be created (absolute or relative path)
keyStore - Key store containing the private key to be used for signing
privateKeyId - signing key Id
privateKeyPassword - Private key password
outStream - File name where the detached signature will be stored (absolute or relative path)
asciiArmor - if true, the output file is in ASCII armored format, when false the output will be in binary format
Throws:
PGPException - if an OpenPGP related error has occurred
java.io.IOException - if an I/O error has occurred
NoPrivateKeyFoundException - If privateKeyStream does not contain an OpenPGP private key. Extends PGPException
WrongPasswordException - If the specified password for the private key is incorrect
Since:
3.1.1.4

detachedSignFile

public void detachedSignFile(java.lang.String dataFileName,
                             KeyStore keyStore,
                             java.lang.String privateKeyUserId,
                             java.lang.String privateKeyPassword,
                             java.lang.String detachedSignatureFileName,
                             boolean asciiArmor)
                      throws PGPException,
                             java.io.IOException
Creates an OpenPGP detached signature for a given file.

Hash algorithm used is the one specified through setHash(String)

Example:
 import java.io;
 import com.didisoft.pgp.*;
 
 public class DetachedSignDemo
 {
    public void Demo() throws Exception
    {
         // create an instance of the KeyStore
         KeyStore keyStore = new KeyStore("pgp.keystore", "changeit");
         
         // initialize the library 
         PGPLib pgp = new PGPLib();
 
         // The signing key is usually our private key
         long signKeyId = keyStore.getKeyIdForKeyIdHex("79AEAE03");
    
        // should output be binary or ASCII armored 
        boolean asciiArmor = true;
        
        String dataFileName = "C:\\INPUT.txt"; 
        String detachedSignatureFile = "C:\\INPUT.txt.sig"; 
        
        pgp.detachedSignFile(dataFileName, 
                               keyStore,
                               signKeyId, 
                               "private key password",
                               detachedSignatureFile, 
                               asciiArmor);              
    }
 }
 

Parameters:
dataFileName - File name for which an OpenPGP detached signature will be created (absolute or relative path)
keyStore - Key store containing the private key to be used for signing
privateKeyUserId - signing key User Id or hexadecimal Key ID
privateKeyPassword - Private key password
outStream - File name where the detached signature will be stored (absolute or relative path)
asciiArmor - if true, the output file is in ASCII armored format, when false the output will be in binary format
Throws:
PGPException - if an OpenPGP related error has occurred
java.io.IOException - if an I/O error has occurred
NoPrivateKeyFoundException - If privateKeyStream does not contain an OpenPGP private key. Extends PGPException
WrongPasswordException - If the specified password for the private key is incorrect
Since:
3.1.1.4

detachedSignStream

public void detachedSignStream(java.io.InputStream dataStream,
                               java.io.InputStream privateKeyStream,
                               java.lang.String privateKeyPassword,
                               java.io.OutputStream outStream,
                               boolean asciiArmor)
                        throws PGPException,
                               java.io.IOException
Creates an OpenPGP detached signature for a given data stream contents.

Hash algorithm used is the one specified through setHash(String)
Note: The caller has the responsibility to close the output stream.

Example:
 import java.io;
 import com.didisoft.pgp.*;
 
 public class DetachedSignDemo
 {
    public void Demo() throws Exception
    {
        // initialize the library
        PGPLib pgp = new PGPLib();
        
        // should output be binary or ASCII armored 
        boolean asciiArmor = true;
        
        InputStream dataFileStream = FileInputStream("C:\\INPUT.txt"); 
        InputStream privateKeyStream = new FileInputStream("C:\\private_key.asc");
        
        OutputStream outputSigned = null;
        try 
        {
         outputSigned = new FileOutputStream("C:\\INPUT.txt.sig"); 
        
         pgp.detachedSignStream(dataFileStream, 
                               privateKeyStream, 
                               "private key password",
                               outputSigned, 
                               asciiArmor);              
        } finally {
         // we have the obligation to close the output stream
         outputSigned.close();
        }
    }
 }
 

Parameters:
dataStream - Data stream for which a detached signature is to be created
privateKeyStream - Private key as stream, used for signing
privateKeyPassword - Private key password
outStream - Output stream where the detached signature will be stored
asciiArmor - if true, output file is in ASCII armored format
Throws:
PGPException - if an OpenPGP related error has occurred
java.io.IOException - if an I/O error has occurred
NoPrivateKeyFoundException - If privateKeyStream does not contain an OpenPGP private key. Extends PGPException
WrongPasswordException - If the specified password for the private key is incorrect

detachedSignStream

public void detachedSignStream(java.io.InputStream dataStream,
                               KeyStore keyStore,
                               long keyId,
                               java.lang.String privateKeyPassword,
                               java.io.OutputStream outStream,
                               boolean asciiArmor)
                        throws PGPException,
                               java.io.IOException
Creates an OpenPGP detached signature for a given data stream contents.

Hash algorithm used is the one specified through setHash(String)
Note: The caller has the responsibility to close the output stream.

Parameters:
dataStream - Data stream for which a detached signature is to be created
keyStore - KeyStore instance containing the private key used for signing
keyId - Key Id of the private key that will be used for signing
privateKeyPassword - Private key password
outStream - Output stream where the detached signature will be stored
asciiArmor - if true, output file is in ASCII armored format
Throws:
PGPException - if an OpenPGP related error has occurred
java.io.IOException - if an I/O error has occurred
NoPrivateKeyFoundException - If privateKeyStream does not contain an OpenPGP private key. Extends PGPException
WrongPasswordException - If the specified password for the private key is incorrect

detachedSignStream

public void detachedSignStream(java.io.InputStream dataStream,
                               KeyStore keyStore,
                               java.lang.String userId,
                               java.lang.String privateKeyPassword,
                               java.io.OutputStream outStream,
                               boolean asciiArmor)
                        throws PGPException,
                               NoPrivateKeyFoundException,
                               java.io.IOException
Creates an OpenPGP detached signature for a given data stream contents.

Hash algorithm used is the one specified through setHash(String)
Note: The caller has the responsibility to close the output stream.

Parameters:
dataStream - Data stream for which a detached signature is to be created
keyStore - KeyStore instance containing the private key used for signing
userId - User Id or hexadecimal Key ID of the private key that will be used for signing.
privateKeyPassword - Private key password
outStream - Output stream where the detached signature will be stored
asciiArmor - if true, output file is in ASCII armored format
Throws:
PGPException - if an OpenPGP related error has occurred
java.io.IOException - if an I/O error has occurred
NoPrivateKeyFoundException - If privateKeyStream does not contain an OpenPGP private key. Extends PGPException
WrongPasswordException - If the specified password for the private key is incorrect

clearSignFile

public void clearSignFile(java.lang.String inputFileName,
                          java.lang.String privateKeyFileName,
                          java.lang.String privateKeyPassword,
                          java.lang.String hashingAlgorithm,
                          java.lang.String outputFileName)
                   throws PGPException,
                          java.io.IOException,
                          WrongPasswordException
OpenPGP clear signs a file.

GPG equivalent command: gpg --clearsign inputFileName --output outputFileName

Example:

 import com.didisoft.pgp.*;
 
 public class ClearSignDemo {
     public static void main(String[] args) throws Exception{
         // initialize the library 
         PGPLib pgp = new PGPLib();
         
         // clear sign
         pgp.clearSignFile("INPUT.txt", 
                           "private.key", 
                           "private key password", 
                           HashAlgorithm.SHA256, 
                           "OUTPUT.sig.txt");
     }
 }
 

Parameters:
inputFileName - File name to be clear signed (absolute or relative path)
privateKeyFileName - Private Key file (absolute or relative path)
privateKeyPassword - Private key password
hashingAlgorithm - Hashing algorithm, one of: SHA256, SHA384, SHA512, SHA224, SHA1, MD5, RIPEMD160, MD2
outputFileName - Output file name (absolute or relative path)
Throws:
java.io.IOException - If a file/stream operation throws an exception
lw.bouncycastle.openpgp.PGPException - OpenPGP error
NoPrivateKeyFoundException - If privateKeyFileName does not contain an OpenPGP private key. Extends PGPException
WrongPasswordException - If the private key password is incorrect
java.security.InvalidParameterException - If the hashingAlgorithm parameter is not among the supported values
KeyIsExpiredException - If the key is expired. Extends PGPException
KeyIsRevokedException - If the key is revoked. Extends PGPException
PGPException
See Also:
HashAlgorithm

clearSignFileVersion3

public void clearSignFileVersion3(java.lang.String inputFileName,
                                  java.lang.String privateKeyFileName,
                                  java.lang.String privateKeyPassword,
                                  java.lang.String hashingAlgorithm,
                                  java.lang.String outputFileName)
                           throws PGPException,
                                  java.io.IOException,
                                  WrongPasswordException
OpenPGP clear signs a file, using OpenPGP version 3 signature format (old format used by PGP 2.x)

Use when needed compatibility with PGP 2.x

GPG equivalent command: gpg --force-v3-sigs --clearsign inputFileName

Example:

 import com.didisoft.pgp.*;
 
 public class ClearSignVersion3Demo {
     public static void main(String[] args) throws Exception{
         // initialize the library 
         PGPLib pgp = new PGPLib();
         
         // clear sign with version 3 signature
         pgp.clearSignFileVersion3("INPUT.txt", 
                           "private.key", 
                           "private key password", 
                           HashAlgorithm.SHA256, 
                           "OUTPUT.sig.txt");
     }
 }
 

Parameters:
inputFileName - File name to be clear signed (absolute or relative path)
privateKeyFileName - Private Key file (absolute or relative path)
privateKeyPassword - Private key password
hashingAlgorithm - Hashing algorithm, one of: SHA256, SHA384, SHA512, SHA224, SHA1, MD5, RIPEMD160, MD2
outputFileName - Output file name (absolute or relative path)
Throws:
java.io.IOException - If a file/stream operation throws an exception
PGPException - OpenPGP encryption error
NoPrivateKeyFoundException - If privateKeyFileName does not contain an OpenPGP private key. Extends PGPException
WrongPasswordException - If the private key password is incorrect
java.security.InvalidParameterException - If the hashingAlgorithm parameter is other than the supported values
KeyIsExpiredException - If the key is expired. Extends PGPException
KeyIsRevokedException - If the key is revoked. Extends PGPException
See Also:
HashAlgorithm, clearSignString(String, String, String, String)

clearSignString

public java.lang.String clearSignString(java.lang.String stringToSign,
                                        java.lang.String privateKeyFileName,
                                        java.lang.String privateKeyPassword,
                                        java.lang.String hashingAlgorithm)
                                 throws PGPException,
                                        java.io.IOException,
                                        WrongPasswordException
OpenPGP clear signs a String

Example usage:

 import com.didisoft.pgp.*;
 
 public class ClearSignDemo {
     public static void main(String[] args) throws Exception{
         // initialize the library 
         PGPLib pgp = new PGPLib();
         
         String message = "The quick brown fox jumps.";
          
         // clear sign
         String clearSignedMessage = 
           pgp.clearSignString(message, 
                               "private.key", 
                               "private key password", 
                               HashAlgorithm.SHA256);
     }
 }
 

Parameters:
stringToSign - String message to be signed
privateKeyFileName - Private Key file (absolute or relative path)
privateKeyPassword - Private key password
hashingAlgorithm - Hashing algorithm, one of: SHA256, SHA384, SHA512, SHA224, SHA1, MD5, RIPEMD160, MD2
Returns:
The clear signed message.
Throws:
java.io.IOException - If a file/stream operation throws an exception
lw.bouncycastle.openpgp.PGPException - OpenPGP encryption error
NoPrivateKeyFoundException - If privateKeyFileName does not contain an OpenPGP private key. Extends PGPException
WrongPasswordException - If the private key password is incorrect
java.security.InvalidParameterException - If the hashingAlgorithm parameter is other than the supported values. Runtime exception
KeyIsExpiredException - If the key is expired. Extends PGPException
KeyIsRevokedException - If the key is revoked. Extends PGPException
PGPException
See Also:
clearSignStringVersion3(String, String, String, String), HashAlgorithm

clearSignStringVersion3

public java.lang.String clearSignStringVersion3(java.lang.String stringToSign,
                                                java.lang.String privateKeyFileName,
                                                java.lang.String privateKeyPassword,
                                                java.lang.String hashingAlgorithm)
                                         throws PGPException,
                                                java.io.IOException,
                                                WrongPasswordException
OpenPGP clear signs a String, using OpenPGP version 3 signature format (the old format)

Use when needed compatibility with PGP 2.x and PGP 5.x systems.

Parameters:
stringToSign - String message to be signed
privateKeyFileName - Private Key file (absolute or relative path)
privateKeyPassword - Private key password
hashingAlgorithm - Hashing algorithm, one of: SHA256, SHA384, SHA512, SHA224, SHA1, MD5, RIPEMD160, MD2.
@see HashAlgorithm
Returns:
The clear signed message.
Throws:
java.io.IOException - If a file/stream operation throws an exception
PGPException - OpenPGP encryption error
NoPrivateKeyFoundException - If privateKeyFileName does not contain an OpenPGP private key. Extends PGPException
WrongPasswordException - If the private key password is incorrect
java.security.InvalidParameterException - If the hashingAlgorithm parameter is other than the supported values. Runtime exception
KeyIsExpiredException - If the key is expired. Extends PGPException
KeyIsRevokedException - If the key is revoked. Extends PGPException
See Also:
clearSignFileVersion3(String, String, String, String, String), verifyFile(String, String, String)

signFile

public void signFile(KeyStore keyStore,
                     java.lang.String dataFileName,
                     java.lang.String keyIdHex,
                     java.lang.String privateKeyPassword,
                     java.lang.String outputFileName)
              throws PGPException,
                     WrongPasswordException,
                     java.io.IOException
OpenPGP signs given file using specified Private Key, using OpenPGP Key Store.

Optional settings:
Compression algorithm used is the one specified with setCompression(String)
Hashing algorithm used is the one specified with setHash(String)

Parameters:
dataFileName - File name to be encrypted (absolute or relative path)
keyStore - Key store instance containing the private key to be used for signing
keyIdHex - key ID of the Public Key in Hex format
privateKeyPassword - Private key password
outputFileName - File name of the Output encrypted file (absolute or relative path)
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP encryption error
NoPrivateKeyFoundException - if the private key source does not contain a private key or is corrupted
WrongPasswordException - If the private key password is incorrect
KeyIsExpiredException - If the key is expired. Extends PGPException
KeyIsRevokedException - If the key is revoked. Extends PGPException
See Also:
verifyFile(String, String, String)

signFile

public void signFile(KeyStore keyStore,
                     java.lang.String dataFileName,
                     long privateKeyId,
                     java.lang.String privateKeyPassword,
                     java.lang.String outputFileName)
              throws PGPException,
                     WrongPasswordException,
                     java.io.IOException
OpenPGP signs given file using specified Private Key, using OpenPGP Key Store.

Optional settings:
Compression algorithm used is the one specified with setCompression(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import com.didisoft.pgp.KeyStore;
 import com.didisoft.pgp.PGPLib;
 
 public class KeyStoreSignFileDemo {
     public static void main(String[] args) throws Exception{        
         // create an instance of the KeyStore
         KeyStore keyStore = new KeyStore("pgp.keystore", "changeit");
         
         // initialize the library 
         PGPLib pgp = new PGPLib();
 
         // The signing key is usually our private key
         long signKeyId = keyStore.getKeyIdForUserId("demo@didisoft.com");
         String signKeyPassword = "changeit";        
         
         pgp.signFile("INPUT.txt",
                     keyStore, 
                     signKeyId, 
                     signKeyPassword, 
                     "signed.pgp");
     }
 }
 

Parameters:
dataFileName - File name to be encrypted (absolute or relative path)
keyStore - Key store containing the private key to be used for signing
privateKeyId - Key Id of the private key to be used for signing
privateKeyPassword - Private key password
outputFileName - File name of the output signed file (absolute or relative path)
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP encryption error
NoPrivateKeyFoundException - if the private key source does not contain a private key or is corrupted
WrongPasswordException - If the private key password is incorrect
KeyIsExpiredException - If the key is expired. Extends PGPException
KeyIsRevokedException - If the key is revoked. Extends PGPException
See Also:
verifyFile(String, KeyStore, String)

signFile

public void signFile(java.lang.String dataFileName,
                     KeyStore keyStore,
                     java.lang.String privateKeyUserId,
                     java.lang.String privateKeyPassword,
                     java.lang.String outputFileName,
                     boolean asciiArmor)
              throws PGPException,
                     WrongPasswordException,
                     java.io.IOException
OpenPGP signs a file, with private key stored in a KeyStore object.

Optional settings:
Compression algorithm used is the one specified with setCompression(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import com.didisoft.pgp.KeyStore;
 import com.didisoft.pgp.PGPLib;
 
 public class KeyStoreSignFileDemo {
     public static void main(String[] args) throws Exception{        
         // create an instance of the KeyStore
         KeyStore keyStore = new KeyStore("pgp.keystore", "changeit");
         
         // initialize the library 
         PGPLib pgp = new PGPLib();
 
         // The signing key is usually our private key
         long signKeyUserId = "demo@didisoft.com";
         String signKeyPassword = "changeit";        
         
         // specify should the output be ASCII or binary
         boolean asciiArmor = false;
         pgp.signFile("INPUT.txt",
                     keyStore, 
                     signKeyUserId, 
                     signKeyPassword, 
                     "signed.pgp",
                     asciiArmor);
     }
 }
 

Parameters:
dataFileName - File name to be encrypted (absolute or relative path)
keyStore - Key store containing the private key to be used for signing
privateKeyUserId - signing key User Id or hexadecimal Key ID
privateKeyPassword - signing key password
outputFileName - File name of the output signed file (absolute or relative path)
asciiArmor - boolean if true the output is ASCII armored, if false the output is in binary format
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP encryption error
NoPrivateKeyFoundException - if the private key source does not contain a private key or is corrupted
WrongPasswordException - If the private key password is incorrect
KeyIsExpiredException - If the key is expired. Extends PGPException
KeyIsRevokedException - If the key is revoked. Extends PGPException
Since:
2.5.2
See Also:
verifyFile(String, KeyStore, String)

signFile

public void signFile(java.lang.String dataFileName,
                     KeyStore keyStore,
                     long privateKeyId,
                     java.lang.String privateKeyPassword,
                     java.lang.String outputFileName,
                     boolean asciiArmor)
              throws PGPException,
                     WrongPasswordException,
                     java.io.IOException
OpenPGP signs a file, with private key stored in a KeyStore object.

Optional settings:
Compression algorithm used is the one specified with setCompression(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import com.didisoft.pgp.KeyStore;
 import com.didisoft.pgp.PGPLib;
 
 public class KeyStoreSignFileDemo {
     public static void main(String[] args) throws Exception{        
         // create an instance of the KeyStore
         KeyStore keyStore = new KeyStore("pgp.keystore", "changeit");
         
         // initialize the library 
         PGPLib pgp = new PGPLib();
 
         // The signing key is usually our private key
         long signKeyId = keyStore.getKeyIdForKeyIdHex("79AEAE03");
         String signKeyPassword = "changeit";        
         
         // specify should the output be ASCII or binary
         boolean asciiArmor = false;
         pgp.signFile("INPUT.txt",
                     keyStore, 
                     signKeyId, 
                     signKeyPassword, 
                     "signed.pgp",
                     asciiArmor);
     }
 }
 

Parameters:
dataFileName - File name to be encrypted (absolute or relative path)
keyStore - Key store containing the private key to be used for signing
privateKeyId - signing key Id
privateKeyPassword - signing key password
outputFileName - File name of the output signed file (absolute or relative path)
asciiArmor - boolean if true the output is ASCII armored, if false the output is in binary format
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP encryption error
NoPrivateKeyFoundException - if the private key source does not contain a private key or is corrupted
WrongPasswordException - If the private key password is incorrect
KeyIsExpiredException - If the key is expired. Extends PGPException
KeyIsRevokedException - If the key is revoked. Extends PGPException
Since:
2.5.7
See Also:
verifyFile(String, KeyStore, String)

signFile

public void signFile(java.lang.String inputFileName,
                     java.lang.String privateKeyFileName,
                     java.lang.String privateKeyPassword,
                     java.lang.String outputFileName,
                     boolean asciiArmor)
              throws java.io.IOException,
                     PGPException,
                     WrongPasswordException
OpenPGP signs a file.

Optional settings:
Compression algorithm used is the one specified with setCompression(String)
Hashing algorithm used is the one specified with setHash(String)

Example usage:

 import com.didisoft.pgp.*;
 
 public class SignFile {
     public static void main(String[] args) throws Exception{
         // initialize the library 
         PGPLib pgp = new PGPLib();
         
         // specify should the output be ASCII or binary
         boolean asciiArmor = false;
         pgp.signFile("INPUT.txt", 
                     "private_key.asc", 
                     "private key password", 
                     "signed.pgp", 
                     asciiArmor);
     }
 }
 

Parameters:
inputFileName - File Name to be OpenPGP Signed (absolute or relative path)
privateKeyFileName - Private Key file (absolute or relative path) or the key as ASCII armoured string
privateKeyPassword - Private key password
outputFileName - File name of the output OpenPGP signed file (absolute or relative path)
asciiArmor - boolean if true the output is ASCII armored, if false the output is in binary format
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP encryption error
NoPrivateKeyFoundException - if the private key source does not contain a private key or is corrupted
WrongPasswordException - If the private key password is incorrect
KeyIsExpiredException - If the key is expired. Extends PGPException
KeyIsRevokedException - If the key is revoked. Extends PGPException
See Also:
verifyFile(InputStream, InputStream)

signFile

public void signFile(java.lang.String fileName,
                     java.io.InputStream privateKeyStream,
                     java.lang.String privateKeyPassword,
                     java.io.OutputStream out,
                     boolean asciiArmor)
              throws java.io.IOException,
                     PGPException,
                     WrongPasswordException
OpenPGP signs a file.

Optional settings:
Compression algorithm used is the one specified with setCompression(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import java.io.*;
 import com.didisoft.pgp.PGPLib;
 
 public class SignFileDemo {
     public static void main(String[] args) throws Exception{        
         // initialize the library 
         PGPLib pgp = new PGPLib();
 
         // The signing key is usually our private key
         FileInputStream privateKeyStream = new FileInputStream("private_key.asc");
         String signKeyPassword = "changeit";        
         
         // specify should the output be ASCII or binary
         boolean asciiArmor = false;
         
         FileOutputStream outputSignedStream = new FileOutputStream("signed.pgp");
          
         pgp.signFile("c:\\Data\\INPUT.txt",
                     privateKeyStream, 
                     signKeyPassword, 
                     outputSignedFile,
                     asciiArmor);
     }
 }
 

Parameters:
fileName - File Name to be signed (absolute or relative path)
privateKeyStream - Private Key input stream
out - Output Stream signed
privateKeyPassword - Private key password
asciiArmor - if true output stream is in ASCII armored format, when false output stream is in binary format
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP encryption error
NoPrivateKeyFoundException - if the private key source does not contain a private key or is corrupted
WrongPasswordException - If the private key password is incorrect
KeyIsExpiredException - If the key is expired. Extends PGPException
KeyIsRevokedException - If the key is revoked. Extends PGPException
See Also:
verifyStream(InputStream, InputStream, OutputStream)

signStream

public void signStream(java.io.InputStream dataInputStream,
                       java.lang.String fileNameLabel,
                       java.io.InputStream privateKeyStream,
                       java.lang.String privateKeyPassword,
                       java.io.OutputStream signedStream,
                       boolean asciiArmor)
                throws java.io.IOException,
                       PGPException,
                       WrongPasswordException
OpenPGP signs a stream.

Optional settings:
Compression algorithm used is the one specified with setCompression(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import java.io.*;
 import com.didisoft.pgp.PGPLib;
 
 public class SignStreamDemo {
     public static void main(String[] args) throws Exception{        
         // initialize the library 
         PGPLib pgp = new PGPLib();
 
         // The signing key is usually our private key
         FileInputStream privateKeyStream = new FileInputStream("private_key.asc");
         String signKeyPassword = "changeit";        
         
         // specify should the output be ASCII or binary
         boolean asciiArmor = false;
         
         FileInputStream dataStream = new FileInputStream("c:\\Data\\INPUT.txt");
         FileOutputStream outputSignedStream = new FileOutputStream("signed.pgp");
          
         pgp.signStream(dataStream,
                     "INPUT.txt" 
                     privateKeyStream, 
                     signKeyPassword, 
                     outputSignedFile,
                     asciiArmor);
     }
 }
 

Parameters:
dataInputStream - InputStream containing data to be signed
fileNameLabel - File name string to be associated with the data stream in the produced OpenPGP archive.
privateKeyStream - Private key input stream
signedStream - Output stream signed
privateKeyPassword - Private key password
asciiArmor - if true output stream is in ASCII armored format, when false output stream is in binary format
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP encryption error
NoPrivateKeyFoundException - if the private key source does not contain a private key or is corrupted
WrongPasswordException - If the private key password is incorrect
KeyIsExpiredException - If the key is expired. Extends PGPException
KeyIsRevokedException - If the key is revoked. Extends PGPException
See Also:
verifyStream(InputStream, InputStream, OutputStream)

signStream

public void signStream(java.io.InputStream dataInputStream,
                       java.lang.String fileNameLabel,
                       KeyStore keyStore,
                       java.lang.String signingKeyUserId,
                       java.lang.String privateKeyPassword,
                       java.io.OutputStream signedStream,
                       boolean asciiArmor)
                throws java.io.IOException,
                       PGPException,
                       WrongPasswordException
OpenPGP signs stream with a private key stored in a KeyStore.

Optional settings:
Compression algorithm used is the one specified with setCompression(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class SignStreamDemo {
     public static void main(String[] args) throws Exception{        
         // create an instance of the KeyStore
         KeyStore keyStore = new KeyStore("pgp.keystore", "changeit");
         
         // initialize the library 
         PGPLib pgp = new PGPLib();
 
         // The signing key is usually our private key
         long signUserId = "demo@didisoft.com";
         String signKeyPassword = "changeit";        
         
         // specify should the output be ASCII or binary
         boolean asciiArmor = false;
         
         FileInputStream dataStream = new FileInputStream("c:\\Data\\INPUT.txt");
         FileOutputStream outputSignedStream = new FileOutputStream("signed.pgp");
          
         pgp.signStream(dataStream,
                     "INPUT.txt" 
                     keyStore, 
                     signUserId, 
                     signKeyPassword, 
                     outputSignedFile,
                     asciiArmor);
     }
 }
 

Parameters:
dataInputStream - InputStream containing data to be signed
fileNameLabel - File name string to be associated with the data stream in the produced OpenPGP archive.
keyStore - KeyStore containing the private key for signing
signingKeyUserId - User Id or hexadecimal Key ID of the signing private key
privateKeyPassword - Private key password
signedStream - Output stream signed
asciiArmor - if true output stream is in ASCII armored format, when false output stream is in binary format
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP encryption error
NoPrivateKeyFoundException - if the private key source does not contain a private key or is corrupted
WrongPasswordException - If the private key password is incorrect
KeyIsExpiredException - If the key is expired. Extends PGPException
KeyIsRevokedException - If the key is revoked. Extends PGPException
See Also:
verifyStream(InputStream, KeyStore, OutputStream)

signStream

public void signStream(java.io.InputStream dataInputStream,
                       java.lang.String fileNameLabel,
                       KeyStore keyStore,
                       long signingKeyId,
                       java.lang.String privateKeyPassword,
                       java.io.OutputStream signedStream,
                       boolean asciiArmor)
                throws java.io.IOException,
                       PGPException,
                       WrongPasswordException
OpenPGP signs stream with a private key stored in a KeyStore.

Optional settings:
Compression algorithm used is the one specified with setCompression(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class SignStreamDemo {
     public static void main(String[] args) throws Exception{        
         // create an instance of the KeyStore
         KeyStore keyStore = new KeyStore("pgp.keystore", "changeit");
         
         // initialize the library 
         PGPLib pgp = new PGPLib();
 
         // The signing key is usually our private key
         long signKeyId = keyStore.getKeyIdForUserId("demo@didisoft.com");
         String signKeyPassword = "changeit";        
         
         // specify should the output be ASCII or binary
         boolean asciiArmor = false;
         
         FileInputStream dataStream = new FileInputStream("c:\\Data\\INPUT.txt");
         FileOutputStream outputSignedStream = new FileOutputStream("signed.pgp");
          
         pgp.signStream(dataStream,
                     "INPUT.txt" 
                     keyStore, 
                     signKeyId, 
                     signKeyPassword, 
                     outputSignedFile,
                     asciiArmor);
     }
 }
 

Parameters:
dataInputStream - InputStream containing data to be signed
fileNameLabel - File name string to be associated with the data stream in the produced OpenPGP archive.
keyStore - KeyStore containing the private key for signing
signingKeyId - Key Id of the private key
privateKeyPassword - Private key password
signedStream - Output stream signed
asciiArmor - if true output stream is in ASCII armored format, when false output stream is in binary format
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP encryption error
NoPrivateKeyFoundException - if the private key source does not contain a private key or is corrupted
WrongPasswordException - If the private key password is incorrect
KeyIsExpiredException - If the key is expired. Extends PGPException
KeyIsRevokedException - If the key is revoked. Extends PGPException
See Also:
verifyStream(InputStream, KeyStore, OutputStream)

signFileVersion3

public void signFileVersion3(java.lang.String fileName,
                             java.lang.String privateKeyFileName,
                             java.lang.String privateKeyPassword,
                             java.lang.String outputFileName,
                             boolean asciiArmor)
                      throws java.io.IOException,
                             PGPException,
                             WrongPasswordException
Signs a file in OpenPGP version 3 format (compatible with PGP 2.x systems)

Optional settings:
Compression algorithm used is the one specified with setCompression(String)
Hashing algorithm used is the one specified with setHash(String)

Example usage:

 import com.didisoft.pgp.*;
 
 public class SignFileV3Demo {
     public static void main(String[] args) throws Exception{
         // initialize the library 
         PGPLib pgp = new PGPLib();
         
         // specify should the output be ASCII or binary
         boolean asciiArmor = false;
         
         signFileVersion3("INPUT.txt", 
                     "private_key.asc", 
                     "private key password", 
                     "signed.pgp", 
                     asciiArmor);
     }
 }
 

Parameters:
fileName - File Name to be signed (absolute or relative path)
privateKeyFileName - Private Key file (absolute or relative path) or the key as ASCII armoured string
privateKeyPassword - Private Key password
outputFileName - File name of the output OpenPGP signed file (absolute or relative path)
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP encryption error
NoPrivateKeyFoundException - if the private key source does not contain a private key or is corrupted
WrongPasswordException - If the private key password is incorrect
KeyIsExpiredException - If the key is expired. Extends PGPException
KeyIsRevokedException - If the key is revoked. Extends PGPException
See Also:
verifyFile(String, String, String)

signStreamVersion3

public void signStreamVersion3(java.io.InputStream dataFileStream,
                               java.lang.String internalFileName,
                               java.io.InputStream privateKeyStream,
                               java.lang.String privateKeyPassword,
                               java.io.OutputStream out,
                               boolean asciiArmor)
                        throws java.io.IOException,
                               PGPException,
                               WrongPasswordException
Signs a stream using OpenPGP version 3 signatures format (compatible with PGP 2.x systems)

Optional settings:
Compression algorithm used is the one specified with setCompression(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import java.io.*;
 import com.didisoft.pgp.PGPLib;
 
 public class SignStreamDemo {
     public static void main(String[] args) throws Exception{        
         // initialize the library 
         PGPLib pgp = new PGPLib();
 
         // The signing key is usually our private key
         FileInputStream privateKeyStream = new FileInputStream("private_key.asc");
         String signKeyPassword = "changeit";        
         
         // specify should the output be ASCII or binary
         boolean asciiArmor = false;
         
         FileInputStream dataStream = new FileInputStream("c:\\Data\\INPUT.txt");
         FileOutputStream outputSignedStream = new FileOutputStream("signed.pgp");
          
         pgp.signStreamVersion3(dataStream,
                     "INPUT.txt" 
                     privateKeyStream, 
                     signKeyPassword, 
                     outputSignedFile,
                     asciiArmor);
     }
 }
 

Parameters:
dataFileStream - File data input stream, to be signed
internalFileName - File name to be associated with the data stream in the produced OpenPGP archive
privateKeyStream - Private Key input stream
out - Output Stream signed
privateKeyPassword - Private key password
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP encryption error
NoPrivateKeyFoundException - if the private key source does not contain a private key or is corrupted
WrongPasswordException - If the private key password is incorrect
KeyIsExpiredException - If the key is expired. Extends PGPException
KeyIsRevokedException - If the key is revoked. Extends PGPException
See Also:
verifyStream(InputStream, InputStream, OutputStream)

signAndEncryptFile

public void signAndEncryptFile(java.lang.String dataFileName,
                               java.lang.String privateKeyFileName,
                               java.lang.String privateKeyPassword,
                               java.lang.String publicKeyFile,
                               java.lang.String outputFileName,
                               boolean asciiArmor)
                        throws PGPException,
                               WrongPasswordException,
                               java.io.IOException
OpenPGP signs and encrypts a file in one pass.
(Note that this is not the same as first encrypt and then sign a file, because in that case a double compression is performed.)

Optional settings:
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // should output be ASCII or binary
         boolean asciiArmor = false;
         // should integrity check information be added
         boolean withIntegrityCheck = false;
         
         // sign and encrypt
         pgp.signAndEncryptFile("INPUT.txt", 
                                 "private_key.asc", 
                                 "key password",
                                 "recipient_key.asc",
                                 "encrypted_output.pgp", 
                                 asciiArmor,
                                 withIntegrityCheck);
     }
 }         
 

Parameters:
dataFileName - File Name to be OpenPGP signed and encrypted (absolute or relative path)
privateKeyFileName - Private Key file (absolute or relative path), used for signing or the key as ASCII armored string
privateKeyPassword - Private key password
publicKeyFile - Public key file (absolute or relative path), used for encryption or the key as ASCII armored string
outputFileName - File name of the OpenPGP Signed file (absolute or relative path)
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptAndVerifyFile(String, String, String, String, String)

signAndEncryptFile

public void signAndEncryptFile(java.lang.String dataFileName,
                               java.lang.String privateKeyFileName,
                               java.lang.String privateKeyPassword,
                               java.lang.String publicKeyFile,
                               java.lang.String outputFileName,
                               boolean asciiArmor,
                               boolean withIntegrityCheck)
                        throws PGPException,
                               WrongPasswordException,
                               java.io.IOException
OpenPGP signs and encrypts a file in one pass.
(Note that this is not the same as first encrypt and then sign a file)

Optional settings:
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // should output be ASCII or binary
         boolean asciiArmor = false;
         // should integrity check information be added
         boolean withIntegrityCheck = false;
         
         // sign and encrypt
         pgp.signAndEncryptFile("INPUT.txt", 
                                 "private_key.asc", 
                                 "key password",
                                 "recipient_key.asc",
                                 "encrypted_output.pgp", 
                                 asciiArmor,
                                 withIntegrityCheck);
     }
 }         
 

Parameters:
dataFileName - File Name to be OpenPGP signed and encrypted (absolute or relative path)
privateKeyFileName - Private Key file (absolute or relative path), used for signing
privateKeyPassword - Private key password
publicKeyFile - Public key file (absolute or relative path), used for encryption or the key as ASCII armored string
outputFileName - File name of the OpenPGP Signed file (absolute or relative path)
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
withIntegrityCheck - Should integrity check be added to the output file.
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptAndVerifyFile(String, String, String, String, String)

signAndEncryptFile

public void signAndEncryptFile(java.lang.String dataFileName,
                               java.lang.String privateKeyFileName,
                               java.lang.String privateKeyPassword,
                               java.lang.String[] publicKeyFiles,
                               java.lang.String outputFileName,
                               boolean asciiArmor,
                               boolean withIntegrityCheck)
                        throws PGPException,
                               WrongPasswordException,
                               java.io.IOException
OpenPGP signs and encrypts a file in one pass.
(Note that this is not the same as first encrypt and then sign a file)

Optional settings:
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // should output be ASCII or binary
         boolean asciiArmor = false;
         // should integrity check information be added
         boolean withIntegrityCheck = false;
         
         String[] recipientKeys = new String[] {"recipient_key1.asc", 
                                              "recipient_key2.asc",
                                              "recipient_key3.asc"};
         
         // sign and encrypt
         pgp.signAndEncryptFile("INPUT.txt", 
                                 "private_key.asc", 
                                 "key password",
                                 recipientKeys,
                                 "encrypted_output.pgp", 
                                 asciiArmor,
                                 withIntegrityCheck);
     }
 }         
 

Parameters:
dataFileName - File Name to be OpenPGP signed and encrypted (absolute or relative path)
privateKeyFileName - Private Key file (absolute or relative path), used for signing or the key as ASCII armored string
privateKeyPassword - Private key password
publicKeyFiles - Public key files that will be used for encryption (absolute or relative paths) or the keys as ASCII armored strings
outputFileName - File name of the OpenPGP Signed file (absolute or relative path)
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
withIntegrityCheck - Should integrity check be added to the output file.
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptAndVerifyFile(String, String, String, String, String)

signAndEncryptFile

public void signAndEncryptFile(java.lang.String fileName,
                               java.io.InputStream privateKeyStream,
                               java.lang.String privateKeyPassword,
                               java.io.InputStream publicKeyStream,
                               java.io.OutputStream outputStream,
                               boolean asciiArmor,
                               boolean withIntegrityCheck)
                        throws java.io.IOException,
                               PGPException,
                               WrongPasswordException
OpenPGP signs and encrypts a file in one pass.
(Note that this is not the same as first encrypt and then sign a file, because in that case a double compression is performed.)

Optional settings:
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import java.io.*;
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // should output be ASCII or binary
         boolean asciiArmor = false;
         // should integrity check information be added
         boolean withIntegrityCheck = false;
         
         // The signing key is usually our private key
         FileInputStream privateKeyStream = new FileInputStream("private_key.asc");
         String signKeyPassword = "changeit";
         
         FileInputStream publicEncryptionKeyStream = new FileInputStream("recipient_key.asc");        
         
         // specify should the output be ASCII or binary
         boolean asciiArmor = false;
         
         FileOutputStream outputStream = new FileOutputStream("encrypted_output.pgp");
         
         // sign and encrypt
         pgp.signAndEncryptFile("INPUT.txt", 
                                 privateKeyStream, 
                                 signKeyPassword,
                                 publicEncryptionKeyStream,
                                 outputStream, 
                                 asciiArmor,
                                 withIntegrityCheck);
     }
 }         
 

Parameters:
fileName - File Name to be OpenPGP Signed (absolute or relative path)
privateKeyStream - Private Key input stream (used for signing)
privateKeyPassword - Private key password
publicKeyStream - Public Key input stream (used for encryption)
outputStream - Output Stream signed and encrypted
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
withIntegrityCheck - Should integrity check be added to the file.
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptAndVerifyStream(InputStream, InputStream, String, InputStream, OutputStream)

signAndEncryptStream

public void signAndEncryptStream(java.io.InputStream dataStream,
                                 java.lang.String internalFileName,
                                 java.io.InputStream privateKeyStream,
                                 java.lang.String privateKeyPassword,
                                 java.io.InputStream publicKeyStream,
                                 java.io.OutputStream outputStream,
                                 boolean asciiArmor,
                                 boolean withIntegrityCheck)
                          throws java.io.IOException,
                                 PGPException,
                                 WrongPasswordException,
                                 NoPublicKeyFoundException,
                                 NoPrivateKeyFoundException
OpenPGP signs and encrypts a stream in one pass.
(Note that this is not the same as first encrypt and then sign)

Optional settings:
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import java.io.*;
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // should output be ASCII or binary
         boolean asciiArmor = false;
         // should integrity check information be added
         boolean withIntegrityCheck = false;
         
         // The signing key is usually our private key
         FileInputStream privateKeyStream = new FileInputStream("private_key.asc");
         String signKeyPassword = "changeit";
         
         FileInputStream publicEncryptionKeyStream = new FileInputStream("recipient_key.asc");        
         
         // specify should the output be ASCII or binary
         boolean asciiArmor = false;
         
         FileInputStream dataStream = new FileInputStream("c:\\Data\\INPUT.txt");
         FileOutputStream outputStream = new FileOutputStream("encrypted_output.pgp");
         
         // sign and encrypt
         pgp.signAndEncryptStream(dataStream,
                                 "INPUT.txt", 
                                 privateKeyStream, 
                                 signKeyPassword,
                                 publicEncryptionKeyStream,
                                 outputStream, 
                                 asciiArmor,
                                 withIntegrityCheck);
     }
 }         
 

Parameters:
dataStream - Data input stream to be signed
internalFileName - File name string to be associated with the data stream in the produced OpenPGP archive.
privateKeyStream - Private Key input stream (used for signing)
privateKeyPassword - Private key password
publicKeyStream - Public Key input stream (used for encryption)
outputStream - Output Stream signed and encrypted
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
withIntegrityCheck - Should integrity check be added to the file.
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptAndVerifyStream(InputStream, InputStream, String, InputStream, OutputStream)

signAndEncryptStream

public void signAndEncryptStream(java.io.InputStream dataStream,
                                 java.lang.String internalFileName,
                                 java.io.InputStream privateKeyStream,
                                 java.lang.String privateKeyPassword,
                                 java.io.InputStream[] publicKeyStreams,
                                 java.io.OutputStream outputStream,
                                 boolean asciiArmor,
                                 boolean withIntegrityCheck)
                          throws java.io.IOException,
                                 PGPException,
                                 WrongPasswordException,
                                 NoPublicKeyFoundException,
                                 NoPrivateKeyFoundException
OpenPGP signs and encrypts a stream in one pass.
(Note that this is not the same as first encrypt and then sign)

Optional settings:
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import java.io.*;
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // should output be ASCII or binary
         boolean asciiArmor = false;
         // should integrity check information be added
         boolean withIntegrityCheck = false;
         
         // The signing key is usually our private key
         FileInputStream privateKeyStream = new FileInputStream("private_key.asc");
         String signKeyPassword = "changeit";
         
         FileInputStream publicEncryptionKeyStream = new FileInputStream("recipient_key.asc");        
         
         // specify should the output be ASCII or binary
         boolean asciiArmor = false;
         
         FileInputStream dataStream = new FileInputStream("c:\\Data\\INPUT.txt");
         FileOutputStream outputStream = new FileOutputStream("encrypted_output.pgp");
         
         // sign and encrypt
         pgp.signAndEncryptStream(dataStream,
                                 "INPUT.txt", 
                                 privateKeyStream, 
                                 signKeyPassword,
                                 publicEncryptionKeyStream,
                                 outputStream, 
                                 asciiArmor,
                                 withIntegrityCheck);
     }
 }         
 

Parameters:
dataStream - Data input stream to be signed
internalFileName - File name string to be associated with the data stream in the produced OpenPGP archive.
privateKeyStream - Private Key input stream (used for signing)
privateKeyPassword - Private key password
publicKeyStream - Public Key input stream (used for encryption)
outputStream - Output Stream signed and encrypted
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
withIntegrityCheck - Should integrity check be added to the file.
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptAndVerifyStream(InputStream, InputStream, String, InputStream, OutputStream)

signAndEncryptFile

public void signAndEncryptFile(java.lang.String fileName,
                               KeyStore keyStore,
                               java.lang.String signUserId,
                               java.lang.String privateKeyPassword,
                               java.lang.String encUserId,
                               java.lang.String outputFileName,
                               boolean asciiArmor,
                               boolean withIntegrityCheck)
                        throws java.io.IOException,
                               PGPException
OpenPGP signs and encrypts a file in one pass.

(Note that this is not the same as first encrypt and then sign a file, because in that case a double compression is performed.)
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // should output be ASCII or binary
         boolean asciiArmor = false;
         // should integrity check information be added
         boolean withIntegrityCheck = false;
         
         // create an instance of the KeyStore
         KeyStore keyStore = new KeyStore("pgp.keystore", "changeit");
         
         // The signing key is usually our private key
         String signKeyUserId = "demo@didisoft.com";
         String signKeyPassword = "changeit";
         
         String encryptionKeyUserId = "Recipient Company ACM";
                 
         // sign and encrypt
         pgp.signAndEncryptFile("INPUT.txt",
                                 keyStore,  
                                 signKeyUserId, 
                                 signKeyPassword,
                                 encryptionKeyUserId,
                                 "encrypted_output.pgp", 
                                 asciiArmor,
                                 withIntegrityCheck);
     }
 }         
 

Parameters:
fileName - File Name to be OpenPGP signed and encrypted (absolute or relative path)
keyStore - KeyStore containing the private key for signing and the public key for encryption
signUserId - User Id or hexadecimal Key ID of the private key for signing
privateKeyPassword - Private key password
encUserId - User Id or hexadecimal Key ID of the public encryption key
outputFileName - File name of the OpenPGP Signed file (absolute or relative path)
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
withIntegrityCheck - if true integrity check information is added to the output file.
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
verifyFile(String, String, String)

signAndEncryptFile

public void signAndEncryptFile(java.lang.String fileName,
                               KeyStore keyStore,
                               java.lang.String signUserId,
                               java.lang.String privateKeyPassword,
                               java.lang.String[] encUserIds,
                               java.lang.String outputFileName,
                               boolean asciiArmor,
                               boolean withIntegrityCheck)
                        throws java.io.IOException,
                               PGPException
OpenPGP signs and encrypts a file in one pass for multiple recipients.

(Note that this is not the same as first encrypt and then sign a file)
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // should output be ASCII or binary
         boolean asciiArmor = false;
         // should integrity check information be added
         boolean withIntegrityCheck = false;
         
         // create an instance of the KeyStore
         KeyStore keyStore = new KeyStore("pgp.keystore", "changeit");
         
         // The signing key is usually our private key
         String signKeyUserId = "demo@didisoft.com";
         String signKeyPassword = "changeit";
         
         String encryptionKeyUserIds = new String[] {"Recipient Company ACM",
                                                     "Recipient Company 2",
                                                     "Recipient Company 3"} ;
                 
         // sign and encrypt
         pgp.signAndEncryptFile("INPUT.txt",
                                 keyStore,  
                                 signKeyUserId, 
                                 signKeyPassword,
                                 encryptionKeyUserIds,
                                 "encrypted_output.pgp", 
                                 asciiArmor,
                                 withIntegrityCheck);
     }
 }         
 

Parameters:
fileName - File Name to be OpenPGP signed and encrypted (absolute or relative path)
keyStore - KeyStore containing the private key for signing and the public key for encryption
signUserId - User Id or hexadecimal Key ID of the private key for signing
privateKeyPassword - Private key password
encUserIds - Array of User Id's or hexadecimal Key ID's of the recipients public keys that will be used for encryption
outputFileName - File name of the OpenPGP Signed file (absolute or relative path)
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
withIntegrityCheck - if true integrity check information is added to the output file.
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptAndVerifyFileTo(String, KeyStore, String, String), decryptAndVerifyFile(String, KeyStore, String, String)

signAndEncryptFile

public void signAndEncryptFile(java.lang.String fileName,
                               KeyStore keyStore,
                               long signKeyId,
                               java.lang.String privateKeyPassword,
                               long[] encKeyIds,
                               java.lang.String outputFileName,
                               boolean asciiArmor,
                               boolean withIntegrityCheck)
                        throws java.io.IOException,
                               PGPException
OpenPGP signs and encrypts a file in one pass for multiple recipients.

(Note that this is not the same as first encrypt and then sign a file)
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // should output be ASCII or binary
         boolean asciiArmor = false;
         // should integrity check information be added
         boolean withIntegrityCheck = false;
         
         // create an instance of the KeyStore
         KeyStore keyStore = new KeyStore("pgp.keystore", "changeit");
         
         // The signing key is usually our private key
         long signKeyId = keyStore.getKeyIdForUserId("demo@didisoft.com");
         String signKeyPassword = "changeit";
         
         long[] encryptionKeyIds = new long[] {keyStore.getKeyIdForKeyIdHex("74BB3286"),
                                               keyStore.getKeyIdForUserId("recipient@company.com")};
                 
         // sign and encrypt
         pgp.signAndEncryptFile("INPUT.txt",
                                 keyStore,  
                                 signKeyId, 
                                 signKeyPassword,
                                 encryptionKeyIds,
                                 "encrypted_output.pgp", 
                                 asciiArmor,
                                 withIntegrityCheck);
     }
 }         
 

Parameters:
fileName - File Name to be OpenPGP signed and encrypted (absolute or relative path)
keyStore - KeyStore containing the private key for signing and the public key for encryption
signKeyId - Key Id of the private key for signing
privateKeyPassword - Private key password
encKeyIds - Key Id's of the public keys that will be used for encryption
outputFileName - File name of the output OpenPGP file (absolute or relative path)
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
withIntegrityCheck - if true integrity check information is added to the output file.
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptAndVerifyFileTo(String, KeyStore, String, String), decryptAndVerifyFile(String, KeyStore, String, String)

signAndEncryptFile

public void signAndEncryptFile(java.lang.String fileName,
                               KeyStore keyStore,
                               long signKeyId,
                               java.lang.String privateKeyPassword,
                               long encKeyId,
                               java.lang.String outputFileName,
                               boolean asciiArmor,
                               boolean withIntegrityCheck)
                        throws java.io.IOException,
                               PGPException
OpenPGP signs and encrypts a file in one pass.

(Note that this is not the same as first encrypt and then sign a file, because in that case a double compression is performed.)
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // should output be ASCII or binary
         boolean asciiArmor = false;
         // should integrity check information be added
         boolean withIntegrityCheck = false;
         
         // create an instance of the KeyStore
         KeyStore keyStore = new KeyStore("pgp.keystore", "changeit");
         
         // The signing key is usually our private key
         long signKeyId = keyStore.getKeyIdForUserId("demo@didisoft.com");
         String signKeyPassword = "changeit";
         
         long encryptionKeyId = keyStore.getKeyIdForKeyIdHex("74BB3286");
                 
         // sign and encrypt
         pgp.signAndEncryptFile("INPUT.txt",
                                 keyStore,  
                                 signKeyId, 
                                 signKeyPassword,
                                 encryptionKeyId,
                                 "encrypted_output.pgp", 
                                 asciiArmor,
                                 withIntegrityCheck);
     }
 }         
 

Parameters:
fileName - File Name to be OpenPGP signed and encrypted (absolute or relative path)
keyStore - KeyStore containing the private key for signing and the public key for encryption
signKeyId - Key Id of the private key for signing
privateKeyPassword - Private key password
encKeyId - Key Id of the public encryption key
outputFileName - File name of the output OpenPGP file (absolute or relative path)
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
withIntegrityCheck - if true integrity check information is added to the output file.
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptAndVerifyFileTo(String, KeyStore, String, String), decryptAndVerifyFile(String, KeyStore, String, String)

signAndEncryptStream

public void signAndEncryptStream(java.io.InputStream dataFileStream,
                                 java.lang.String internalFileName,
                                 KeyStore keyStore,
                                 java.lang.String signUserId,
                                 java.lang.String privateKeyPassword,
                                 java.lang.String encUserId,
                                 java.io.OutputStream outputStream,
                                 boolean asciiArmor,
                                 boolean withIntegrityCheck)
                          throws java.io.IOException,
                                 PGPException
OpenPGP signs and encrypts a file in one pass.

(Note that this is not the same as first encrypt and then sign a file, because in that case a double compression is performed.)
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import java.io.*;
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // should output be ASCII or binary
         boolean asciiArmor = false;
         // should integrity check information be added
         boolean withIntegrityCheck = false;
         
         // create an instance of the KeyStore
         KeyStore keyStore = new KeyStore("pgp.keystore", "changeit");
         
         // The signing key is usually our private key
         String signKeyUserId = "demo@didisoft.com";
         String signKeyPassword = "changeit";
         
         String encryptionKeyUserId = "Recipient Company ACM";
                 
         FileInputStream dataStream = new FileInputStream("c:\\Data\\INPUT.txt");
         FileOutputStream outputSignedStream = new FileOutputStream("signed.pgp");
         
         // sign and encrypt
         pgp.signAndEncryptStream(dataStream,
                                 "INPUT.txt",
                                 keyStore,  
                                 signKeyUserId, 
                                 signKeyPassword,
                                 encryptionKeyUserId,
                                 outputSignedStream, 
                                 asciiArmor,
                                 withIntegrityCheck);
     }
 }         
 

Parameters:
dataFileStream - File data input stream, to be signed
internalFileName - File name string to be associated with the data stream in the produced OpenPGP archive.
keyStore - KeyStore containing the private key for signing and the public key for encryption
signUserId - User Id or hexadecimal Key ID of the private key for signing
privateKeyPassword - Private key password
encUserId - User Id or hexadecimal Key ID of the public key for encryption
outputStream - Output Stream signed and encrypted
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
withIntegrityCheck - should integrity check be added to the file.
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
verifyStream(InputStream, KeyStore, OutputStream)

signAndEncryptStream

public void signAndEncryptStream(java.io.InputStream dataFileStream,
                                 java.lang.String internalFileName,
                                 KeyStore keyStore,
                                 java.lang.String signUserId,
                                 java.lang.String privateKeyPassword,
                                 java.lang.String[] encUserIds,
                                 java.io.OutputStream outputStream,
                                 boolean asciiArmor,
                                 boolean withIntegrityCheck)
                          throws java.io.IOException,
                                 PGPException
OpenPGP signs and encrypts a file in one pass for multiple recipients

(Note that this is not the same as first encrypt and then sign a file, because in that case a double compression is performed.)
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import java.io.*;
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // should output be ASCII or binary
         boolean asciiArmor = false;
         // should integrity check information be added
         boolean withIntegrityCheck = false;
         
         // create an instance of the KeyStore
         KeyStore keyStore = new KeyStore("pgp.keystore", "changeit");
         
         // The signing key is usually our private key
         String signKeyUserId = "demo@didisoft.com";
         String signKeyPassword = "changeit";
         
         String[] encryptionKeyUserIds = new String[] {"Recipient Company ACM", "recipient2@company.com"};
                 
         FileInputStream dataStream = new FileInputStream("c:\\Data\\INPUT.txt");
         FileOutputStream outputSignedStream = new FileOutputStream("signed.pgp");
         
         String internalFileNameLabel = "INPUT.txt"; 
         
         // sign and encrypt
         pgp.signAndEncryptStream(dataStream,
                                 internalFileNameLabel,
                                 keyStore,  
                                 signKeyUserId, 
                                 signKeyPassword,
                                 encryptionKeyUserIds,
                                 outputSignedStream, 
                                 asciiArmor,
                                 withIntegrityCheck);
     }
 }         
 

Parameters:
dataFileStream - File data input stream, to be signed
internalFileName - File name string to be associated with the data stream in the produced OpenPGP archive.
keyStore - KeyStore containing the private key for signing and the public key for encryption
signUserId - User Id or hexadecimal Key ID of the private key for signing
privateKeyPassword - Private key password
encUserIds - User Id's or hexadecimal Key ID's of the public keys for encryption
outputStream - Output Stream signed and encrypted
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
withIntegrityCheck - should integrity check be added to the file.
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
verifyStream(InputStream, KeyStore, OutputStream)

signAndEncryptStream

public void signAndEncryptStream(java.io.InputStream dataFileStream,
                                 java.lang.String internalFileName,
                                 KeyStore keyStore,
                                 java.lang.String signUserId,
                                 java.lang.String privateKeyPassword,
                                 long[] encKeyIds,
                                 java.io.OutputStream outputStream,
                                 boolean asciiArmor,
                                 boolean withIntegrityCheck)
                          throws java.io.IOException,
                                 PGPException
OpenPGP signs and encrypts a file in one pass for multiple recipients

(Note that this is not the same as first encrypt and then sign a file, because in that case a double compression is performed.)
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import java.io.*;
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // should output be ASCII or binary
         boolean asciiArmor = false;
         // should integrity check information be added
         boolean withIntegrityCheck = false;
         
         // create an instance of the KeyStore
         KeyStore keyStore = new KeyStore("pgp.keystore", "changeit");
         
         // The signing key is usually our private key
         String signKeyUserId = "demo@didisoft.com";
         String signKeyPassword = "changeit";
         
         long[] encryptionKeyUserIds = new long[] {keyStore.getKeyIdForUserId("Recipient Company ACM"), 
                                                                                                keyStore.getKeyIdForUserId("recipient2@company.com")};
                 
         FileInputStream dataStream = new FileInputStream("c:\\Data\\INPUT.txt");
         FileOutputStream outputSignedStream = new FileOutputStream("signed.pgp");
         
         String internalFileNameLabel = "INPUT.txt"; 
         
         // sign and encrypt
         pgp.signAndEncryptStream(dataStream,
                                 internalFileNameLabel,
                                 keyStore,  
                                 signKeyUserId, 
                                 signKeyPassword,
                                 encryptionKeyUserIds,
                                 outputSignedStream, 
                                 asciiArmor,
                                 withIntegrityCheck);
     }
 }         
 

Parameters:
dataFileStream - File data input stream, to be signed
internalFileName - File name string to be associated with the data stream in the produced OpenPGP archive.
keyStore - KeyStore containing the private key for signing and the public key for encryption
signUserId - User Id or hexadecimal Key ID of the private key for signing
privateKeyPassword - Private key password
encKeyIds - Key Id's of the public keys for encryption
outputStream - Output Stream signed and encrypted
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
withIntegrityCheck - should integrity check be added to the file.
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
verifyStream(InputStream, KeyStore, OutputStream)

signAndEncryptFileVersion3

public void signAndEncryptFileVersion3(java.lang.String dataFileName,
                                       java.lang.String privateKeyFileName,
                                       java.lang.String privateKeyPassword,
                                       java.lang.String publicKeyFile,
                                       java.lang.String outputFileName,
                                       boolean asciiArmor)
                                throws PGPException,
                                       java.io.IOException
OpenPGP signs and encrypts a file in one pass, using OpenPGP version 3 signature format (compatible with PGP 6.5 and below)

(Note that this is not the same as first encrypt and then sign a file, because in that case a double compression is performed.)
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // should output be ASCII or binary
         boolean asciiArmor = false;
         
         // sign and encrypt
         pgp.signAndEncryptFileVersion3("INPUT.txt", 
                                 "private_key.asc", 
                                 "key password",
                                 "recipient_key.asc",
                                 "encrypted_output.pgp", 
                                 asciiArmor);
     }
 }         
 

Parameters:
dataFileName - File Name to be OpenPGP signed and encrypted (absolute or relative path)
privateKeyFileName - Private Key file (absolute or relative path), used for signing or the key as ASCII armored string
privateKeyPassword - Private key password
publicKeyFile - Recipients public key file (absolute or relative path), used for encryption or the key as ASCII armored string
outputFileName - File name of the OpenPGP Signed file (absolute or relative path)
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptAndVerifyFile(String, String, String, String, String)

signAndEncryptFileVersion3

public void signAndEncryptFileVersion3(java.lang.String dataFileName,
                                       java.lang.String privateKeyFileName,
                                       java.lang.String privateKeyPassword,
                                       java.lang.String publicKeyFile,
                                       java.lang.String outputFileName,
                                       boolean asciiArmor,
                                       boolean withIntegrityCheck)
                                throws PGPException,
                                       java.io.IOException
OpenPGP signs and encrypts a file in one pass, using OpenPGP version 3 signature format (compatible with PGP 6.5 and below)

(Note that this is not the same as first encrypt and then sign a file, because in that case a double compression is performed.)
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // should output be ASCII or binary
         boolean asciiArmor = false;
         // should integrity check information be added
         boolean withIntegrityCheck = false;
         
         // sign and encrypt
         pgp.signAndEncryptFileVersion3("INPUT.txt", 
                                 "private_key.asc", 
                                 "key password",
                                 "recipient_key.asc",
                                 "encrypted_output.pgp", 
                                 asciiArmor,
                                 withIntegrityCheck);
     }
 }         
 

Parameters:
dataFileName - File Name to be OpenPGP signed and encrypted (absolute or relative path)
privateKeyFileName - Private Key file (absolute or relative path), used for signing or the key as ASCII armored string
privateKeyPassword - Private key password
publicKeyFile - Recipients' public key file (absolute or relative path), used for encryption or the key as ASCII armored string
outputFileName - File name of the OpenPGP Signed file (absolute or relative path)
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
withIntegrityCheck - Should integrity check be added to the file. When producing data to be used by old systems (e.g. PGP 6.5) it is better to be false.
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptAndVerifyFile(String, String, String, String, String)

signAndEncryptStreamVersion3

public void signAndEncryptStreamVersion3(java.io.InputStream dataFileStream,
                                         java.lang.String internalFileName,
                                         java.io.InputStream privateKeyStream,
                                         java.lang.String privateKeyPassword,
                                         java.io.InputStream publicKeyStream,
                                         java.io.OutputStream outputStream,
                                         boolean asciiArmor)
                                  throws java.io.IOException,
                                         PGPException,
                                         WrongPasswordException
OpenPGP signs and encrypts a file in one pass, using OpenPGP version 3 signature format (compatible with PGP 6.5 and below)
(Note that this is not the same as first encrypt and then sign a file, because in that case a double compression is performed.)
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import java.io.*;
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // should output be ASCII or binary
         boolean asciiArmor = false;
         
         // The signing key is usually our private key
         FileInputStream privateKeyStream = new FileInputStream("private_key.asc");
         String signKeyPassword = "changeit";
         
         FileInputStream publicEncryptionKeyStream = new FileInputStream("recipient_key.asc");        
         
         FileInputStream dataStream = new FileInputStream("c:\\Data\\INPUT.txt");
         FileOutputStream outputStream = new FileOutputStream("encrypted_output.pgp");
         
         // sign and encrypt
         pgp.signAndEncryptStreamVersion3(dataStream,
                                          "INPUT.txt", 
                                          privateKeyStream, 
                                          signKeyPassword,
                                          publicEncryptionKeyStream,
                                          outputStream, 
                                          asciiArmor);
     }
 }         
 

Parameters:
dataFileStream - File data input stream, to be signed
internalFileName - File name string to be associated with the data stream in the produced OpenPGP archive.
privateKeyStream - Private Key input stream (used for signing)
privateKeyPassword - Private key password
publicKeyStream - Public Key input stream (used for encryption)
outputStream - Output Stream signed and encrypted
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptAndVerifyStream(InputStream, InputStream, String, InputStream, OutputStream)

signAndEncryptStreamVersion3

public void signAndEncryptStreamVersion3(java.io.InputStream dataFileStream,
                                         java.lang.String internalFileName,
                                         KeyStore keyStore,
                                         java.lang.String signingKeyUserId,
                                         java.lang.String privateKeyPassword,
                                         java.lang.String encryptionKeyUserId,
                                         java.io.OutputStream outputStream,
                                         boolean asciiArmor)
                                  throws java.io.IOException,
                                         PGPException,
                                         WrongPasswordException
OpenPGP signs and encrypts a file in one pass, using OpenPGP version 3 signature format (compatible with PGP 6.5 and below)
(Note that this is not the same as first encrypt and then sign a file, because in that case a double compression is performed.)
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import java.io.*;
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptStreamV3Demo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // should output be ASCII or binary
         boolean asciiArmor = false;
         
         // create an instance of the KeyStore
         KeyStore keyStore = new KeyStore("pgp.keystore", "changeit");
         
         // The signing key is usually our private key
         String signKeyUserId = "demo@didisoft.com";
         String signKeyPassword = "changeit";
         
         String encryptionKeyUserId = "Recipient Company ACM";
         
         FileInputStream dataStream = new FileInputStream("c:\\Data\\INPUT.txt");
         FileOutputStream outputStream = new FileOutputStream("encrypted_output.pgp");
         
         // sign and encrypt
         pgp.signAndEncryptStreamVersion3(dataStream,
                                          "INPUT.txt",
                                          keyStore, 
                                          signKeyUserId, 
                                          signKeyPassword,
                                          encryptionKeyUserId,
                                          outputStream, 
                                          asciiArmor);
     }
 }         
 

Parameters:
dataFileStream - File data input stream, to be signed
internalFileName - File name string to be associated with the data stream in the produced OpenPGP archive.
keyStore - KeyStore containing the public encryption and private signing keys
signingKeyId - User Id or hexadecimal Key Id of the private key used for signing
privateKeyPassword - Private key password
encryptionKeyId - User Id or hexadecimal Key Id of the public key used for encryption
outputStream - Output Stream signed and encrypted
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptAndVerifyStream(InputStream, InputStream, String, InputStream, OutputStream)

signAndEncryptStreamVersion3

public void signAndEncryptStreamVersion3(java.io.InputStream dataFileStream,
                                         java.lang.String internalFileName,
                                         KeyStore keyStore,
                                         long signingKeyId,
                                         java.lang.String privateKeyPassword,
                                         long encryptionKeyId,
                                         java.io.OutputStream outputStream,
                                         boolean asciiArmor)
                                  throws java.io.IOException,
                                         PGPException,
                                         WrongPasswordException
OpenPGP signs and encrypts a file in one pass, using OpenPGP version 3 signature format (compatible with PGP 6.5 and below)
(Note that this is not the same as first encrypt and then sign a file, because in that case a double compression is performed.)
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import java.io.*;
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptStreamV3Demo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // should output be ASCII or binary
         boolean asciiArmor = false;
         
         // create an instance of the KeyStore
         KeyStore keyStore = new KeyStore("pgp.keystore", "changeit");
         
         // The signing key is usually our private key
         String signKeyUserId = "demo@didisoft.com";
         String signKeyPassword = "changeit";
         
         String encryptionKeyUserId = "Recipient Company ACM";
         
         FileInputStream dataStream = new FileInputStream("c:\\Data\\INPUT.txt");
         FileOutputStream outputStream = new FileOutputStream("encrypted_output.pgp");
         
         // sign and encrypt
         pgp.signAndEncryptStreamVersion3(dataStream,
                                          "INPUT.txt",
                                          keyStore, 
                                          signKeyUserId, 
                                          signKeyPassword,
                                          encryptionKeyUserId,
                                          outputStream, 
                                          asciiArmor);
     }
 }         
 

Parameters:
dataFileStream - File data input stream, to be signed
internalFileName - File name string to be associated with the data stream in the produced OpenPGP archive.
keyStore - KeyStore containing the public encryption and private signing keys
signingKeyId - Key Id of the private key used for signing
privateKeyPassword - Private key password
encryptionKeyId - Key Id of the public key used for encryption
outputStream - Output Stream signed and encrypted
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptAndVerifyStream(InputStream, InputStream, String, InputStream, OutputStream)

signAndEncryptStreamVersion3

public void signAndEncryptStreamVersion3(java.io.InputStream dataFileStream,
                                         java.lang.String internalFileName,
                                         java.io.InputStream privateKeyStream,
                                         java.lang.String privateKeyPassword,
                                         java.io.InputStream publicKeyStream,
                                         java.io.OutputStream outputStream,
                                         boolean asciiArmor,
                                         boolean withIntegrityCheck)
                                  throws java.io.IOException,
                                         PGPException,
                                         WrongPasswordException
OpenPGP signs and encrypts a file in one pass, using OpenPGP version 3 signature format (compatible with older PGP 2.x systems)
(Note that this is not the same as first encrypt and then sign a file, because in that case a double compression is performed.)
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import java.io.*;
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // should output be ASCII or binary
         boolean asciiArmor = false;
         // should integrity check information be added
         boolean withIntegrityCheck = false;
         
         // The signing key is usually our private key
         FileInputStream privateKeyStream = new FileInputStream("private_key.asc");
         String signKeyPassword = "changeit";
         
         FileInputStream publicEncryptionKeyStream = new FileInputStream("recipient_key.asc");        
         
         FileInputStream dataStream = new FileInputStream("c:\\Data\\INPUT.txt");
         FileOutputStream outputStream = new FileOutputStream("encrypted_output.pgp");
         
         // sign and encrypt
         pgp.signAndEncryptStreamVersion3(dataStream,
                                          "INPUT.txt", 
                                          privateKeyStream, 
                                          signKeyPassword,
                                          publicEncryptionKeyStream,
                                          outputStream, 
                                          asciiArmor,
                                          withIntegrityCheck);
     }
 }         
 

Parameters:
dataFileStream - File data input stream, to be signed
internalFileName - File name string to be associated with the data stream in the produced OpenPGP archive.
privateKeyStream - Private Key input stream (used for signing)
privateKeyPassword - Private key password
publicKeyStream - Public Key input stream (used for encryption)
outputStream - Output Stream signed and encrypted
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
withIntegrityCheck - Should integrity check be added to the file. When producing data to be used by old systems (e.g. PGP 2.x) it is better to be false.
Throws:
java.io.IOException - If a file/stream operation throws an exception
PGPException - OpenPGP encryption error
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptAndVerifyStream(InputStream, InputStream, String, InputStream, OutputStream)

signAndEncryptString

public java.lang.String signAndEncryptString(java.lang.String stringToEncrypt,
                                             java.lang.String privateKeyFileName,
                                             java.lang.String privateKeyPassword,
                                             java.lang.String publicKeyFileName)
                                      throws PGPException,
                                             java.io.IOException
OpenPGP signs and encrypts a String message in one pass
The input String is assumed to be UTF-8 encoded.

Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptString {
     public static void main(String[] args) throws Exception {
     
         String stringToEncrypt = "the quick brown fox jumps"; 
     
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // The signing key is usually our private key
         String privateKeyFile "c:\\my_private_key.asc";
         String privateKeyPassword = "password";
         
         String publicEncryptionKeyFile = "c:\\recipient_public_key.asc";        
         
         // sign and encrypt
         String signedAndEncryptedString = 
              pgp.signAndEncryptString(stringToEncrypt,
                                       privateKeyFile, 
                                       privateKeyPassword, 
                                       publicEncryptionKeyFile);
     }
 }         
 

Parameters:
stringToEncrypt - String message to be signed and encrypted in one pass
privateKeyFileName - Private Key (used for signing) or the key as ASCII armored string
privateKeyPassword - Private key password
publicKeyFileName - Public Key (used for encryption)
Returns:
signed and encrypted message
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptAndVerifyStream(InputStream, InputStream, String, InputStream, OutputStream)

signAndEncryptStringVersion3

public java.lang.String signAndEncryptStringVersion3(java.lang.String stringToEncrypt,
                                                     java.lang.String privateKeyFileName,
                                                     java.lang.String privateKeyPassword,
                                                     java.lang.String publicKeyFileName)
                                              throws PGPException,
                                                     java.io.IOException
OpenPGP signs and encrypts a String message in one pass with OpenPGP version 3 signatures
The input String is assumed to be UTF-8 encoded.

Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptStringV3 {
     public static void main(String[] args) throws Exception {
     
         String stringToEncrypt = "the quick brown fox jumps"; 
     
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // The signing key is usually our private key
         String privateKeyFile "c:\\my_private_key.asc";
         String privateKeyPassword = "password";
         
         String publicEncryptionKeyFile = "c:\\recipient_public_key.asc";        
         
         // sign and encrypt
         String signedAndEncryptedString = 
              pgp.signAndEncryptStringVersion3(stringToEncrypt,
                                       privateKeyFile, 
                                       privateKeyPassword, 
                                       publicEncryptionKeyFile);
     }
 }         
 

Parameters:
stringToEncrypt - String message to be signed and encrypted in one pass
privateKeyFileName - Private Key file name (used for signing) or the key as ASCII armored string
privateKeyPassword - Private key password
(used - for signing) Public Key file name (used for encryption) or the key as ASCII armored string
Returns:
signed and encrypted message
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptAndVerifyStream(InputStream, InputStream, String, InputStream, OutputStream)

signAndEncryptString

public java.lang.String signAndEncryptString(java.lang.String stringToEncrypt,
                                             java.lang.String privateKeyFileName,
                                             java.lang.String privateKeyPassword,
                                             java.lang.String publicKeyFileName,
                                             java.lang.String charsetName)
                                      throws PGPException,
                                             java.io.IOException
OpenPGP signs and encrypts a String message in one pass
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptString {
     public static void main(String[] args) throws Exception {
     
         String stringToEncrypt = "the quick brown fox jumps"; 
     
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // The signing key is usually our private key
         String privateKeyFile "c:\\my_private_key.asc";
         String privateKeyPassword = "password";
         
         String publicEncryptionKeyFile = "c:\\recipient_public_key.asc";        
         
         String charsetCode = "UTF-8";
         
         // sign and encrypt
         String signedAndEncryptedString = 
              pgp.signAndEncryptString(stringToEncrypt,
                                       privateKeyFile, 
                                       privateKeyPassword, 
                                       publicEncryptionKeyFile,
                                       charsetCode);
     }
 }         
 

Parameters:
stringToEncrypt - String message to be signed and encrypted in one pass
privateKeyFileName - Private Key file name (used for signing) or the key as ASCII armored string
privateKeyPassword - Private key password
publicKeyFileName - Public Key file name (used for encryption) or the key as ASCII armored string
charsetName - the name of a supported charset
Returns:
signed and encrypted message
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

signAndEncryptStringVersion3

public java.lang.String signAndEncryptStringVersion3(java.lang.String stringToEncrypt,
                                                     java.lang.String privateKeyFileName,
                                                     java.lang.String privateKeyPassword,
                                                     java.lang.String publicKeyFileName,
                                                     java.lang.String charsetName)
                                              throws PGPException,
                                                     java.io.IOException
OpenPGP signs and encrypts a String message in one pass creating OpenPGP version 3 signatures
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
Hashing algorithm used is the one specified with setHash(String)

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class SignAndEncryptStringV3 {
     public static void main(String[] args) throws Exception {
     
         String stringToEncrypt = "the quick brown fox jumps"; 
     
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         // The signing key is usually our private key
         String privateKeyFile "c:\\my_private_key.asc";
         String privateKeyPassword = "password";
         
         String publicEncryptionKeyFile = "c:\\recipient_public_key.asc";        
         
         String charsetCode = "UTF-8";
         
         // sign and encrypt
         String signedAndEncryptedString = 
              pgp.signAndEncryptStringVersion3(stringToEncrypt,
                                       privateKeyFile, 
                                       privateKeyPassword, 
                                       publicEncryptionKeyFile,
                                       charsetCode);
     }
 }         
 

Parameters:
stringToEncrypt - String message to be signed and encrypted in one pass
privateKeyFileName - Private Key (used for signing)
privateKeyPassword - Private key password
publicKeyFileName - Public Key (used for encryption)
charsetName - the name of a supported charset
Returns:
signed and encrypted message
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
NoPrivateKeyFoundException - If the private key source does not contain an OpenPGP private key or is corrupted
WrongPasswordException - If the specified password for the private key is incorrect
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

decryptString

public java.lang.String decryptString(java.lang.String message,
                                      java.lang.String privateKeyFileName,
                                      java.lang.String privateKeyPassword)
                               throws java.io.IOException,
                                      PGPException
Decrypts an OpenPGP encrypted UTF-8 string message

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class DecryptStringDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = "..."; // Fill here the OpenPGP encrypted message

         String privateKeyFile = "c:\\my_private_key.asc";
         String privateKeyPassword = "my passsword";
         
         String decryptedMessage = pgp.decryptString(openpgpMessage,
                                                     privateKeyFile,
                                                     privateKeyPassword);
                                                           
         System.out.println("plain message: " + decryptedMessage);
     }
 }
 

Parameters:
message - OpenPGP encrypted message
privateKeyFile - Private key used for decryption or the key as ASCII armored string
privateKeyPassword - The password of the private key
Returns:
decrypted string message
Throws:
java.io.IOException - if an I/O operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted

decryptString

public java.lang.String decryptString(java.lang.String message,
                                      java.lang.String privateKeyFileName,
                                      java.lang.String privateKeyPassword,
                                      java.lang.String charsetName)
                               throws java.io.IOException,
                                      PGPException
Decrypts an OpenPGP encrypted string message.

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class DecryptStringDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = "..."; // Fill here the OpenPGP encrypted message

         String privateKeyFile = "c:\\my_private_key.asc";
         String privateKeyPassword = "my passsword";
         
         String messageCharSet = "UTF-8";
         String decryptedMessage = pgp.decryptString(openpgpMessage,
                                                     privateKeyFile,
                                                     privateKeyPassword, 
                                                     messageCharSet);
                                                           
         System.out.println("plain message: " + decryptedMessage);
     }
 }
 

Parameters:
message - OpenPGP encrypted message
privateKeyFile - Private key used for decryption or the key as ASCII armored string
privateKeyPassword - The password of the private key
charsetName - the name of a supported charset
Returns:
decrypted string message
Throws:
java.io.IOException - if an I/O operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted

decryptString

public java.lang.String decryptString(java.lang.String message,
                                      java.io.InputStream privateKeyStream,
                                      java.lang.String privateKeyPassword)
                               throws java.io.IOException,
                                      PGPException
Decrypts an OpenPGP encrypted UTF-8 string message.

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class DecryptStringDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = "..."; // Fill here the OpenPGP encrypted message

         String privateKeyFile = "c:\\my_private_key.asc";
         String privateKeyPassword = "my passsword";
                InputStream privateKeyStream = null;
         
         String messageCharSet = "UTF-8";
         try {
                privateKeyStream = new FileInputStream(privateKeyFileName);
                String decryptedMessage = pgp.decryptString(openpgpMessage,
                                                        privateKeyFile,
                                                        privateKeyPassword, 
                                                        messageCharSet);
         } finally {
                if (privateKeyStream != null)
                        privateKeyStream.close();
         }
                                                           
         System.out.println("plain message: " + decryptedMessage);
     }
 }
 

Parameters:
message - OpenPGP encrypted message
privateKeyStream - Private key used for decryption
privateKeyPassword - The password of the private key
Returns:
decrypted UTF-8 string message
Throws:
java.io.IOException - if an I/O operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted

decryptString

public java.lang.String decryptString(java.lang.String message,
                                      KeyStore keyStore,
                                      java.lang.String privateKeyPassword)
                               throws java.io.IOException,
                                      PGPException
Decrypts an OpenPGP encrypted UTF-8 string message.

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class DecryptStringDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = "..."; // Fill here the OpenPGP encrypted message

         String privateKeyPassword = "my passsword";
                 KeyStore keyStore = KeyStore.OpenFile("mylocal.keystore", "my password");
         
         String decryptedMessage = pgp.decryptString(openpgpMessage,
                                                        keyStore,
                                                        privateKeyPassword);
                                                           
         System.out.println("plain message: " + decryptedMessage);
     }
 }
 

Parameters:
message - OpenPGP encrypted message
keyStore - KeyStore containing the private decryption key
privateKeyPassword - The password of the private key
Returns:
decrypted string message
Throws:
java.io.IOException - if an I/O operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted

decryptString

public java.lang.String decryptString(java.lang.String message,
                                      KeyStore keyStore,
                                      java.lang.String privateKeyPassword,
                                      java.lang.String charsetName)
                               throws java.io.IOException,
                                      PGPException
Decrypts an OpenPGP encrypted string message.

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class DecryptStringDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = "..."; // Fill here the OpenPGP encrypted message

         String privateKeyPassword = "my passsword";
                 KeyStore keyStore = KeyStore.OpenFile("mylocal.keystore", "my password");
         
         String messageCharSet = "UTF-8";
         String decryptedMessage = pgp.decryptString(openpgpMessage,
                                                        keyStore,
                                                        privateKeyPassword, 
                                                        messageCharSet);
                                                           
         System.out.println("plain message: " + decryptedMessage);
     }
 }
 

Parameters:
message - OpenPGP encrypted message
keyStore - KeyStore containing the private decryption key
privateKeyPassword - The password of the private key
charsetName - the name of a supported charset
Returns:
decrypted string message
Throws:
java.io.IOException - if an I/O operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted

decryptString

public java.lang.String decryptString(java.lang.String message,
                                      java.io.InputStream privateKeyStream,
                                      java.lang.String privateKeyPassword,
                                      java.lang.String charsetName)
                               throws java.io.IOException,
                                      PGPException
Decrypts an OpenPGP encrypted string message.

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class DecryptStringDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = "..."; // Fill here the OpenPGP encrypted message

         String privateKeyFile = "c:\\my_private_key.asc";
         String privateKeyPassword = "my passsword";
                InputStream privateKeyStream = null;
         
         // verify and extract the signed content
         String messageCharSet = "UTF-8";
         try {
                privateKeyStream = new FileInputStream(privateKeyFileName);
                String decryptedMessage = pgp.decryptString(openpgpMessage,
                                                        privateKeyFile,
                                                        privateKeyPassword, 
                                                        messageCharSet);
         } finally {
                if (privateKeyStream != null)
                        privateKeyStream.close();
         }
                                                           
         System.out.println("plain message: " + decryptedMessage);
     }
 }
 

Parameters:
message - OpenPGP encrypted message
privateKeyStream - Private key used for decryption
privateKeyPassword - The password of the private key
charsetName - the name of a supported charset
Returns:
decrypted string message
Throws:
java.io.IOException - if an I/O operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted

decryptStream

public java.lang.String decryptStream(java.io.InputStream encryptedStream,
                                      java.io.InputStream privateKeyStream,
                                      java.lang.String privateKeyPassword,
                                      java.io.OutputStream outputStream)
                               throws PGPException,
                                      java.io.IOException
Decrypts an OpenPGP encrypted stream using Private key input stream.

For an extended exception handling example, check the online exception handling section.

Parameters:
encryptedStream - Input stream to be decrypted
privateKeyStream - Private key input stream
privateKeyPassword - Private key password
outputStream - Output stream for the decrypted contents
Returns:
Original File name stored in the OpenPGP Archive
Throws:
java.io.IOException - if an I/O operation throws an exception
PGPException - if a problem has occurred while decrypting data
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
See Also:
encryptStream(InputStream, String, InputStream, OutputStream, boolean, boolean)

decryptStreamTo

public java.lang.String[] decryptStreamTo(java.io.InputStream encryptedStream,
                                          java.io.InputStream privateKeyStream,
                                          java.lang.String privateKeyPassword,
                                          java.lang.String outputFolder)
                                   throws PGPException,
                                          java.io.IOException
Decrypts an OpenPGP encrypted stream to a specified folder. This method supports multiple file PGP archives (created with PGP(r) Desktop 9+ and compatible software)

For an extended exception handling example, check the online exception handling section.

Parameters:
encryptedStream - Input stream to be decrypted
privateKeyStream - Private key input stream
privateKeyPassword - Private key password
outputFolder - Output folder where the decrypted file(s) will be stored
Returns:
Array of absolute paths of the decrypted file(s).
Throws:
java.io.IOException - if an I/O operation throws an exception
PGPException - if a problem has occurred while decrypting data
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
See Also:
encryptFiles(String[], String[], String, boolean, boolean)

decryptStreamTo

public java.lang.String[] decryptStreamTo(java.io.InputStream encryptedStream,
                                          KeyStore keyStore,
                                          java.lang.String privateKeyPassword,
                                          java.lang.String outputFolder)
                                   throws PGPException,
                                          java.io.IOException
Decrypts an OpenPGP encrypted stream to a specified folder. This method supports multiple file PGP archives (created with PGP Desktop 9+ and compatible software)

For an extended exception handling example, check the online exception handling section.

Parameters:
encryptedStream - Input stream to be decrypted
keyStore - KeyStore containing the decryption private key
privateKeyPassword - Private key password
outputFolder - Output folder where the decrypted file(s) will be stored
Returns:
Array of absolute paths of the decrypted file(s).
Throws:
java.io.IOException - if an I/O operation throws an exception
PGPException - if a problem has occurred while decrypting data
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
See Also:
encryptFiles(String[], KeyStore, String[], String, boolean, boolean), encryptFiles(String[], KeyStore, long[], String, boolean, boolean)

decryptStream

public java.lang.String decryptStream(java.io.InputStream encryptedStream,
                                      KeyStore pgpKeyStore,
                                      java.lang.String privateKeyPassword,
                                      java.io.OutputStream outputStream)
                               throws PGPException,
                                      java.io.IOException
Decrypts an OpenPGP encrypted stream using a private key supplied as an input stream.

For an extended exception handling example, check the online exception handling section.

Parameters:
encryptedStream - Input Stream to be decrypted
pgpKeyStore - Instance of KeyStore, that should contain the Private key to decrypt encryptedStream
privateKeyPassword - Private key password
outputStream - Output Stream for the decrypted contents
Returns:
Original file name stored in the OpenPGP Archive
Throws:
java.io.IOException - if an I/O operation throws an exception
PGPException - if a problem has occurred while decrypting data
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
See Also:
encryptStream(InputStream, String, KeyStore, String, OutputStream, boolean, boolean), encryptStream(InputStream, String, KeyStore, long, OutputStream, boolean, boolean)

decryptFile

public java.lang.String decryptFile(java.lang.String encryptedFileName,
                                    KeyStore pgpKeyStore,
                                    java.lang.String privateKeyPassword,
                                    java.lang.String outputFileName)
                             throws PGPException,
                                    java.io.IOException
Decrypts an OpenPGP encrypted file using key from a OpenPGP key store.

For an extended exception handling example, check the online exception handling section.

Parameters:
encryptedFileName - File name to be decrypted (absolute or relative path)
pgpKeyStore - Key store object. See KeyStore
privateKeyPassword - Private key password
outputFileName - File name of the Output decrypted file (absolute or relative path)
Returns:
The original file name of the encrypted data in this OpenPGP archive
Throws:
java.io.IOException - if an I/O operation throws an exception
PGPException - if a problem has occurred while decrypting data
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
See Also:
encryptFile(String, KeyStore, String, String), encryptFile(String, KeyStore, long, String)

decryptFile

public java.lang.String decryptFile(java.lang.String encryptedFileName,
                                    java.lang.String privateKeyFileName,
                                    java.lang.String privateKeyPassword,
                                    java.lang.String outputFileName)
                             throws PGPException,
                                    java.io.IOException
Decrypts an OpenPGP encrypted file using Private key file.

For an extended exception handling example, check the online exception handling section.

Example:
 import com.didisoft.pgp.*;
 
 public class DecryptFile {
     public static void main(String[] args) throws Exception{
         // initialize the library instance
         PGPLib pgp = new PGPLib();
         
         String privateKeyFile = "private.key";
         String privateKeyPass = "changeit";
 
         // The decrypt method returns the original name of the file
         // that was encrypted. We can use it afterwards,
         // to rename OUTPUT.txt      
         String originalFileName = pgp.decryptFile("encrypted.pgp", 
                                                 privateKeyFile, 
                                                 privateKeyPass, 
                                                 "OUTPUT.txt");
     }
 

Parameters:
encryptedFileName - File name to be decrypted (absolute or relative path)
privateKeyFileName - Private Key file name (absolute or relative path) or the key as ASCII armored string
privateKeyPassword - Private key password
outputFileName - File name of the Output decrypted file (absolute or relative path).
Returns:
The original file name of the encrypted data in this OpenPGP archive
Throws:
java.io.IOException - if an I/O operation throws an exception
PGPException - if a problem has occurred while decrypting data
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
See Also:
encryptFile(String, String, String, boolean, boolean)

decryptFilePBE

public java.lang.String decryptFilePBE(java.lang.String encryptedFileName,
                                       java.lang.String decryptionPassword,
                                       java.lang.String outputFileName)
                                throws PGPException,
                                       java.io.IOException
Decrypts an OpenPGP file that was encrypted with password (PBE, symmetric key encrypted).

Example:
 import com.didisoft.pgp.*;
 
 public class DecryptFilePBE {
     public static void main(String[] args) throws Exception{
         // initialize the library instance
         PGPLib pgp = new PGPLib();
         
         // The decrypt method returns the original name of the file
         // that was encrypted. We can use it afterwards,
         // to rename OUTPUT.txt      
         String originalFileName = pgp.decryptFilePBE("encrypted.pgp", 
                                                        "decryption password", 
                                                        "OUTPUT.txt");
     }
 }    
 

Parameters:
encryptedFileName - File name to be decrypted (absolute or relative path)
decryptionPassword - Password used for symmetric encryption of the input file
outputFileName - File name of the Output decrypted file (absolute or relative path).
Returns:
The original file name of the encrypted data in this OpenPGP archive
Throws:
java.io.IOException - if an I/O operation throws an exception
PGPException - if a problem has occurred while decrypting data
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
WrongPasswordException - if the password is misspelled.
FileIsEncryptedException - if the encrypted input is encrypted with an OpenPGP key only
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
See Also:
encryptFilePBE(String, String, String, String, boolean, boolean)

decryptStringPBE

public java.lang.String decryptStringPBE(java.lang.String message,
                                         java.lang.String decryptionPassword)
                                  throws java.io.IOException,
                                         PGPException
Decrypts an OpenPGP password encrypted UTF-8 string message.

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class DecryptStringPBEDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = "..."; // Fill here the OpenPGP encrypted message

         String decryptionPassword = "my passsword";
         
         String decryptedMessage = pgp.decryptStringPBE(openpgpMessage,
                                                     decryptionPassword);
                                                           
         System.out.println("plain message: " + decryptedMessage);
     }
 }
 

Parameters:
message - OpenPGP encrypted message
decryptionPassword - The same password that was used to encrypt the message
Returns:
decrypted string message
Throws:
java.io.IOException - if an I/O operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted

decryptStringPBE

public java.lang.String decryptStringPBE(java.lang.String message,
                                         java.lang.String decryptionPassword,
                                         java.lang.String charsetName)
                                  throws java.io.IOException,
                                         PGPException
Decrypts an OpenPGP password encrypted string message.

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class DecryptStringDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = "..."; // Fill here the OpenPGP encrypted message

         String decryptionPassword = "my passsword";
         
         // verify and extract the signed content
         String messageCharSet = "UTF-8";
         String decryptedMessage = pgp.decryptStringPBE(openpgpMessage,
                                                     decryptionPassword, 
                                                     messageCharSet);
                                                           
         System.out.println("plain message: " + decryptedMessage);
     }
 }
 

Parameters:
message - OpenPGP encrypted message
decryptionPassword - The same password that was used to encrypt the message
charsetName - the name of a supported charset
Returns:
decrypted string message
Throws:
java.io.IOException - if an I/O operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted

decryptStreamPBE

public java.lang.String decryptStreamPBE(java.io.InputStream encryptedStream,
                                         java.lang.String decryptionPassword,
                                         java.io.OutputStream outputStream)
                                  throws PGPException,
                                         java.io.IOException
Decrypts an OpenPGP stream that was encrypted with a password (PBE, symmetric key encrypted).

Example:
 import com.didisoft.pgp.*;
 
 public class DecryptStreamPBE {
     public static void main(String[] args) throws Exception{
        // initialize the library instance
        PGPLib pgp = new PGPLib();
                      
        InputStream encryptedStream = null;
        OutputStream outputStream = null;
 
        try {
            encryptedStream = new BufferedInputStream(new FileInputStream("encrypted.pgp"));
            outputStream = new BufferedOutputStream(new FileOutputStream("OUTPUT.txt"));
         
            decryptStreamPBE(encryptedStream, "decryption password", outputStream);
        } finally {
            encryptedStream.close();
            outputStream.close();
        }    
     }
 }    
 

Parameters:
encryptedStream - Input stream data to be decrypted
decryptionPassword - Password used for symmetric encryption of the input file
outputFileName - Output stream for the decrypted data
Returns:
The original file name of the encrypted data in this OpenPGP archive
Throws:
java.io.IOException - if an I/O operation throws an exception
PGPException - if a problem has occurred while decrypting data
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
WrongPasswordException - if the password is misspelled.
FileIsEncryptedException - if the encrypted input is encrypted with an OpenPGP key only
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
See Also:
encryptFilePBE(String, String, String, String, boolean, boolean)

decryptFileTo

public java.lang.String[] decryptFileTo(java.lang.String encryptedFileName,
                                        java.lang.String privateKeyFileName,
                                        java.lang.String privateKeyPassword,
                                        java.lang.String outputFolder)
                                 throws PGPException,
                                        java.io.IOException
Decrypts the content of an OpenPGP encrypted file into a folder.

For an extended exception handling example, check the online exception handling section.

Example usage:

 import com.didisoft.pgp.*;
 
 public class DecryptFileTo {
     public static void main(String[] args) throws Exception{
         // initialize the library instance
         PGPLib pgp = new PGPLib();
         
         String privateKeyFile = "private.key";
         String privateKeyPass = "changeit";
 
         // The decrypt method returns array with decrypted file paths
         String[] files = pgp.decryptFileTo("encrypted.pgp", 
                                           privateKeyFile, 
                                           privateKeyPass, 
                                           "c:\\Temp\\");
                                                 
         for (int i=0; i

Parameters:
encryptedFileName - File name to be decrypted (absolute or relative path)
privateKeyFileName - Private Key file name (absolute or relative path) or the key as ASCII armored string
privateKeyPassword - Private key password
outputFolder - Folder path (absolute or relative path) where the decrypted file(s) will be stored
Returns:
Array of file paths of the decrypted file(s)
Throws:
java.io.IOException - if an I/O operation throws an exception
PGPException - if a problem has occurred while decrypting data
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
See Also:
encryptFiles(String[], String[], String, boolean, boolean)

decryptFileTo

public java.lang.String[] decryptFileTo(java.lang.String encryptedFileName,
                                        KeyStore keyStore,
                                        java.lang.String privateKeyPassword,
                                        java.lang.String outputFolder)
                                 throws PGPException,
                                        java.io.IOException
Decrypts the content of an OpenPGP encrypted file into a folder.

For an extended exception handling example, check the online exception handling section.

Example usage:

 import com.didisoft.pgp.*;
 
 public class DecryptFileTo {
     public static void main(String[] args) throws Exception{
         // initialize the library instance
         PGPLib pgp = new PGPLib();
         
         KeyStore keyStore = new KeyStore("my.keystore", "keystore pasword");
         String privateKeyPass = "changeit";
 
         // The decrypt method returns array with decrypted file paths
         String[] files = pgp.decryptFileTo("encrypted.pgp", 
                                           keyStore, 
                                           privateKeyPass, 
                                           "c:\\Temp\\");
                                                 
         for (int i=0; i

Parameters:
encryptedFileName - File name to be decrypted (absolute or relative path)
keyStore - KeyStore object containing the private decryption key
privateKeyPassword - Private key password
outputFolder - Folder path (absolute or relative path) where the decrypted file(s) will be stored
Returns:
Array of file paths of the decrypted file(s)
Throws:
java.io.IOException - if an I/O operation throws an exception
PGPException - if a problem has occurred while decrypting data
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
See Also:
encryptFiles(String[], KeyStore, String[], String, boolean, boolean)

decryptFile

public java.lang.String decryptFile(java.lang.String encryptedFileName,
                                    java.io.InputStream privateKeyStream,
                                    java.lang.String privateKeyPassword,
                                    java.lang.String outputFileName)
                             throws PGPException,
                                    java.io.IOException
Decrypts an OpenPGP encrypted file using Private key input stream.

Parameters:
encryptedFileName - File name to be decrypted (absolute or relative path)
privateKeyStream - Private Key input stream
privateKeyPassword - Private key password
outputFileName - File name of the Output decrypted file (absolute or relative path).
Returns:
The original file name of the encrypted data in this OpenPGP archive
Throws:
java.io.IOException - if an I/O operation throws an exception
PGPException - if a problem has occurred while decrypting data
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
See Also:
encryptFile(String, String, String, boolean, boolean)

encryptString

public java.lang.String encryptString(java.lang.String stringToEncrypt,
                                      java.lang.String publicKeyFileName)
                               throws PGPException,
                                      java.io.IOException
OpenPGP encrypts a UTF-8 encoded string message
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class EncryptStringDemo {
     public static void main(String[] args) throws Exception {
         String stringToEncrypt = "the quick brown fox jumps"; 
     
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         String publicEncryptionKeyFile = "c:\\recipient_public_key.asc";        
         
         // encrypt
         String encryptedString = 
              pgp.encryptString(stringToEncrypt,
                                publicEncryptionKeyFile);
     }
 }         
 

Parameters:
stringToEncrypt - String message to be encrypted
publicKeyFileName - Public Key (used for encryption) or the key as ASCII armored string
Returns:
encrypted string message
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptString

public java.lang.String encryptString(java.lang.String stringToEncrypt,
                                      java.lang.String publicKeyFileName,
                                      java.lang.String charsetName)
                               throws PGPException,
                                      java.io.IOException
OpenPGP encrypts a String message
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class EncryptStringDemo {
     public static void main(String[] args) throws Exception {
         String stringToEncrypt = "the quick brown fox jumps"; 
     
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         String publicEncryptionKeyFile = "c:\\recipient_public_key.asc";        
         String charsetCode = "UTF-8";
         
         // encrypt
         String encryptedString = 
              pgp.encryptString(stringToEncrypt,
                                publicEncryptionKeyFile,
                                charsetCode);
     }
 }         
 

Parameters:
stringToEncrypt - String message to be encrypted
publicKeyFileName - Public Key (used for encryption) or the key as ASCII armored string
charsetName - the name of a supported charset
Returns:
encrypted string message
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptString

public java.lang.String encryptString(java.lang.String stringToEncrypt,
                                      java.lang.String[] publicKeyFileNames,
                                      java.lang.String charsetName)
                               throws PGPException,
                                      java.io.IOException
OpenPGP encrypts a String message
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class EncryptStringDemo {
     public static void main(String[] args) throws Exception {
         String stringToEncrypt = "the quick brown fox jumps"; 
     
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         String publicEncryptionKeyFile = "c:\\recipient_public_key.asc";        
         String charsetCode = "UTF-8";
         
         // encrypt
         String encryptedString = 
              pgp.encryptString(stringToEncrypt,
                                new String[] {"c:\\recipient_public_key1.asc",
                                                                "c:\\recipient_public_key2.asc",},
                                charsetCode);
     }
 }         
 

Parameters:
stringToEncrypt - String message to be encrypted
publicKeyFileNames - Public keys (used for encryption) or the key as ASCII armored string
charsetName - the name of a supported charset
Returns:
encrypted string message
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptString

public java.lang.String encryptString(java.lang.String stringToEncrypt,
                                      KeyStore keyStore,
                                      java.lang.String userId)
                               throws PGPException,
                                      java.io.IOException
OpenPGP encrypts a UTF-8 String message

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class EncryptStringDemo {
     public static void main(String[] args) throws Exception {
         String stringToEncrypt = "the quick brown fox jumps"; 
     
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         KeyStore keystore = KeyStore.openFile("c:\\mylocal.keystore", "my password");        
         
         // encrypt
         String encryptedString = 
              pgp.encryptString(stringToEncrypt,
                                keystore,
                                "ACM company");
     }
 }         
 

Parameters:
stringToEncrypt - String message to be encrypted
keyStore - KeyStore containing the encryption key
userId - User Id or hexadecimal Key Id of the recipient's public key
Returns:
encrypted string message
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptString

public java.lang.String encryptString(java.lang.String stringToEncrypt,
                                      KeyStore keyStore,
                                      java.lang.String userId,
                                      java.lang.String charsetName)
                               throws PGPException,
                                      java.io.IOException
OpenPGP encrypts a String message

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class EncryptStringDemo {
     public static void main(String[] args) throws Exception {
         String stringToEncrypt = "the quick brown fox jumps"; 
     
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         KeyStore keystore = KeyStore.openFile("c:\\mylocal.keystore", "my password");        
         String charsetCode = "UTF-8";
         
         // encrypt
         String encryptedString = 
              pgp.encryptString(stringToEncrypt,
                                keystore,
                                "ACM company",
                                charsetCode);
     }
 }         
 

Parameters:
stringToEncrypt - String message to be encrypted
keyStore - KeyStore containing the encryption key
userId - User Id or hexadecimal Key Id of the recipient's public key
charsetName - the name of a supported charset
Returns:
encrypted string message
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptString

public java.lang.String encryptString(java.lang.String stringToEncrypt,
                                      KeyStore keyStore,
                                      long keyId)
                               throws PGPException,
                                      java.io.IOException
OpenPGP encrypts a UTF-8 String message

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class EncryptStringDemo {
     public static void main(String[] args) throws Exception {
         String stringToEncrypt = "the quick brown fox jumps"; 
     
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         KeyStore keystore = KeyStore.openFile("c:\\mylocal.keystore", "my password");        
         
         // encrypt
         String encryptedString = 
              pgp.encryptString(stringToEncrypt,
                                keystore,
                                keystore.getKeyIdForKeyIdHex("A0324F1D"));
     }
 }         
 

Parameters:
stringToEncrypt - String message to be encrypted
keyStore - KeyStore containing the encryption key
keyId - Key Id of the recipient's public key
Returns:
encrypted string message
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptString

public java.lang.String encryptString(java.lang.String stringToEncrypt,
                                      KeyStore keyStore,
                                      long keyId,
                                      java.lang.String charsetName)
                               throws PGPException,
                                      java.io.IOException
OpenPGP encrypts a String message

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class EncryptStringDemo {
     public static void main(String[] args) throws Exception {
         String stringToEncrypt = "the quick brown fox jumps"; 
     
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         KeyStore keystore = KeyStore.openFile("c:\\mylocal.keystore", "my password");        
         String charsetCode = "UTF-8";
         
         // encrypt
         String encryptedString = 
              pgp.encryptString(stringToEncrypt,
                                keystore,
                                keystore.getKeyIdForKeyIdHex("A0324F1D"),
                                charsetCode);
     }
 }         
 

Parameters:
stringToEncrypt - String message to be encrypted
keyStore - KeyStore containing the encryption key
keyId - Key Id of the recipient's public key
charsetName - the name of a supported charset
Returns:
encrypted string message
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptString

public java.lang.String encryptString(java.lang.String stringToEncrypt,
                                      KeyStore keyStore,
                                      long[] keyIds,
                                      java.lang.String charsetName)
                               throws PGPException,
                                      java.io.IOException
OpenPGP encrypts a String message for multiple recipients

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class EncryptStringDemo {
     public static void main(String[] args) throws Exception {
         String stringToEncrypt = "the quick brown fox jumps"; 
     
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         KeyStore keystore = KeyStore.openFile("c:\\mylocal.keystore", "my password");        
         String charsetCode = "UTF-8";
         
         // encrypt
         String encryptedString = 
              pgp.encryptString(stringToEncrypt,
                                keystore,
                                new long[] {keystore.getKeyIdForKeyIdHex("A0324F1D")},
                                charsetCode);
     }
 }         
 

Parameters:
stringToEncrypt - String message to be encrypted
keyStore - KeyStore containing the encryption key
keyIds - array of Key Ids of the recipients' public keys
charsetName - the name of a supported charset
Returns:
encrypted string message
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptString

public java.lang.String encryptString(java.lang.String stringToEncrypt,
                                      KeyStore keyStore,
                                      java.lang.String[] keyIdOrUserIds,
                                      java.lang.String charsetName)
                               throws PGPException,
                                      java.io.IOException
OpenPGP encrypts a String message for multiple recipients

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class EncryptStringDemo {
     public static void main(String[] args) throws Exception {
         String stringToEncrypt = "the quick brown fox jumps"; 
     
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         KeyStore keystore = KeyStore.openFile("c:\\mylocal.keystore", "my password");        
         String charsetCode = "UTF-8";
         
         // encrypt
         String encryptedString = 
              pgp.encryptString(stringToEncrypt,
                                keystore,
                                new String[] {"A0324F1D", "James Doe"},
                                charsetCode);
     }
 }         
 

Parameters:
stringToEncrypt - String message to be encrypted
keyStore - KeyStore containing the encryption key
keyIdOrUserIds - array of hexadecimal Key Ids or User IDs of the recipients' public keys
charsetName - the name of a supported charset
Returns:
encrypted string message
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptString

public java.lang.String encryptString(java.lang.String stringToEncrypt,
                                      java.io.InputStream publicEncryptionKeyStream)
                               throws PGPException,
                                      java.io.IOException
OpenPGP encrypts a String UTF-8 message
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class EncryptStringDemo {
     public static void main(String[] args) throws Exception {
         String stringToEncrypt = "the quick brown fox jumps"; 
     
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         String publicEncryptionKeyFile = "c:\\recipient_public_key.asc";        
         
         InputStream publicEncryptionKeyStream = null;
         try {
                publicEncryptionKeyStream = new FileInputStream(publicKeyFileName);
        
         // encrypt
         String encryptedString = 
              pgp.encryptString(stringToEncrypt,
                                publicEncryptionKeyStream);
        } finally {
              if (publicEncryptionKeyStream != null)
                publicEncryptionKeyStream.close();
        }      
    }
 }         
 

Parameters:
stringToEncrypt - String UTF-8 message to be encrypted
publicEncryptionKeyStream - Public Key as stream (used for encryption)
Returns:
encrypted string message
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptString

public java.lang.String encryptString(java.lang.String stringToEncrypt,
                                      java.io.InputStream publicEncryptionKeyStream,
                                      java.lang.String charsetName)
                               throws PGPException,
                                      java.io.IOException
OpenPGP encrypts a String message
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class EncryptStringDemo {
     public static void main(String[] args) throws Exception {
         String stringToEncrypt = "the quick brown fox jumps"; 
     
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         String publicEncryptionKeyFile = "c:\\recipient_public_key.asc";        
         String charsetCode = "UTF-8";
         
         InputStream publicEncryptionKeyStream = null;
         try {
                publicEncryptionKeyStream = new FileInputStream(publicKeyFileName);
        
         // encrypt
         String encryptedString = 
              pgp.encryptString(stringToEncrypt,
                                publicEncryptionKeyStream,
                                charsetCode);
        } finally {
              if (publicEncryptionKeyStream != null)
                publicEncryptionKeyStream.close();
        }      
    }
 }         
 

Parameters:
stringToEncrypt - String message to be encrypted
publicEncryptionKeyStream - Public Key as stream (used for encryption)
charsetName - the name of a supported charset
Returns:
encrypted string message
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

signString

public java.lang.String signString(java.lang.String message,
                                   java.lang.String privateKeyFile,
                                   java.lang.String privateKeyPassword)
                            throws PGPException,
                                   java.io.IOException
OpenPGP signs a String message assuming the message is UTF-8 encoded

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class SignStringDemo {
     public static void main(String[] args) throws Exception {
         String message = "the quick brown fox jumps"; 
     
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         String privateKeyFile = "c:\\my_key.asc";        
         
         String signedString = 
              pgp.signString(message,
                                privateKeyFile,
                                "key password");
    }
 }         
 

Parameters:
stringToEncrypt - String message to be encrypted
privateKeyStream - Private Key file name (used for signing) or the key as ASCII armored string
privateKeyPassword - the password of the private key
Returns:
signed string message
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPrivateKeyFoundException - if the private key source does not contain a public key or is corrupted
WrongPrivateKeyException - if the provided password for the private key is wrong

signString

public java.lang.String signString(java.lang.String message,
                                   java.lang.String privateKeyFile,
                                   java.lang.String privateKeyPassword,
                                   java.lang.String charsetName)
                            throws PGPException,
                                   java.io.IOException
OpenPGP signs a String message

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class SignStringDemo {
     public static void main(String[] args) throws Exception {
         String message = "the quick brown fox jumps"; 
     
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         String privateKeyFile = "c:\\my_key.asc";        
         String charsetCode = "UTF-8";
         
         String signedString = 
              pgp.signString(message,
                                privateKeyFile,
                                "key password",
                                charsetCode);
    }
 }         
 

Parameters:
stringToEncrypt - String message to be encrypted
privateKeyStream - Private Key file name (used for signing) or the key as ASCII armored string
privateKeyPassword - the password of the private key
charsetName - the name of a supported charset
Returns:
signed string message
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPrivateKeyFoundException - if the private key source does not contain a public key or is corrupted
WrongPrivateKeyException - if the provided password for the private key is wrong

signString

public java.lang.String signString(java.lang.String message,
                                   java.io.InputStream privateKeyStream,
                                   java.lang.String privateKeyPassword,
                                   java.lang.String charsetName)
                            throws PGPException,
                                   java.io.IOException
OpenPGP signs a String message

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class SignStringDemo {
     public static void main(String[] args) throws Exception {
         String message = "the quick brown fox jumps"; 
     
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         String privateKeyFile = "c:\\my_key.asc";        
         String charsetCode = "UTF-8";
         
         InputStream privateKeyStream = null;
         try {
                privateKeyStream = new FileInputStream(privateKeyFile);
        
         String signedString = 
              pgp.signString(message,
                                privateKeyStream,
                                "key password",
                                charsetCode);
        } finally {
              if (privateKeyStream != null)
                privateKeyStream.close();
        }      
    }
 }         
 

Parameters:
stringToEncrypt - String message to be encrypted
privateKeyStream - Private Key as stream (used for signing)
privateKeyPassword - the password of the private key
charsetName - the name of a supported charset
Returns:
signed string message
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPrivateKeyFoundException - if the private key source does not contain a public key or is corrupted
WrongPrivateKeyException - if the provided password for the private key is wrong

signString

public java.lang.String signString(java.lang.String message,
                                   KeyStore keyStore,
                                   java.lang.String privateKeyUserId,
                                   java.lang.String privateKeyPassword,
                                   java.lang.String charsetName)
                            throws PGPException,
                                   java.io.IOException
OpenPGP signs a String message

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class SignStringDemo {
     public static void main(String[] args) throws Exception {
         String message = "the quick brown fox jumps"; 
     
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         KeyStore keyStore = new KeyStore("pgp.keystore", "changeit");
         
         // The signing key is usually our private key
         long signKeyUserId = "demo@didisoft.com";
         String signKeyPassword = "changeit";        
         String charsetCode = "UTF-8";
         
         InputStream privateKeyStream = null;
         try {
                privateKeyStream = new FileInputStream(privateKeyFile);
        
         String signedPGPMessage = 
              pgp.signString(message,
                                keyStore,
                                signKeyUserId,
                                "key password",
                                signKeyPassword,
                                charsetCode);
        } finally {
              if (privateKeyStream != null)
                privateKeyStream.close();
        }      
    }
 }         
 

Parameters:
stringToEncrypt - String message to be encrypted
keyStore - KeyStore containing the private key to be used for signing
privateKeyUserId - signing key User Id or hexadecimal Key ID
privateKeyPassword - the password of the private key
charsetName - the name of a supported charset
Returns:
signed string message
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPrivateKeyFoundException - if the private key source does not contain a public key or is corrupted
WrongPrivateKeyException - if the provided password for the private key is wrong
Since:
3.1.0

signString

public java.lang.String signString(java.lang.String message,
                                   KeyStore keyStore,
                                   long privateKeyId,
                                   java.lang.String privateKeyPassword,
                                   java.lang.String charsetName)
                            throws PGPException,
                                   java.io.IOException
OpenPGP signs a String message

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class SignStringDemo {
     public static void main(String[] args) throws Exception {
         String message = "the quick brown fox jumps"; 
     
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         KeyStore keyStore = new KeyStore("pgp.keystore", "changeit");
         
         // The signing key is usually our private key
         long signKeyId = keyStore.getKeyIdForUserId("demo@didisoft.com");;
         String signKeyPassword = "changeit";        
         String charsetCode = "UTF-8";
         
         InputStream privateKeyStream = null;
         try {
                privateKeyStream = new FileInputStream(privateKeyFile);
        
         String signedPGPMessage = 
              pgp.signString(message,
                                keyStore,
                                signKeyId,
                                "key password",
                                signKeyPassword,
                                charsetCode);
        } finally {
              if (privateKeyStream != null)
                privateKeyStream.close();
        }      
    }
 }         
 

Parameters:
stringToEncrypt - String message to be encrypted
keyStore - KeyStore containing the private key to be used for signing
privateKeyUserId - signing key Id
privateKeyPassword - the password of the private key
charsetName - the name of a supported charset
Returns:
signed string message
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error
NoPrivateKeyFoundException - if the private key source does not contain a public key or is corrupted
WrongPrivateKeyException - if the provided password for the private key is wrong
Since:
3.1.0

encryptStream

public void encryptStream(java.io.InputStream dataStream,
                          java.lang.String fileName,
                          java.io.InputStream[] publicKeyStreams,
                          java.io.OutputStream outputStream,
                          boolean asciiArmor,
                          boolean withIntegrityCheck)
                   throws PGPException,
                          java.io.IOException
OpenPGP encrypts an input stream using the first available Public key from a Key ring input stream

Compression algorithm used is the one specified with #setCompression(CompressionAlgorithm) if supported by the public key, otherwise the first supported by the key algorithm is used.
Symmetric cipher algorithm used is the one specified with #setCypher(CypherAlgorithm) if supported by the public key, otherwise the first supported by the key algorithm is used.

Parameters:
dataStream - Input Stream to be encrypted
fileName - File Name string to be stored in the OpenPGP file (OpenPGP archive stores information for the file name being encrypted)
publicKeyStream - Input stream from the Public key
outputStream - Output OpenPGP encrypted stream
asciiArmor - If true, output is in ASCII armored mode, when false in binary. For large files it is recommended to be false (binary format)
withIntegrityCheck - Should integrity check be added to the file.
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptStream

public void encryptStream(java.io.InputStream dataStream,
                          java.lang.String fileName,
                          long streamLength,
                          java.lang.String publicKeyFileName,
                          java.io.OutputStream out,
                          boolean asciiArmor)
                   throws PGPException,
                          java.io.IOException
OpenPGP encrypts stream using the first available public key from a key ring file.

Compression algorithm used is the one specified with setCompression(String) if supported by the public key, otherwise the first supported by the key algorithm is used.
Symmetric cipher algorithm used is the one specified with setCypher(String) if supported by the public key, otherwise the first supported by the key algorithm is used.

Parameters:
dataStream - Input Stream to be encrypted
fileName - File Name string to be stored in the OpenPGP file (OpenPGP archive stores information for the file name being encrypted)
streamLength - Length of stream to be encrypted
publicKeyFileName - Key ring file name (absolute or relative path)
out - Output Stream OpenPGP encrypted
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
Since:
2.5.6
See Also:
decryptStream(InputStream, InputStream, String, OutputStream)

encryptStream

public void encryptStream(java.io.InputStream dataStream,
                          java.lang.String fileName,
                          long streamLength,
                          java.lang.String publicKeyFileName,
                          java.io.OutputStream out,
                          boolean asciiArmor,
                          boolean withIntegrityCheck)
                   throws PGPException,
                          java.io.IOException
OpenPGP encrypts stream using the first available public key from a key ring file.

Compression algorithm used is the one specified with setCompression(String) if supported by the public key, otherwise the first supported by the key algorithm is used.
Symmetric cipher algorithm used is the one specified with setCypher(String) if supported by the public key, otherwise the first supported by the key algorithm is used.

Parameters:
dataStream - Input Stream to be encrypted
fileName - File Name string to be stored in the OpenPGP file (OpenPGP archive stores information for the file name being encrypted)
streamLength - Length of stream to be encrypted
publicKeyFileName - Key ring file name (absolute or relative path)
out - Output Stream OpenPGP encrypted
asciiArmor - if true output is in ASCII armored format, when false output is in binary format
withIntegrityCheck - Should integrity check be added to the file.
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptStream(InputStream, InputStream, String, OutputStream)

encryptStream

public void encryptStream(java.io.InputStream dataStream,
                          java.lang.String fileName,
                          KeyStore keyStore,
                          java.lang.String userId,
                          java.io.OutputStream out,
                          boolean asciiArmor,
                          boolean withIntegrityCheck)
                   throws PGPException,
                          java.io.IOException
OpenPGP Encrypts Input Stream using a Public key located in a KeyStore

Compression algorithm used is the one specified with setCompression(String) if supported by the public key, otherwise the first supported by the key algorithm is used.
Symmetric cipher algorithm used is the one specified with setCypher(String) if supported by the public key, otherwise the first supported by the key algorithm is used.

Parameters:
dataStream - Input Stream to be encrypted
fileName - File Name string to be stored in the OpenPGP file (OpenPGP archive stores information for the file name being encrypted)
keyStore - Key store object. See KeyStore
userId - User ID or hexadecimal Key ID of the encryption key
out - Output Stream OpenPGP encrypted
asciiArmor - if true output is in ASCII armored format, when false output is in binary format. For large files it is recommended to be false (binary format)
withIntegrityCheck - Should integrity check be added to the file.
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptStream(InputStream, KeyStore, String, OutputStream)

encryptStream

public void encryptStream(java.io.InputStream dataStream,
                          java.lang.String fileName,
                          KeyStore keyStore,
                          java.lang.String[] userIds,
                          java.io.OutputStream out,
                          boolean asciiArmor,
                          boolean withIntegrityCheck)
                   throws PGPException,
                          java.io.IOException
OpenPGP Encrypts Input Stream using a Public key located in a KeyStore

Compression algorithm used is the one specified with #setCompression(CompressionAlgorithm) if supported by the public key, otherwise the first supported by the key algorithm is used.
Symmetric cipher algorithm used is the one specified with #setCypher(CypherAlgorithm) if supported by the public key, otherwise the first supported by the key algorithm is used.

Parameters:
dataStream - Input Stream to be encrypted
fileName - File Name string to be stored in the OpenPGP file (OpenPGP archive stores information for the file name being encrypted)
keyStore - Key store object. See KeyStore
userIds - List of User IDs of the form "name (comment) <email address>" (can be seen using KeyStore.listKeys())
out - Output Stream OpenPGP encrypted
asciiArmor - if true output is in ASCII armored format, when false output is in binary format. For large files it is recommended to be false (binary format)
withIntegrityCheck - Should integrity check be added to the file.
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptStream(InputStream, KeyStore, String, OutputStream)

encryptStream

public void encryptStream(java.io.InputStream dataStream,
                          java.lang.String fileName,
                          KeyStore keyStore,
                          long[] keyIds,
                          java.io.OutputStream out,
                          boolean asciiArmor,
                          boolean withIntegrityCheck)
                   throws PGPException,
                          java.io.IOException
OpenPGP encrypts input stream using recipients' public keys located in a KeyStore

Compression algorithm used is the one specified with #setCompression(CompressionAlgorithm) if supported by the public key, otherwise the first supported by the key algorithm is used.
Symmetric cipher algorithm used is the one specified with #setCypher(CypherAlgorithm) if supported by the public key, otherwise the first supported by the key algorithm is used.

Parameters:
dataStream - Input Stream to be encrypted
fileName - File Name string to be stored in the OpenPGP file (OpenPGP archive stores information for the file name being encrypted)
keyStore - Key store object. See KeyStore
keyId - Array of Key Id's of the Public keys used for encryption
out - Output Stream OpenPGP encrypted
asciiArmor - Should file be in Armored mode
withIntegrityCheck - Should integrity check be added to the file.
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptStream

public void encryptStream(java.io.InputStream dataStream,
                          java.lang.String fileName,
                          KeyStore keyStore,
                          long keyId,
                          java.io.OutputStream out,
                          boolean asciiArmor,
                          boolean withIntegrityCheck)
                   throws PGPException,
                          java.io.IOException
OpenPGP encrypts input stream using a recipient public key located in a KeyStore

Compression algorithm used is the one specified with setCompression(String) if supported by the public key, otherwise the first supported by the key algorithm is used.
Symmetric cipher algorithm used is the one specified with setCypher(String) if supported by the public key, otherwise the first supported by the key algorithm is used.

Parameters:
dataStream - Input Stream to be encrypted
fileName - File Name string to be stored in the OpenPGP file (OpenPGP archive stores information for the file name being encrypted)
keyStore - Key store object. See KeyStore
keyId - Key Id of the Public Key
out - Output Stream OpenPGP encrypted
asciiArmor - Should file be in Armored mode
withIntegrityCheck - Should integrity check be added to the file.
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptStream

public void encryptStream(java.io.InputStream dataStream,
                          java.lang.String fileName,
                          long streamLength,
                          java.io.InputStream publicKeyStream,
                          java.io.OutputStream out,
                          boolean asciiArmor,
                          boolean withIntegrityCheck)
                   throws PGPException,
                          java.io.IOException
OpenPGP encrypts an input stream using the first available public key supplied as an input stream

Compression algorithm used is the one specified with setCompression(String) if supported by the public key, otherwise the first supported by the key algorithm is used.
Symmetric cipher algorithm used is the one specified with setCypher(String) if supported by the public key, otherwise the first supported by the key algorithm is used.

Parameters:
dataStream - Input Stream to be encrypted
fileName - File Name string to be stored in the OpenPGP file (OpenPGP archive stores information for the file name being encrypted)
streamLength - Length of stream to be encrypted
publicKeyStream - Input stream from the Public key
out - Output Stream OpenPGP encrypted
asciiArmor - Should file be in Armored mode
withIntegrityCheck - Should integrity check be added to the file.
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptStream

public void encryptStream(java.io.InputStream dataStream,
                          java.lang.String fileName,
                          java.io.InputStream publicKeyStream,
                          java.io.OutputStream outputStream,
                          boolean asciiArmor,
                          boolean withIntegrityCheck)
                   throws PGPException,
                          java.io.IOException
OpenPGP encrypts an input stream using the first available Public key from a Key ring input stream

Compression algorithm used is the one specified with setCompression(String) if supported by the public key, otherwise the first supported by the key algorithm is used.
Symmetric cipher algorithm used is the one specified with setCypher(String) if supported by the public key, otherwise the first supported by the key algorithm is used.

Parameters:
dataStream - Input Stream to be encrypted
fileName - File Name string to be stored in the OpenPGP file (OpenPGP archive stores information for the file name being encrypted)
publicKeyStream - Input stream from the Public key
outputStream - Output OpenPGP encrypted stream
asciiArmor - If true, output is in ASCII armored mode, when false in binary. For large files it is recommended to be false (binary format)
withIntegrityCheck - Should integrity check be added to the file.
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptStream

public void encryptStream(java.io.InputStream dataStream,
                          java.lang.String fileName,
                          PGPKeyPair publicKey,
                          java.io.OutputStream outputStream,
                          boolean asciiArmor,
                          boolean withIntegrityCheck)
                   throws PGPException,
                          java.io.IOException
OpenPGP encrypts an input stream using the first available Public key from a Key ring input stream

Compression algorithm used is the one specified with setCompression(String) if supported by the public key, otherwise the first supported by the key algorithm is used.
Symmetric cipher algorithm used is the one specified with setCypher(String) if supported by the public key, otherwise the first supported by the key algorithm is used.

Parameters:
dataStream - Input Stream to be encrypted
fileName - File Name string to be stored in the OpenPGP file (OpenPGP archive stores information for the file name being encrypted)
publicKeyStream - Input stream from the Public key
outputStream - Output OpenPGP encrypted stream
asciiArmor - If true, output is in ASCII armored mode, when false in binary. For large files it is recommended to be false (binary format)
withIntegrityCheck - Should integrity check be added to the file.
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptStringPBE

public java.lang.String encryptStringPBE(java.lang.String stringToEncrypt,
                                         java.lang.String encryptionPassword)
                                  throws PGPException,
                                         java.io.IOException
OpenPGP encrypts a UTF-8 String message with a password
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class EncryptStringPBEDemo {
     public static void main(String[] args) throws Exception {
         String stringToEncrypt = "the quick brown fox jumps"; 
     
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         String encryptionPassword = "my password";        
         
         // sign and encrypt
         String encryptedString = 
              pgp.encryptStringPBE(stringToEncrypt,
                                encryptionPassword);
     }
 }         
 

Parameters:
stringToEncrypt - String message to be encrypted
encryptionPassword - Password that will be used for symmetric OpenPGP encryption of the message
Returns:
encrypted string message
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error

encryptStringPBE

public java.lang.String encryptStringPBE(java.lang.String stringToEncrypt,
                                         java.lang.String encryptionPassword,
                                         java.lang.String charsetName)
                                  throws PGPException,
                                         java.io.IOException
OpenPGP encrypts a String message with a password
Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:
 import com.didisoft.pgp.PGPLib;
 
 public class EncryptStringPBEDemo {
     public static void main(String[] args) throws Exception {
         String stringToEncrypt = "the quick brown fox jumps"; 
     
         // create an instance of the library
         PGPLib pgp = new PGPLib();
              
         String encryptionPassword = "my password";        
         String charsetCode = "UTF-8";
         
         // sign and encrypt
         String encryptedString = 
              pgp.encryptStringPBE(stringToEncrypt,
                                encryptionPassword,
                                charsetCode);
     }
 }         
 

Parameters:
stringToEncrypt - String message to be encrypted
encryptionPassword - Password that will be used for symmetric OpenPGP encryption of the message
charsetName - the name of a supported charset
Returns:
encrypted string message
Throws:
java.io.IOException - In case of an I/O error
PGPException - general OpenPGP error

encryptStreamPBE

public void encryptStreamPBE(java.io.InputStream dataStream,
                             java.lang.String fileNameLabel,
                             java.lang.String password,
                             java.io.OutputStream out,
                             boolean asciiArmor,
                             boolean withIntegrityCheck)
                      throws PGPException,
                             java.io.IOException
Encrypts an input stream with a password based OpenPGP encryption (PBE)

Compression algorithm used is the one specified with setCompression(String) if supported by the public key, otherwise the first supported by the key algorithm is used.
Symmetric cipher algorithm used is the one specified with setCypher(String) if supported by the public key, otherwise the first supported by the key algorithm is used.

The example below illustrates the usage of this method:
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.io.OutputStream;
 import com.didisoft.pgp.PGPLib;
 
 public class EncryptStreamPBE {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
 
         // is output ASCII or binary
         boolean asciiArmor = true;
         // should integrity check information be added
         // set to false for compatibility with older versions of PGP such as 6.5.8.
         boolean withIntegrityCheck = true;
 
         // obtain the streams
         InputStream inStream = new FileInputStream("DataFiles/INPUT.txt");
         OutputStream outStream = new FileOutputStream("DataFiles/PBEencrypted.pgp");
 
         // Here "INPUT.txt" is just a label to be associated with the data OpenPGP packet
         // The data packet is a mandatory component of the pgp file internals and holds:
         // file name label, timestamp, and the encrypted data
         pgp.encryptStreamPBE(inStream, "INPUT.txt", "encryption password", outStream, asciiArmor, withIntegrityCheck);
     }
 }
 

Parameters:
dataStream - Input Stream to be encrypted
fileNameLabel - File Name label to be stored in the OpenPGP file (OpenPGP archive stores information for the file name being encrypted)
out - Output stream where the encrypted content will be stored
asciiArmor - If true, output is in ASCII armored mode, when false in binary. For large files it is recommended to be false (binary format)
withIntegrityCheck - Should integrity check be added to the file.
Throws:
PGPException - PGP encryption error
java.io.IOException - if an error occurs reading dataStream

encryptFilePBE

public void encryptFilePBE(java.lang.String dataFileName,
                           java.lang.String publicKeyFileName,
                           java.lang.String alternativePassword,
                           java.lang.String outputFileName,
                           boolean asciiArmor,
                           boolean withIntegrityCheck)
                    throws PGPException,
                           java.io.IOException
Encrypts a file with a public key and a passphrase.
The passphrase can be used to decrypt the file if the corresponding private key is lost.

Equivalent GnuPG command:
gpg -r [public key user id] -c -e [dataFileName]

Compression algorithm used is the one specified with setCompression(String) if supported by the public key, otherwise the first supported by the key algorithm is used.
Symmetric cipher algorithm used is the one specified with setCypher(String) if supported by the public key, otherwise the first supported by the key algorithm is used.

Parameters:
dataFileName - File name to be encrypted (absolute or relative path)
publicKeyFileName - Public key file name (absolute or relative path) or the public key as ASCII armoured string
alternativePassword - Additional passphrase that can be used to decrypt the file instead of using the private key
outputFileName - File name of the Output encrypted file (absolute or relative path)
asciiArmor - If true, output is in ASCII armored mode, when false in binary. For large files it is recommended to be false (binary format)
withIntegrityCheck - Should integrity check be added to the file.
Throws:
PGPException - OpenPGP encryption error
java.io.IOException - in case of an I/O error
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptFilePBE

public void encryptFilePBE(java.lang.String dataFileName,
                           java.lang.String password,
                           java.lang.String outputFileName,
                           boolean asciiArmor,
                           boolean withIntegrityCheck)
                    throws PGPException,
                           java.io.IOException
Encrypts a file with a passphrase.
The same passphrase is used to decrypt the file

Equivalent GnuPG command:
gpg -c -e [dataFileName]

Compression algorithm used is the one specified with setCompression(String) if supported by the public key, otherwise the first supported by the key algorithm is used.
Symmetric cipher algorithm used is the one specified with setCypher(String) if supported by the public key, otherwise the first supported by the key algorithm is used.

The example below illustrates how the usage of this method:
 import com.didisoft.pgp.*;
 
 public class EncryptFilePBE {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
        
         // if true the output file will be in ASCII armored format,
         // otherwise will be in binary format
         boolean asciiArmor = true;
         // if true additional integrity check information is added
         // set to false for compatibility with older versions of PGP such as 6.5.8.
         boolean withIntegrityCheck = false;
                
         pgp.encryptFilePBE("INPUT.txt",
                         "password",
                         "PBEencrypted.pgp",
                         asciiArmor,
                         withIntegrityCheck);
     }
 }
 

Parameters:
dataFileName - File name to be encrypted (absolute or relative path)
password - Passphrase used to encrypt and decrypt the file
outputFileName - File name of the Output encrypted file (absolute or relative path)
asciiArmor - If true, output is in ASCII armored mode, when false in binary. For large files it is recommended to be false (binary format)
withIntegrityCheck - Should integrity check be added to the file.
Throws:
PGPException - OpenPGP encryption error
java.io.IOException - in case of an I/O error

encryptFile

public void encryptFile(java.lang.String dataFileName,
                        java.lang.String publicKeyFileName,
                        java.lang.String outputFileName,
                        boolean asciiArmor)
                 throws PGPException,
                        java.io.IOException
OpenPGP encrypts given file using the public key of the recipient.

Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example usage:

 import com.didisoft.pgp.*;
 
 public class EncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         // if true the output file will be in ASCII armored format, 
         // otherwise in binary format
         boolean asciiArmor = true;
                 
         pgp.encryptFile("INPUT.txt", 
                         "recipient_key.asc", 
                         "encrypted.pgp", 
                         asciiArmor);
     }
 }
 

Parameters:
dataFileName - File name to be encrypted (absolute or relative path)
publicKeyFileName - Recipient public key file name (absolute or relative path) or the public key as ASCII armoured string
outputFileName - File name of the output encrypted file (absolute or relative path)
asciiArmor - if true output is in ASCII armored format, otherwise is in binary format. For large files it is recommended to be false (binary format)
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
Since:
2.5.6

encryptFile

public void encryptFile(java.lang.String dataFileName,
                        java.lang.String publicKeyFileName,
                        java.lang.String outputFileName,
                        boolean asciiArmor,
                        boolean withIntegrityCheck)
                 throws PGPException,
                        java.io.IOException
OpenPGP encrypts given file using the public key of the recipient.

Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example usage:

 import com.didisoft.pgp.*;
 
 public class EncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         // if true the output file will be in ASCII armored format, 
         // otherwise will be in binary format
         boolean asciiArmor = true;
         // if true additional integrity check information is added
         // set to false for compatibility with older versions of PGP such as 6.5.8.
         boolean withIntegrityCheck = true;
                 
         pgp.encryptFile("INPUT.txt", 
                         "recipient_key.asc", 
                         "encrypted.pgp", 
                         asciiArmor, 
                         withIntegrityCheck);
     }
 }
 

Parameters:
dataFileName - File name to be encrypted (absolute or relative path)
publicKeyFileName - Recipient public key file name (absolute or relative path) or the public key as ASCII armoured string
outputFileName - File name of the output encrypted file (absolute or relative path)
asciiArmor - if true output is in ASCII armored format, otherwise is in binary format. For large files it is recommended to be false (binary format)
withIntegrityCheck - if true additional integrity check is added to the file. Set to false for compatibility with older versions of PGP such as 6.5.8.
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptFile

public void encryptFile(java.lang.String dataFileName,
                        java.lang.String[] publicKeysFileNames,
                        java.lang.String outputFileName,
                        boolean asciiArmor,
                        boolean withIntegrityCheck)
                 throws PGPException,
                        java.io.IOException
OpenPGP encrypts a file for multiple recipients.


Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example usage:

 import com.didisoft.pgp.*;
 
 public class EncryptFileForMultipleRecipients {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         // if true the output file will be in ASCII armored format, 
         // otherwise will be in binary format
         boolean asciiArmor = true;
         // if true additional integrity check information is added
         // set to false for compatibility with older versions of PGP such as 6.5.8.
         boolean withIntegrityCheck = true;

         String[] recipientsPublicKeys = {"public_key1.asc", 
                                       "public_key2.asc",
                                       "public_key3.asc"};        
                 
         pgp.encryptFile("INPUT.txt", 
                         recipientsPublicKeys, 
                         "encrypted.pgp", 
                         asciiArmor, 
                         withIntegrityCheck);
     }
 }
 

Parameters:
dataFileName - File name to be encrypted (absolute or relative path)
publicKeysFileNames - Array of recipients' public keys file names (absolute or relative paths) or the public keys as ASCII armoured strings
outputFileName - File name of the output encrypted file (absolute or relative path)
asciiArmor - if true output is in ASCII armored format, otherwise is in binary format.
withIntegrityCheck - if true additional integrity check is added to the file.
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptFile

public void encryptFile(java.lang.String dataFileName,
                        KeyStore keyStore,
                        java.lang.String[] recipientsUserIds,
                        java.lang.String outputFileName,
                        boolean asciiArmor,
                        boolean withIntegrityCheck)
                 throws PGPException,
                        java.io.IOException
OpenPGP encrypts a file for multiple recipients.


Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:

 import com.didisoft.pgp.*;
 
 public class EncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         // if true the output file will be in ASCII armored format, 
         // otherwise will be in binary format
         boolean asciiArmor = true;
         // if true additional integrity check information is added
         // set to false for compatibility with older versions of PGP such as 6.5.8.
         boolean withIntegrityCheck = true;

         // initialize the KeyStore  
         KeyStore keyStore = new KeyStore("mykeys.keystore", "password");  

         String[] recipientsUserIds = {"recipient1@company.com", 
                                       "John Doe",
                                       "Clearing House"};        
                 
         pgp.encryptFile("INPUT.txt", 
                         keyStore,
                         recipientsUserIds, 
                         "encrypted.pgp", 
                         asciiArmor, 
                         withIntegrityCheck);
     }
 }
 

Parameters:
dataFileName - File name to be encrypted (absolute or relative path)
keyStore - KeyStore holding recipients' public keys
recipientsUserIds - Array of recipients' public keys User Id's or hexadecimal Key ID's
outputFileName - File name of the output encrypted file (absolute or relative path)
asciiArmor - if true output is in ASCII armored format, otherwise is in binary format.
withIntegrityCheck - if true additional integrity check is added to the file.
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptFile

public void encryptFile(java.lang.String dataFileName,
                        KeyStore keyStore,
                        long[] recipientsKeyIds,
                        java.lang.String outputFileName,
                        boolean asciiArmor,
                        boolean withIntegrityCheck)
                 throws PGPException,
                        java.io.IOException
OpenPGP encrypts a file for multiple recipients.


Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:
 import com.didisoft.pgp.*;
 
 public class EncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         // if true the output file will be in ASCII armored format, 
         // otherwise will be in binary format
         boolean asciiArmor = true;
         // if true additional integrity check information is added
         // set to false for compatibility with older versions of PGP such as 6.5.8.
         boolean withIntegrityCheck = true;

         KeyStore keyStore = new KeyStore("mykeys.keystore", "password");  

         long[] recipientsKeyIds = {15432123891819, 
                                    keyStore.getKeyIdForUserId("Company ACM"),
                                    keyStore.getKeyIdForKeyIdHex("79AEAE03")};        
                 
         pgp.encryptFile("INPUT.txt", 
                         keyStore,
                         recipientsKeyIds, 
                         "encrypted.pgp", 
                         asciiArmor, 
                         withIntegrityCheck);
     }
 }
 

Parameters:
dataFileName - File name to be encrypted (absolute or relative path)
keyStore - KeyStore holding recipients' public keys
recipientsKeyIds - Array of recipients' public keys Key Id's
outputFileName - File name of the output encrypted file (absolute or relative path)
asciiArmor - if true output is in ASCII armored format, otherwise is in binary format.
withIntegrityCheck - if true additional integrity check is added to the file.
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptFiles

public void encryptFiles(java.lang.String[] dataFileNames,
                         java.lang.String publicKeyFileName,
                         java.lang.String outputFileName,
                         boolean asciiArmor,
                         boolean withIntegrityCheck)
                  throws PGPException,
                         java.io.IOException
OpenPGP encrypts multiple files into one OpenPGP archive.

Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example usage:

 import com.didisoft.pgp.*;
 
 public class EncryptFilesDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         // if true the output file will be in ASCII armored format, 
         // otherwise will be in binary format
         boolean asciiArmor = true;
         // if true additional integrity check information is added
         // set to false for compatibility with older versions of PGP such as 6.5.8.
         boolean withIntegrityCheck = true;

         String[] inputFiles = {"INPUT1.txt", 
                                "INPUT2.txt",
                                "INPUT3.txt"};        

         String recipientPublicKey = "public_key1.asc";        
                 
         pgp.encryptFiles(inputFiles, 
                         recipientPublicKey, 
                         "encrypted.pgp", 
                         asciiArmor, 
                         withIntegrityCheck);
     }
 }
 

Parameters:
dataFileNames - File names to be encrypted (absolute or relative path)
publicKeyFileName - Recipients public key file name (absolute or relative path) or the public key as ASCII armoured string
outputFileName - File name of the output encrypted file (absolute or relative path)
asciiArmor - if true output is in ASCII armored format, otherwise is in binary format.
withIntegrityCheck - if true additional integrity check is added to the file.
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptFiles

public void encryptFiles(java.lang.String[] dataFileNames,
                         java.lang.String[] publicKeysFileNames,
                         java.lang.String outputFileName,
                         boolean asciiArmor,
                         boolean withIntegrityCheck)
                  throws PGPException,
                         java.io.IOException
OpenPGP encrypts multiple files into one OpenPGP archive.

Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example usage:

 import com.didisoft.pgp.*;
 
 public class EncryptFilesDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         // if true the output file will be in ASCII armored format, 
         // otherwise will be in binary format
         boolean asciiArmor = true;
         // if true additional integrity check information is added
         // set to false for compatibility with older versions of PGP such as 6.5.8.
         boolean withIntegrityCheck = true;

         String[] inputFiles = {"INPUT1.txt", 
                                "INPUT2.txt",
                                "INPUT3.txt"};        

         String[] recipientsPublicKeys = {"public_key1.asc", 
                                       "public_key2.asc",
                                       "public_key3.asc"};        
                 
                 
         pgp.encryptFiles(inputFiles, 
                         recipientsPublicKeys, 
                         "encrypted.pgp", 
                         asciiArmor, 
                         withIntegrityCheck);
     }
 }
 

Parameters:
dataFileNames - File names to be encrypted (absolute or relative path)
publicKeysFileNames - Array of recipients' public keys file names (absolute or relative path) or the public keys as ASCII armoured strings
outputFileName - File name of the output encrypted file (absolute or relative path)
asciiArmor - if true output is in ASCII armored format, otherwise is in binary format.
withIntegrityCheck - if true additional integrity check is added to the file.
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptFiles

public void encryptFiles(java.lang.String[] dataFileNames,
                         KeyStore keyStore,
                         java.lang.String[] recipientsUserIds,
                         java.lang.String outputFileName,
                         boolean asciiArmor,
                         boolean withIntegrityCheck)
                  throws PGPException,
                         java.io.IOException
OpenPGP encrypts multiple files into one OpenPGP archive

Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:

 import com.didisoft.pgp.*;
 
 public class EncryptFilesDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         // if true the output file will be in ASCII armored format, 
         // otherwise will be in binary format
         boolean asciiArmor = true;
         // if true additional integrity check information is added
         boolean withIntegrityCheck = true;

         String[] inputFiles = {"INPUT1.txt", 
                                "INPUT2.txt",
                                "INPUT3.txt"};        

         KeyStore keyStore = new KeyStore("mykeys.keystore", "password");  

         String[] recipientsUserIds = {"recipient1@company.com", 
                                       "John Doe",
                                       "Clearing House"};        
                 
         pgp.encryptFiles(inputFiles, 
                         keyStore,  
                         recipientsUserIds, 
                         "encrypted.pgp", 
                         asciiArmor, 
                         withIntegrityCheck);
     }
 }
 

Parameters:
dataFileNames - File names to be encrypted (absolute or relative path)
keyStore - KeyStore containing the recipients public keys
recipientsUserIds - Array of recipients' public keys User Id's or hexadecimal Key ID
outputFileName - File name of the output encrypted file (absolute or relative path)
asciiArmor - if true output is in ASCII armored format, otherwise is in binary format.
withIntegrityCheck - if true additional integrity check is added to the file.
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptFiles

public void encryptFiles(java.lang.String[] dataFileNames,
                         KeyStore keyStore,
                         long[] recipientsKeyIds,
                         java.lang.String outputFileName,
                         boolean asciiArmor,
                         boolean withIntegrityCheck)
                  throws PGPException,
                         java.io.IOException
OpenPGP encrypts multiple files into one OpenPGP archive

Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example usage:

 import com.didisoft.pgp.*;
 
 public class EncryptFilesDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         // if true the output file will be in ASCII armored format, 
         // otherwise will be in binary format
         boolean asciiArmor = true;
         // if true additional integrity check information is added
         boolean withIntegrityCheck = true;

         String[] inputFiles = {"INPUT1.txt", 
                                "INPUT2.txt",
                                "INPUT3.txt"};        

         KeyStore keyStore = new KeyStore("mykeys.keystore", "password");  

         long[] recipientsKeyIds = {15432123891819, 
                                    keyStore.getKeyIdForUserId("Company ACM"),
                                    keyStore.getKeyIdForKeyIdHex("79AEAE03")};        
                 
         pgp.encryptFiles(inputFiles, 
                         keyStore,  
                         recipientsUserIds, 
                         "encrypted.pgp", 
                         asciiArmor, 
                         withIntegrityCheck);
     }
 }
 

Parameters:
dataFileNames - File names to be encrypted (absolute or relative path)
keyStore - KeyStore containing the recipients public keys
recipientsKeyIds - Array of recipients' public keys Key Id's
outputFileName - File name of the output encrypted file (absolute or relative path)
asciiArmor - if true output is in ASCII armored format, otherwise is in binary format.
withIntegrityCheck - if true additional integrity check is added to the file.
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptFile

public void encryptFile(java.lang.String dataFileName,
                        java.io.InputStream publicKeyStream,
                        java.lang.String outputFileName,
                        boolean asciiArmor,
                        boolean withIntegrityCheck)
                 throws PGPException,
                        java.io.IOException
OpenPGP encrypts given file using the first available public key from a key ring input stream

Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:

 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class EncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         // if true the output file will be in ASCII armored format, 
         // otherwise will be in binary format
         boolean asciiArmor = true;
         // if true additional integrity check information is added
         boolean withIntegrityCheck = true;
         
         FileInputStream keyStream = null;
         try {        
           keyStream = new FileInputStream("recipient_key.asc");        
           pgp.encryptFile("INPUT.txt", 
                         keyStream, 
                         "encrypted.pgp", 
                         asciiArmor, 
                         withIntegrityCheck);
        } finally {
           if (keyStream != null)
               keyStream.close();
        }                 
     }
 }
 

Parameters:
dataFileName - File name to be encrypted (absolute or relative path)
publicKeyStream - Input stream from the Public key, caller method is responsible for closing it
outputFileName - File name of the Output encrypted file (absolute or relative path)
asciiArmor - if true output is in ASCII armored format, otherwise is in binary format. For large files it is recommended to be false (binary format)
withIntegrityCheck - if true integrity check information is added to the file.
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException

encryptFileByUserId

public int encryptFileByUserId(KeyStore keyStore,
                               java.lang.String dataFileName,
                               java.lang.String userID,
                               java.lang.String outputFileName)
Deprecated. Use instead

OpenPGP encrypts given file using specified public key, stored in specified OpenPGP key store.

Parameters:
dataFileName - File name to be encrypted (absolute or relative path)
keyStore - Key store object. See KeyStore
userID - User ID or hexadecimal Key ID of the encryption key
outputFileName - File name of the Output encrypted file (absolute or relative path)
Returns:
0 if successfully encrypted, 1 if an error has occurred

encryptFile

public void encryptFile(java.lang.String dataFileName,
                        KeyStore keyStore,
                        java.lang.String userId,
                        java.lang.String outputFileName,
                        boolean asciiArmor,
                        boolean withIntegrityCheck)
                 throws PGPException,
                        java.io.IOException
OpenPGP encrypts given file using specified public key, stored in specified OpenPGP key store.

Compression algorithm used is the one specified with setCompression(String) if supported by the public key, otherwise the first supported by the key algorithm is used.
Symmetric cipher algorithm used is the one specified with setCypher(String) if supported by the public key, otherwise the first supported by the key algorithm is used.

Example:
 import com.didisoft.pgp.*;
 
 public class EncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         // if true the output file will be in ASCII armored format, 
         // otherwise will be in binary format
         boolean asciiArmor = true;
         // if true additional integrity check information is added
         boolean withIntegrityCheck = true;

         KeyStore keyStore = new KeyStore("mykeys.keystore", "password");  

         String recipientUserId = "recipient@company.com"; 
                 
         pgp.encryptFile("INPUT.txt", 
                         keyStore,
                         recipientUserId, 
                         "encrypted.pgp", 
                         asciiArmor, 
                         withIntegrityCheck);
     }
 }
 

Parameters:
dataFileName - File name to be encrypted (absolute or relative path)
keyStore - Key store object. See KeyStore
userId - Recipient public key User Id or hexadecimal Key ID
outputFileName - File name of the Output encrypted file (absolute or relative path)
asciiArmor - if true the output file will be in ASCII format, if false the output file will be in binary format
withIntegrityCheck - if true integrity check information is added to the file.
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptFile(String, KeyStore, String, String)

encryptFile

public void encryptFile(java.lang.String dataFileName,
                        KeyStore keyStore,
                        java.lang.String userId,
                        java.lang.String outputFileName)
                 throws PGPException,
                        java.io.IOException
OpenPGP encrypts given file using specified public key, stored in specified OpenPGP key store.

Compression algorithm used is the one specified with setCompression(String) if supported by the public key, otherwise the first supported by the key algorithm is used.
Symmetric cipher algorithm used is the one specified with setCypher(String) if supported by the public key, otherwise the first supported by the key algorithm is used.
The output file is in binary format and with no integrity check information. This format is compatible with PGP 2.6.x.

Example:
 import com.didisoft.pgp.*;
 
 public class EncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         // initialize the KeyStore
         KeyStore keyStore = new KeyStore("mykeys.keystore", "password");  

         String recipientUserId = "recipient@company.com"; 
                 
         pgp.encryptFile("INPUT.txt", 
                         keyStore,
                         recipientUserId, 
                         "encrypted.pgp");
     }
 }
 

Parameters:
dataFileName - File name to be encrypted (absolute or relative path)
keyStore - Key store object. See KeyStore
userId - User ID or hexadecimal Key ID of the recipients key
outputFileName - File name of the Output encrypted file (absolute or relative path)
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptFile(String, KeyStore, String, String)

encryptFileByKeyId

public int encryptFileByKeyId(KeyStore keyStore,
                              java.lang.String dataFileName,
                              java.lang.String keyIdHex,
                              java.lang.String outputFileName)
Deprecated. Use instead

OpenPGP Encrypts given file using specified Public Key, stored in specified OpenPGP key store.

Parameters:
dataFileName - File name to be encrypted (absolute or relative path)
keyStore - Key store object. See KeyStore
keyIdHex - Key Id of the Public Key in Hex format
outputFileName - File name of the Output encrypted file (absolute or relative path)

encryptFile

public void encryptFile(java.lang.String dataFileName,
                        KeyStore keyStore,
                        long keyId,
                        java.lang.String outputFileName,
                        boolean asciiArmor,
                        boolean withIntegrityCheck)
                 throws PGPException,
                        java.io.IOException
OpenPGP encrypts given file using specified public key, stored in specified OpenPGP key store.

Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)

Example:
 import com.didisoft.pgp.*;
 
 public class EncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         // if true the output file will be in ASCII armored format, 
         // otherwise will be in binary format
         boolean asciiArmor = true;
         // if true additional integrity check information is added
         boolean withIntegrityCheck = true;

         // initialize the KeyStore  
         KeyStore keyStore = new KeyStore("mykeys.keystore", "password");  

         long recipientKeyId = keyStore.getKeyIdForKeyIdHex("79AEAE03");        
                 
         pgp.encryptFile("INPUT.txt", 
                         keyStore,
                         recipientKeyId, 
                         "encrypted.pgp", 
                         asciiArmor, 
                         withIntegrityCheck);
     }
 }
 

Parameters:
dataFileName - File name to be encrypted (absolute or relative path)
keyStore - Key store object. See KeyStore
keyId - Key Id of the recipient public key
outputFileName - File name of the encrypted output file (absolute or relative path)
asciiArmor - if true the output file will be in ASCII format, if false the output file will be in binary format
withIntegrityCheck - if true integrity check information is added to the file.
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptFile(String, KeyStore, String, String)

encryptFile

public void encryptFile(java.lang.String dataFileName,
                        KeyStore keyStore,
                        long keyId,
                        java.lang.String outputFileName)
                 throws PGPException,
                        java.io.IOException
OpenPGP encrypts given file using specified public key, stored in specified OpenPGP key store.

Compression algorithm used is the one specified with setCompression(String)
Symmetric cipher algorithm used is the one specified with setCypher(String)
The output file is in binary format and with no integrity check information. This format is compatible with PGP 2.6.x.

Example:
 import com.didisoft.pgp.*;
 
 public class EncryptFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         // initialize the KeyStore
         KeyStore keyStore = new KeyStore("mykeys.keystore", "password");  

         long recipientKeyId = keyStore.getKeyIdForKeyIdHex("79AEAE03");        
                 
         pgp.encryptFile("INPUT.txt", 
                         keyStore,
                         recipientKeyId, 
                         "encrypted.pgp");
     }
 }
 

Parameters:
dataFileName - File name to be encrypted (absolute or relative path)
keyStore - Key store object. See KeyStore
keyId - Key Id of the Public Key
outputFileName - File name of the Output encrypted file (absolute or relative path)
Throws:
java.io.IOException - in case of an I/O error
PGPException - OpenPGP encryption error
NoPublicKeyFoundException - if the public key source does not contain a public key or is corrupted
KeyIsExpiredException - If the public key is expired. Extends PGPException
KeyIsRevokedException - If the public key is revoked. Extends PGPException
See Also:
decryptFile(String, String, String, String)

verifyFile

public boolean verifyFile(java.lang.String dataFileName,
                          java.lang.String publicKeyFileName,
                          java.lang.String outputFileName)
                   throws PGPException,
                          FileIsEncryptedException,
                          java.io.IOException
Deprecated. Due to misleading return value. Please use {@link #verifyAndExtract(String, String, String) instead

Verifies the incoming file as being correctly signed.

Example:
 import com.didisoft.pgp.*;
 
 public class VerifyFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         // verify and extract the signed content
         boolean validSignature = pgp.verifyFile("signed.pgp", "sender_public_key.asc", "OUTPUT.txt");      
         if (validSignature) {
             System.out.println("Signature is valid.");
         } else {
             System.out.println("!Signature is invalid!");
         }
     }
 }
 

Parameters:
dataFileName - File name to be verified for a valid OpenPGP signature (absolute or relative path)
publicKeyFileName - Sender public key file name (absolute or relative path) or the key as ASCII armored string
outputFileName - Output file name, extracted from the signed file (absolute or relative path)
Returns:
true if the file is signed from the sender who owns the specified public key, false if not signed with this public key
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
See Also:
signFile(String, String, String, String, boolean), signFileVersion3(String, String, String, String, boolean)

verifyFile

public boolean verifyFile(java.lang.String dataFileName,
                          KeyStore keyStore,
                          java.lang.String outputFileName)
                   throws PGPException,
                          FileIsEncryptedException,
                          java.io.IOException
Deprecated. Due to misleading return value. Please use {@link #verifyAndExtract(String, KeyStore, String) instead

Verifies the incoming file as being correctly signed.

Example:
 import com.didisoft.pgp.*;
 
 public class VerifyFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         // initialize the KeyStore
         KeyStore keyStore = new KeyStore("mykeys.keystore", "password");
           
         // verify and extract the signed content
         boolean validSignature = pgp.verifyFile("signed.pgp", keyStore, "OUTPUT.txt");      
         if (validSignature) {
             System.out.println("Signature is valid.");
         } else {
             System.out.println("!Signature is invalid!");
         }
     }
 }
 

Parameters:
dataFileName - File name to be verified for a valid OpenPGP signature (absolute or relative path)
keyStore - KeyStore object containing the sender public key that will be used for verification
outputFileName - Output file name, extracted from the signed file (absolute or relative path)
Returns:
true if the file is signed from a sender with public key in this KeyStore, false if no key in the KeyStore matches the signature
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
See Also:
signFile(String, KeyStore, String, String, String, boolean)

verifyFile

public boolean verifyFile(java.lang.String dataFileName,
                          java.lang.String publicKeyFileName)
                   throws PGPException,
                          FileIsEncryptedException,
                          java.io.IOException
Deprecated. Due to misleading return value. Please use verifyWithoutExtracting(String, String) instead

Verifies the incoming file as being correctly signed.

Example:
 import com.didisoft.pgp.*;
 
 public class VerifyFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         // initialize the KeyStore
         KeyStore keyStore = new KeyStore("mykeys.keystore", "password");
           
         // verify and extract the signed content
         boolean validSignature = pgp.verifyFile("signed.pgp", "sender_public_key.asc");      
         if (validSignature) {
             System.out.println("Signature is valid.");
         } else {
             System.out.println("!Signature is invalid!");
         }
     }
 }
 

Parameters:
dataFileName - File name to be verified for a valid OpenPGP signature (absolute or relative path)
publicKeyFileName - Sender public key file name (absolute or relative path) or the key as ASCII armored string
Returns:
true if signed correctly, false if not signed with this public key
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
See Also:
signFile(String, String, String, String, boolean)

verifyFile

public boolean verifyFile(java.io.InputStream dataFileStream,
                          java.io.InputStream publicKeyStream)
                   throws PGPException,
                          java.io.IOException
Deprecated. Use verifyStream(InputStream, InputStream)

Verifies the incoming in stream as being correctly signed.

Parameters:
dataFileStream - Input stream from the File to be verified
publicKeyStream - Input stream from the Public key
Returns:
true if signed correctly, false if not signed with this public key
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
See Also:
signStream(InputStream, String, InputStream, String, OutputStream, boolean)

verifyWithoutExtracting

public SignatureCheckResult verifyWithoutExtracting(java.io.InputStream dataFileStream,
                                                    java.io.InputStream publicKeyStream)
                                             throws PGPException,
                                                    FileIsEncryptedException,
                                                    java.io.IOException
Verifies an incoming stream as being correctly OpenPGP signed without extracting its data

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyWithoutExtractStreamDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         InputStream dataStream = new FileInputStream("signed.pgp");
         InputStream keyStream = new FileInputStream("sender_public_key.asc");
         
         try {
           // verify only the signed content
           SignatureCheckResult signatureCheck = pgp.verifyWithoutExtracting(dataStream, keyStream);      
                if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
                } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
                } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("Signature not matching provided public key /it is from another sender/");
                } else {
                  System.out.println("No signature found in message");
                }
         } finally {
           dataStream.close();
           keyStream.close();
         }
     }
 }
 

Parameters:
dataFileStream - Input stream from signed OpenPGP data to be verified
publicKeyStream - Input stream from the Public OpenPGP key
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
Since:
3.1.0
See Also:
signStream(InputStream, String, InputStream, String, OutputStream, boolean)

verifyWithoutExtracting

public SignatureCheckResult verifyWithoutExtracting(java.io.InputStream dataFileStream,
                                                    java.io.InputStream privateKeyStream,
                                                    java.lang.String privateKeyPassword,
                                                    java.io.InputStream publicKeyStream)
                                             throws PGPException,
                                                    FileIsEncryptedException,
                                                    java.io.IOException
Verifies the signature of an OpenPGP signed and encrypted file, without extracting its data

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyWithoutExtractStreamDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         InputStream dataStream = new FileInputStream("signed.pgp");
         InputStream senderPublicKeyStream = new FileInputStream("sender_public_key.asc");
         InputStream privateKeyStream = new FileInputStream("my_private_key.asc");
         String privateKeyPassword = "my key password";
         
         try {
           // verify only the signed content
           SignatureCheckResult signatureCheck = pgp.verifyWithoutExtracting(dataStream, privateKeyStream, privateKeyPassword, senderPublicKeyStream);      
                if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
                } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
                } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("Signature not matching provided public key /it is from another sender/");
                } else {
                  System.out.println("No signature found in message");
                }
         } finally {
           dataStream.close();
           keyStream.close();
         }
     }
 }
 

Parameters:
dataFileStream - Input stream from signed OpenPGP data to be verified
privateKeyStream - Input stream from the private OpenPGP key for decrypting the data
privateKeyPassword - Password for the private OpenPGP key for decrypting the data
publicKeyStream - Input stream from the Public OpenPGP key
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
WrongPasswordException - if the message is also encrypted and the supplied password for the private key doesn't match
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
FileIsEncryptedException
Since:
3.1.0
See Also:
signStream(InputStream, String, InputStream, String, OutputStream, boolean)

verifyWithoutExtracting

public SignatureCheckResult verifyWithoutExtracting(java.io.InputStream dataStream,
                                                    KeyStore keyStore,
                                                    java.lang.String privateKeyPassword)
                                             throws PGPException,
                                                    FileIsEncryptedException,
                                                    java.io.IOException
Verifies the signature of an OpenPGP signed and encrypted file, without extracting its data

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyAndExtractStreamDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         InputStream dataStream = new FileInputStream("signed.pgp");
         InputStream keyStream = new FileInputStream("sender_public_key.asc");
         
         try {
           // verify and extract the signed content
           SignatureCheckResult signatureCheck = pgp.verifyWithoutExtracting(dataStream, keyStream, "private key password");      
                if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
                } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
                } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("Signature not matching provided public key /it is from another sender/");
                } else {
                  System.out.println("No signature found in message");
                }
         } finally {
           dataStream.close();
           keyStream.close();
         }
     }
 }
 

Parameters:
dataStream - Input stream from signed OpenPGP data to be verified
keyStore - KeyStore containing the Public OpenPGP key that can verify the signature and the private key that can decrypt the message
privateKeyPassword - Password for the private key that can decrypt the message
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
WrongPasswordException - if the message is also encrypted and the supplied password for the private key doesn't match
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
FileIsEncryptedException
Since:
3.1.0
See Also:
signStream(InputStream, String, InputStream, String, OutputStream, boolean)

verifyWithoutExtracting

public SignatureCheckResult verifyWithoutExtracting(java.io.InputStream dataStream,
                                                    KeyStore keyStore)
                                             throws PGPException,
                                                    FileIsEncryptedException,
                                                    java.io.IOException
Verifies an incoming stream as being correctly OpenPGP signed without extracting its data

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyAndExtractStreamDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         InputStream dataStream = new FileInputStream("signed.pgp");
         InputStream keyStream = new FileInputStream("sender_public_key.asc");
         
         try {
           // verify and extract the signed content
           SignatureCheckResult signatureCheck = pgp.verifyWithoutExtracting(dataStream, keyStream);      
                if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
                } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
                } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("Signature not matching provided public key /it is from another sender/");
                } else {
                  System.out.println("No signature found in message");
                }
         } finally {
           dataStream.close();
           keyStream.close();
         }
     }
 }
 

Parameters:
dataStream - Input stream from signed OpenPGP data to be verified
keyStore - KeyStore containing the Public OpenPGP key that can verify the signature
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
Since:
3.1.0
See Also:
signStream(InputStream, String, InputStream, String, OutputStream, boolean)

verifyWithoutExtracting

public SignatureCheckResult verifyWithoutExtracting(java.lang.String message,
                                                    java.lang.String privateKeyFile,
                                                    java.lang.String privateKeyPassword,
                                                    java.lang.String publicKeyFile)
                                             throws java.io.IOException,
                                                    PGPException,
                                                    FileIsEncryptedException
Verifies the signature of an OpenPGP signed only message without extracting its data

This method can be used for both signed and clear text signed OpenPGP messages


Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyWithoutExtractStringDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = "..."; // Fill here the OpenPGP signed message

         // The public key of the sender, used to verify the message  
         String publicKeyFile = "c:\\public_key.asc";
         
         String privateKeyFile = "c:\\my_private_key.asc";
         String privateKeyPassword = "my key password";  
         
         // verify without extracting the data
         SignatureCheckResult signatureCheck = pgp.verifyWithoutExtracting(openpgpMessage, privateKeyFile, privateKeyPassword, publicKeyFile);      
         if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
         } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
         } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("Signature not matching provided public key /it is from another sender/");
         } else {
                  System.out.println("No signature found in message");
         }
         
         System.out.println("plain message: " + decryptedMessage.toString());
     }
 }
 

Parameters:
message - OpenPGP signed message or file location
privateKeyFile - The public key of the sender as ASCII armored string or as file location
privateKeyPassword - Password for the private key
publicKeyFile - The public key of the sender as ASCII armored string or as file location
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
WrongPasswordException - if the message is encrypted and the specified private key password doesn't match
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
FileIsEncryptedException
Since:
3.1.0
See Also:
#signString(String, String, String, String)}

verifyWithoutExtracting

public SignatureCheckResult verifyWithoutExtracting(java.lang.String message,
                                                    java.lang.String publicKeyFile)
                                             throws java.io.IOException,
                                                    PGPException,
                                                    FileIsEncryptedException
Verifies the signature of an OpenPGP signed only message without extracting its data

This method can be used for both signed and clear text signed OpenPGP messages


Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyWithoutExtractStringDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = "..."; // Fill here the OpenPGP signed message

         // The public key of the sender, used to verify the message  
         String publicKeyFile = "c:\\public_key.asc";  
         
         // verify without extracting the data
         SignatureCheckResult signatureCheck = pgp.verifyWithoutExtracting(openpgpMessage, publicKeyFile);      
         if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
         } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
         } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("Signature not matching provided public key /it is from another sender/");
         } else {
                  System.out.println("No signature found in message");
         }
         
         System.out.println("plain message: " + decryptedMessage.toString());
     }
 }
 

Parameters:
message - OpenPGP signed message or file location
publicKeyFile - The public key of the sender as ASCII armored string or as file location
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
Since:
3.1.0
See Also:
#signString(String, String, String, String)}

verifyWithoutExtracting

public SignatureCheckResult verifyWithoutExtracting(java.lang.String message,
                                                    KeyStore keyStore)
                                             throws java.io.IOException,
                                                    PGPException,
                                                    FileIsEncryptedException
Verifies an OpenPGP signed only message and extracts the contents

This method can be used for both signed and clear text signed OpenPGP messages


Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyAndExtractStringDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = ""; // Fill here the OpenPGP signed message

         KeyStore keyStore = new KeyStore("mylocal.keystore", "my password");  
         
         SignatureCheckResult signatureCheck = pgp.verifyWithoutExtracting(openpgpMessage, keyStore);      
         if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
         } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
         } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("No matching public key was found in the KeyStore");
         } else {
                  System.out.println("No signature found in message");
         }
         
         System.out.println("plain message: " + decryptedMessage.toString());
     }
 }
 

Parameters:
message - OpenPGP signed message
keyStore - KeyStore containing set of partner public keys agianst which the signature will be varified
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
Since:
3.1.0
See Also:
signString(String, KeyStore, String, String, String)

verifyWithoutExtracting

public SignatureCheckResult verifyWithoutExtracting(java.lang.String message,
                                                    KeyStore keyStore,
                                                    java.lang.String privateKeyPassword)
                                             throws java.io.IOException,
                                                    PGPException,
                                                    FileIsEncryptedException
Verifies an OpenPGP signed only message and extracts the contents

This method can be used for both signed and clear text signed OpenPGP messages


Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyWithoutExtractStringDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = ""; // Fill here the OpenPGP signed message

         KeyStore keyStore = new KeyStore("mylocal.keystore", "my password");  
         
         SignatureCheckResult signatureCheck = pgp.verifyWithoutExtracting(openpgpMessage, keyStore, "private key password");      
         if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
         } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
         } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("No matching public key was found in the KeyStore");
         } else {
                  System.out.println("No signature found in message");
         }
         
         System.out.println("plain message: " + decryptedMessage.toString());
     }
 }
 

Parameters:
message - OpenPGP signed message
keyStore - KeyStore containing set of partner public keys agianst which the signature will be varified
privateKeyPassword - Password for a private key contained in the KeyStore parameter
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
WrongPasswordException - if the data is also encryped and the specified private key pasword doesn't match
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
FileIsEncryptedException
Since:
3.1.0
See Also:
signString(String, KeyStore, String, String, String)

verifyWithoutExtracting

public SignatureCheckResult verifyWithoutExtracting(java.io.File dataFile,
                                                    java.io.File publicKeyFile)
                                             throws PGPException,
                                                    FileIsEncryptedException,
                                                    java.io.IOException
Verifies a file for being correctly OpenPGP signed without extracting its data

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         // verify and extract the signed content
         SignatureCheckResult signatureCheck = 
                                                pgp.verifyWithoutExtracting(new File("signed.pgp"), 
                                                                                        new File("sender_public_key.asc"));
               
         if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
         } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
         } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("Signature not matching provided public key (the message is from another sender)");
         } else {
                  System.out.println("No signature found in message");
         }
     }
 }
 

Parameters:
dataFile - File to be verified for a valid OpenPGP signature
publicKeyFile - Sender public key file
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
Since:
3.1.0
See Also:
signFile(String, String, String, String, boolean), signFileVersion3(String, String, String, String, boolean)

verifyWithoutExtracting

public SignatureCheckResult verifyWithoutExtracting(java.io.File dataFile,
                                                    java.io.File privateKeyFile,
                                                    java.lang.String privateKeyPassword,
                                                    java.io.File publicKeyFile)
                                             throws PGPException,
                                                    FileIsEncryptedException,
                                                    java.io.IOException
Verifies the signature of an OpenPGP signed and encrypted file, without extracting its data

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         // verify and extract the signed content
         SignatureCheckResult signatureCheck = 
                                                pgp.verifyWithoutExtracting(new File("signed.pgp"), 
                                                                                        new File("my_private_key.asc"),
                                                                                        "my key password",
                                                                                        new File("sender_public_key.asc"));
               
         if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
         } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
         } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("Signature not matching provided public key (the message is from another sender)");
         } else {
                  System.out.println("No signature found in message");
         }
     }
 }
 

Parameters:
dataFile - File to be verified for a valid OpenPGP signature
privateKeyFile - Decryption private key file
privateKeyPassword - Password for the private key
publicKeyFile - Sender public key file
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
WrongPasswordException - if the specified password for the private key desn't match
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
FileIsEncryptedException
Since:
3.1.0
See Also:
signFile(String, String, String, String, boolean), signFileVersion3(String, String, String, String, boolean)

verifyWithoutExtracting

public SignatureCheckResult verifyWithoutExtracting(java.io.File dataFile,
                                                    KeyStore keyStore)
                                             throws PGPException,
                                                    FileIsEncryptedException,
                                                    java.io.IOException
Verifies a file for being correctly OpenPGP signed without extracting its data

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         // initialize the KeyStore
         KeyStore keyStore = new KeyStore("mykeys.keystore", "password");
           
         // verify the signed content without extracting
         SignatureCheckResult signatureCheck = pgp.verifyWithoutExtracting(new File("signed.pgp"), keyStore);      
         if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
         } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
         } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("No matching public key was found in the KeyStore");
         } else {
                  System.out.println("No signature found in message");
         }
     }
 }
 

Parameters:
dataFile - File to be verified for a valid OpenPGP signature
keyStore - KeyStore object containing the sender public key that will be used for verification
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
Since:
3.1.0
See Also:
signFile(String, KeyStore, String, String, String, boolean)

verifyWithoutExtracting

public SignatureCheckResult verifyWithoutExtracting(java.io.File dataFile,
                                                    KeyStore keyStore,
                                                    java.lang.String privateKeyPassword)
                                             throws PGPException,
                                                    FileIsEncryptedException,
                                                    java.io.IOException
Verifies the signature of an OpenPGP signed and encrypted file, without extracting its data

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         // initialize the KeyStore
         KeyStore keyStore = new KeyStore("mykeys.keystore", "password");
           
         // verify the signed content without extracting
         SignatureCheckResult signatureCheck = pgp.verifyWithoutExtracting(new File("signed.pgp"), keyStore, "private key password");      
         if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
         } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
         } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("No matching public key was found in the KeyStore");
         } else {
                  System.out.println("No signature found in message");
         }
     }
 }
 

Parameters:
dataFile - File to be verified for a valid OpenPGP signature
keyStore - KeyStore object containing the sender public key that will be used for verification
privateKeyPassword - Password for the decryption private key
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
WrongPasswordException - if the specified password for the private key doesn't match
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
FileIsEncryptedException
Since:
3.1.0
See Also:
signFile(String, KeyStore, String, String, String, boolean)

verifyAndExtract

public SignatureCheckResult verifyAndExtract(java.io.InputStream dataFileStream,
                                             java.io.InputStream publicKeyStream,
                                             java.io.OutputStream outputFileStream)
                                      throws PGPException,
                                             FileIsEncryptedException,
                                             java.io.IOException
Verifies a stream for being correctly OpenPGP signed and extracts its data

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyAndExtractStreamDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         InputStream dataStream = new FileInputStream("signed.pgp");
         InputStream keyStream = new FileInputStream("sender_public_key.asc");
         OutputStream outputStream = new FileOutputStream("OUTPUT.txt");
         
         try {
           // verify and extract the signed content
           SignatureCheckResult signatureCheck = pgp.verifyAndExtract(dataStream, keyStream, outputStream);      
                if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
                } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
                } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("Signature not matching provided public key /it is from another sender/");
                } else {
                  System.out.println("No signature found in message");
                }
         } finally {
           dataStream.close();
           keyStream.close();
           outputStream.close();
         }
     }
 }
 

Parameters:
dataFileStream - Input stream from signed OpenPGP data to be verified
publicKeyStream - Input stream from the Public OpenPGP key
outputFileStream - Output Stream for the uncompressed signed content
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
Since:
3.1.0
See Also:
signStream(InputStream, String, InputStream, String, OutputStream, boolean)

verifyAndExtract

public SignatureCheckResult verifyAndExtract(java.io.InputStream dataFileStream,
                                             KeyStore keyStore,
                                             java.io.OutputStream outputFileStream)
                                      throws PGPException,
                                             FileIsEncryptedException,
                                             java.io.IOException
Verifies an incoming stream for being correctly OpenPGP signed and extracts its data

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyAndExtractStreamDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         InputStream dataStream = new FileInputStream("signed.pgp");
         // initialize the KeyStore
         KeyStore keyStore = new KeyStore("mykeys.keystore", "password");
         
         OutputStream outputStream = new FileOutputStream("OUTPUT.txt");
         
         try {
           // verify and extract the signed content
           SignatureCheckResult signatureCheck = pgp.verifyAndExtract(dataStream, keyStore, outputStream);      
                if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
                } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
                } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("No matching public key was found in the KeyStore");
                } else {
                  System.out.println("No signature found in message");
                }
         } finally {
           dataStream.close();
           outputStream.close();
         }
     }
 }
 

Parameters:
dataFileStream - Input stream from signed OpenPGP data to be verified
publicKeyStream - Input stream from the Public OpenPGP key
outputFileStream - Output Stream for the uncompressed signed content
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
Since:
3.1.0
See Also:
signStream(InputStream, String, InputStream, String, OutputStream, boolean)

verifyAndExtract

public SignatureCheckResult verifyAndExtract(java.lang.String message,
                                             java.lang.String publicKeyFile,
                                             java.lang.StringBuffer decryptedString,
                                             java.lang.String charsetName)
                                      throws java.io.IOException,
                                             PGPException,
                                             FileIsEncryptedException
Verifies an OpenPGP signed only message and extracts the contents

This method can be used for both signed and clear text signed OpenPGP messages


Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyAndExtractStringDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = ""; // Fill here the OpenPGP signed message
         StringBuffer decryptedMessage = new StringBuffer();

         // The public key of the sender, used to verify the message  
         String publicKeyFile = "c:\\public_key.asc";  
         
         // verify and extract the signed content
         String messageCharSet = "UTF-8";
         SignatureCheckResult signatureCheck = pgp.verifyAndExtract(openpgpMessage, publicKeyFile, decryptedMessage, messageCharSet);      
         if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
         } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
         } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("Signature not matching provided public key /it is from another sender/");
         } else {
                  System.out.println("No signature found in message");
         }
         
         System.out.println("plain message: " + decryptedMessage.toString());
     }
 }
 

Parameters:
message - OpenPGP signed message
publicKeyFile - The public key of the sender as ASCII armored string or as file location
decryptedString - Output string buffer for the extracted content
charsetName - the name of a supported charset
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
Since:
3.1.0
See Also:
#signString(String, String, String, String)}

verifyAndExtract

public SignatureCheckResult verifyAndExtract(java.lang.String message,
                                             java.lang.String publicKeyFile,
                                             java.lang.StringBuffer decryptedString)
                                      throws java.io.IOException,
                                             PGPException,
                                             FileIsEncryptedException
Verifies an OpenPGP signed only message and extracts the contents

This method can be used for both signed and clear text signed OpenPGP messages


Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyAndExtractStringDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = ""; // Fill here the OpenPGP signed message
         StringBuffer decryptedMessage = new StringBuffer();

         // The public key of the sender, used to verify the message  
         String publicKeyFile = "c:\\public_key.asc";  
         
         // verify and extract the signed content
         SignatureCheckResult signatureCheck = pgp.verifyAndExtract(openpgpMessage, publicKeyFile, decryptedMessage);      
         if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
         } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
         } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("Signature not matching provided public key /it is from another sender/");
         } else {
                  System.out.println("No signature found in message");
         }
         
         System.out.println("plain message: " + decryptedMessage.toString());
     }
 }
 

Parameters:
message - OpenPGP signed message or file location
publicKeyFile - The public key of the sender as ASCII armored string or as file location
decryptedString - Output string buffer for the extracted content
charsetName - the name of a supported charset
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
See Also:
#signString(String, String, String, String)}

verifyAndExtract

public SignatureCheckResult verifyAndExtract(java.lang.String message,
                                             KeyStore keyStore,
                                             java.lang.StringBuffer decryptedString,
                                             java.lang.String charsetName)
                                      throws java.io.IOException,
                                             PGPException,
                                             FileIsEncryptedException
Verifies an OpenPGP signed only message and extracts the contents

This method can be used for both signed and clear text signed OpenPGP messages


Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyAndExtractStringDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = ""; // Fill here the OpenPGP signed message
         StringBuffer decryptedMessage = new StringBuffer();

         KeyStore keyStore = KeyStore.OpenFile("mylocal.keystore", "my password");  
         
         // verify and extract the signed content
         String messageCharSet = "UTF-8";
         SignatureCheckResult signatureCheck = pgp.verifyAndExtract(openpgpMessage, keyStore, decryptedMessage, messageCharSet);      
         if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
         } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
         } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("No matching public key was found in the KeyStore");
         } else {
                  System.out.println("No signature found in message");
         }
         
         System.out.println("plain message: " + decryptedMessage.toString());
     }
 }
 

Parameters:
message - OpenPGP signed message
keyStore - KeyStore containing set of partner public keys agianst which the signature will be varified
decryptedString - Output string buffer for the extracted content
charsetName - the name of a supported charset
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
Since:
3.1.0
See Also:
signString(String, KeyStore, String, String, String)

verifyAndExtract

public SignatureCheckResult verifyAndExtract(java.lang.String message,
                                             KeyStore keyStore,
                                             java.lang.StringBuffer decryptedString)
                                      throws java.io.IOException,
                                             PGPException,
                                             FileIsEncryptedException
Verifies an OpenPGP signed only message and extracts the contents

This method can be used for both signed and clear text signed OpenPGP messages


Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyAndExtractStringDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = ""; // Fill here the OpenPGP signed message
         StringBuffer decryptedMessage = new StringBuffer();

         KeyStore keyStore = KeyStore.OpenFile("mylocal.keystore", "my password");  
         
         // verify and extract the signed content
         String messageCharSet = "UTF-8";
         SignatureCheckResult signatureCheck = pgp.verifyAndExtract(openpgpMessage, keyStore, decryptedMessage, messageCharSet);      
         if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
         } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
         } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("Signature not matching provided public key /it is from another sender/");
         } else {
                  System.out.println("No signature found in message");
         }
         
         System.out.println("plain message: " + decryptedMessage.toString());
     }
 }
 

Parameters:
message - OpenPGP signed message
keyStore - KeyStore containing set of partner public keys agianst which the signature will be varified
decryptedString - Output string buffer for the extracted content
charsetName - the name of a supported charset
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
Since:
3.1.0
See Also:
signString(String, KeyStore, String, String, String)

verifyAndExtract

public SignatureCheckResult verifyAndExtract(java.lang.String dataFileName,
                                             java.lang.String publicKeyFileName,
                                             java.lang.String outputFileName)
                                      throws PGPException,
                                             FileIsEncryptedException,
                                             java.io.IOException
Verifies a file for being correctly OpenPGP signed and extracts the data

Example:
 import com.didisoft.pgp.*;
 
 public class VerifyFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         // verify and extract the signed content
         SignatureCheckResult signatureCheck = pgp.verifyAndExtract("signed.pgp", "sender_public_key.asc", "OUTPUT.txt");      
         if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
         } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
         } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("Signature not matching provided public key (the message is from another sender)");
         } else {
                  System.out.println("No signature found in message");
         }
     }
 }
 

Parameters:
dataFileName - File name to be verified for a valid OpenPGP signature (absolute or relative path)
publicKeyFileName - Sender public key file name (absolute or relative path) or the key as ASCII armored string
outputFileName - Output file name, extracted from the signed file (absolute or relative path)
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
Since:
3.1.0
See Also:
signFile(String, String, String, String, boolean), signFileVersion3(String, String, String, String, boolean)

verifyAndExtract

public SignatureCheckResult verifyAndExtract(java.io.File dataFile,
                                             java.io.File publicKeyFile,
                                             java.io.File outputFile)
                                      throws PGPException,
                                             FileIsEncryptedException,
                                             java.io.IOException
Verifies a file for being correctly OpenPGP signed and extracts the data

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         // verify and extract the signed content
         SignatureCheckResult signatureCheck = 
                                                pgp.verifyAndExtract(new File("signed.pgp"), 
                                                                                        new File("sender_public_key.asc"), 
                                                                                        new File("OUTPUT.txt"));
               
         if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
         } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
         } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("Signature not matching provided public key (the message is from another sender)");
         } else {
                  System.out.println("No signature found in message");
         }
     }
 }
 

Parameters:
dataFile - File to be verified for a valid OpenPGP signature
publicKeyFile - Sender public key file
outputFile - Output file where the extracted data will be stored
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
Since:
3.1.0
See Also:
signFile(String, String, String, String, boolean), signFileVersion3(String, String, String, String, boolean)

verifyAndExtract

public SignatureCheckResult verifyAndExtract(java.io.File dataFile,
                                             KeyStore keyStore,
                                             java.io.File outputFile)
                                      throws PGPException,
                                             FileIsEncryptedException,
                                             java.io.IOException
Verifies a file for being correctly OpenPGP signed and extracts the data

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         // initialize the KeyStore
         KeyStore keyStore = new KeyStore("mykeys.keystore", "password");
           
         // verify and extract the signed content
         SignatureCheckResult signatureCheck = pgp.verifyFile(new File("signed.pgp"), keyStore, new File("OUTPUT.txt"));      
         if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
         } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
         } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("No matching public key was found in the KeyStore");
         } else {
                  System.out.println("No signature found in message");
         }
     }
 }
 

Parameters:
dataFile - File to be verified for a valid OpenPGP signature
keyStore - KeyStore object containing the sender public key that will be used for verification
outputFile - Output file where the extracted data will be stored
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
Since:
3.1.0
See Also:
signFile(String, KeyStore, String, String, String, boolean)

verifyAndExtract

public SignatureCheckResult verifyAndExtract(java.lang.String dataFileName,
                                             KeyStore keyStore,
                                             java.lang.String outputFileName)
                                      throws PGPException,
                                             FileIsEncryptedException,
                                             java.io.IOException
Verifies a file for being correctly OpenPGP signed and extracts the data

Example:
 import com.didisoft.pgp.*;
 
 public class VerifyFile {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         // initialize the KeyStore
         KeyStore keyStore = new KeyStore("mykeys.keystore", "my password");
           
         // verify and extract the signed content
         SignatureCheckResult signatureCheck = pgp.verifyAndExtract("signed.pgp", keyStore, "OUTPUT.txt");      
         if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
         } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
         } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("Signature not matching provided public key (the message is from another sender)");
         } else {
                  System.out.println("No signature found in message");
         }
     }
 }
 

Parameters:
dataFileName - File name to be verified for a valid OpenPGP signature (absolute or relative path)
keyStore - KeyStore object containing the sender public key that will be used for verification
outputFileName - Output file name, extracted from the signed file (absolute or relative path)
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
Since:
3.1.0
See Also:
signFile(String, KeyStore, String, String, String, boolean)

verifyStream

public boolean verifyStream(java.io.InputStream dataFileStream,
                            java.io.InputStream publicKeyStream)
                     throws PGPException,
                            FileIsEncryptedException,
                            java.io.IOException
Deprecated. Due to misleading return value. Please use verifyWithoutExtracting(InputStream, InputStream) instead

Verifies a stream for being correctly OpenPGP signed without extracting its data

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyStreamDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         InputStream dataStream = new FileInputStream("signed.pgp");
         InputStream keyStream = new FileInputStream("sender_public_key.asc");
         
         try {
           // verify and extract the signed content
           boolean validSignature = pgp.verifyStream(dataStream, keyStream);      
           if (validSignature) {
             System.out.println("Signature is valid.");
           } else {
             System.out.println("!Signature is invalid!");
           }
         } finally {
           dataStream.close();
           keyStream.close();
         }
     }
 }
 

Parameters:
dataFileStream - Input stream from the file to be verified
publicKeyStream - Input stream from the sender public key
Returns:
true if signed correctly, false if not signed with this public key
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
See Also:
signStream(InputStream, String, InputStream, String, OutputStream, boolean)

verifyStream

public boolean verifyStream(java.io.InputStream dataFileStream,
                            java.io.InputStream publicKeyStream,
                            java.io.OutputStream outputFileStream)
                     throws PGPException,
                            FileIsEncryptedException,
                            java.io.IOException
Deprecated. Due to misleading return value. Please use verifyAndExtract(InputStream, InputStream, OutputStream) instead

Verifies the incoming stream as being correctly signed.

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyStreamDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         InputStream dataStream = new FileInputStream("signed.pgp");
         InputStream keyStream = new FileInputStream("sender_public_key.asc");
         OutputStream outputStream = new FileOutputStream("OUTPUT.txt");
         
         try {
           // verify and extract the signed content
           boolean validSignature = pgp.verifyStream(dataStream, keyStream, outputStream);      
           if (validSignature) {
             System.out.println("Signature is valid.");
           } else {
             System.out.println("!Signature is invalid!");
           }
         } finally {
           dataStream.close();
           keyStream.close();
           outputStream.close();
         }
     }
 }
 

Parameters:
dataFileStream - Input stream from the File to be verified
publicKeyStream - Input stream from the Public key
outputFileStream - Output Stream for the uncompressed signed content
Returns:
true if signed correctly, false if not signed with this public key
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
See Also:
signStream(InputStream, String, InputStream, String, OutputStream, boolean)

verifyStream

public boolean verifyStream(java.io.InputStream dataFileStream,
                            KeyStore keyStore,
                            java.io.OutputStream outputFileStream)
                     throws PGPException,
                            FileIsEncryptedException,
                            java.io.IOException
Deprecated. Due to misleading return value. Please use verifyAndExtract(InputStream, KeyStore, OutputStream) instead

Verifies the incoming stream as being correctly signed.

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyStreamDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         InputStream dataStream = new FileInputStream("signed.pgp");
         OutputStream outputStream = new FileOutputStream("OUTPUT.txt");

         // initialize the KeyStore  
         KeyStore keyStore = new KeyStore("mykeys.keystore", "password");  
         
         try {
           // verify and extract the signed content
           boolean validSignature = pgp.verifyStream(dataStream, keyStore, outputStream);      
           if (validSignature) {
             System.out.println("Signature is valid.");
           } else {
             System.out.println("!Signature is invalid!");
           }
         } finally {
           dataStream.close();
           keyStream.close();
           outputStream.close();
         }
     }
 }
 

Parameters:
dataFileStream - Input stream from the File to be verified
keyStore - Key store instance containing the sender public key for verification
outputFileStream - Output Stream for the uncompressed signed content
Returns:
true if signed correctly, false if not signed with this public key
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature
See Also:
signStream(InputStream, String, InputStream, String, OutputStream, boolean)

verifyString

public boolean verifyString(java.lang.String message,
                            java.lang.String publicKeyFileName,
                            java.lang.StringBuffer decryptedString)
                     throws java.io.IOException,
                            PGPException,
                            FileIsEncryptedException
Deprecated. Due to misleading return value. Please use verifyAndExtract(String, String, StringBuffer) instead

Verifies an OpenPGP signed only message.

Note: The embedded plain text message is converted into String assuming it is UTF-8 encoded. Use the overloaded message with charset parameter if it uses different encoding.

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyStringDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = ""; // Fill here the OpenPGP signed message
         StringBuffer decryptedMessage = new StringBuffer();

         // The public key of the sender, used to verify the message  
         String publicKeyFile = "c:\\public_key.asc";  
         
         // verify and extract the signed content
         boolean validSignature = pgp.verifyString(openpgpMessage, publicKeyFile, decryptedMessage);      
         if (validSignature) {
             System.out.println("The signature is valid.");
         } else {
             System.out.println("The signature is invalid!");
         }
         
         System.out.println("plain message: " + decryptedMessage.toString());
     }
 }
 

Parameters:
message - OpenPGP signed message
publicKeyFileName - The public key of the sender, used to verify the message or the key as ASCII armored string
decryptedString - Output string for the uncompressed signed content
Returns:
true if signed correctly, false if not signed with this public key
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature

verifyString

public boolean verifyString(java.lang.String message,
                            java.lang.String publicKeyFileName,
                            java.lang.StringBuffer decryptedString,
                            java.lang.String charsetName)
                     throws java.io.IOException,
                            PGPException,
                            FileIsEncryptedException
Deprecated. Due to misleading return value. Please use verifyAndExtract(String, String, StringBuffer, String) instead

Verifies an OpenPGP signed only message.

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class VerifyStringDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = ""; // Fill here the OpenPGP signed message
         StringBuffer decryptedMessage = new StringBuffer();

         // The public key of the sender, used to verify the message  
         String publicKeyFile = "c:\\public_key.asc";  
         
         // verify and extract the signed content
         String messageCharSet = "UTF-8";
         boolean validSignature = pgp.verifyString(openpgpMessage, publicKeyFile, decryptedMessage, messageCharSet);      
         if (validSignature) {
             System.out.println("The signature is valid.");
         } else {
             System.out.println("The signature is invalid!");
         }
         
         System.out.println("plain message: " + decryptedMessage.toString());
     }
 }
 

Parameters:
message - OpenPGP signed message
publicKeyFileName - The public key of the sender, used to verify the message or the key as ASCII armored string
decryptedString - Output string for the uncompressed signed content
charsetName - the name of a supported charset
Returns:
true if signed correctly, false if not signed with this public key
Throws:
java.io.IOException - in case of an I/O error
PGPException - general OpenPGP error
NoPublicKeyFoundException - if the public key source is not a valid public key or is corrupted
FileIsEncryptedException - if the input file is not only signed but also encrypted
NonPGPDataException - if the input data is not a valid OpenPGP message
DetachedSignatureException - if the input is a detached OpenPGP signature

decryptAndVerifyString

public boolean decryptAndVerifyString(java.lang.String message,
                                      java.lang.String privateKeyFileName,
                                      java.lang.String privateKeyPassword,
                                      java.lang.String publicKeyFileName,
                                      java.lang.StringBuffer decryptedString)
                               throws java.io.IOException,
                                      PGPException,
                                      FileIsEncryptedException
Deprecated. Due to misleading return value. Please use decryptAndVerify(String, String, String, String, StringBuffer) instead

Decrypts and verifies an OpenPGP one pass signed end encrypted message.

Note: The embedded plain text message is converted into String assuming it is UTF-8 encoded. Use the overloaded message with charset parameter if it uses different encoding.

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class DecryptAndVerifyStringDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = ""; // Fill here the OpenPGP encrypted and signed message
         StringBuffer decryptedMessage = new StringBuffer();

         // The public key of the sender, used to verify the message  
         String publicKeyFile = "c:\\public_key.asc";  
         
         String privateKeyFile = "c:\\my_private_key.asc";
         String privateKeyPassword = "my passsword";
         
         // verify and extract the signed content
         boolean validSignature = pgp.decryptAndVerifyString(openpgpMessage,
                                                               privateKeyFile,
                                                               privateKeyPassword, 
                                                               publicKeyFile, 
                                                               decryptedMessage);
                                                                     
         if (validSignature) {
             System.out.println("The signature is valid.");
         } else {
             System.out.println("The signature is invalid!");
         }
         
         System.out.println("plain message: " + decryptedMessage.toString());
     }
 }
 

Parameters:
message - OpenPGP signed message
privateKeyFile - Private key used for decryption or the key as ASCII armored string
privateKeyPassword - The password of the private key
publicKeyFileName - The public key of the sender, used to verify the message or the key as ASCII armored string
decryptedString - Output string for the extracted signed content
Returns:
true if signed correctly, false if not signed with this public key
Throws:
java.io.IOException - if a file/stream operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
NoPublicKeyFoundException - if the supplied public key source does not contain a public key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
FileIsEncryptedException

decryptAndVerifyString

public boolean decryptAndVerifyString(java.lang.String message,
                                      java.io.InputStream privateKeyStream,
                                      java.lang.String privateKeyPassword,
                                      java.io.InputStream publicKeyStream,
                                      java.lang.StringBuffer decryptedString,
                                      java.lang.String charsetName)
                               throws java.io.IOException,
                                      PGPException
Deprecated. Due to misleading return value. Please use decryptAndVerify(String, String, String, String, StringBuffer, String) instead

Decrypts and verifies an OpenPGP one pass signed end encrypted message.

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class DecryptAndVerifyStringDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = ""; // Fill here the OpenPGP encrypted and signed message
         StringBuffer decryptedMessage = new StringBuffer();

         // The public key of the sender, used to verify the message  
         String publicKeyFile = "c:\\public_key.asc";  
         
         String privateKeyFile = "c:\\my_private_key.asc";
         String privateKeyPassword = "my passsword";
         
         // verify and extract the signed content
         String messageCharSet = "UTF-8";
         boolean validSignature = pgp.decryptAndVerifyString(openpgpMessage,
                                                               privateKeyFile,
                                                               privateKeyPassword, 
                                                               publicKeyFile, 
                                                               decryptedMessage, 
                                                               messageCharSet);      
         if (validSignature) {
             System.out.println("The signature is valid.");
         } else {
             System.out.println("The signature is invalid!");
         }
         
         System.out.println("plain message: " + decryptedMessage.toString());
     }
 }
 

Parameters:
message - OpenPGP signed message
privateKeyFile - Private key used for decryption or the key as ASCII armored string
privateKeyPassword - The password of the private key
publicKeyFileName - The public key of the sender, used to verify the message or the key as ASCII armored string
decryptedString - Output string for the extracted signed content
charsetName - the name of a supported charset
Returns:
true if signed correctly, false if not signed with this public key
Throws:
java.io.IOException - if a file/stream operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
NoPublicKeyFoundException - if the supplied public key source does not contain a public key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted

decryptAndVerifyString

public boolean decryptAndVerifyString(java.lang.String message,
                                      java.lang.String privateKeyFileName,
                                      java.lang.String privateKeyPassword,
                                      java.lang.String publicKeyFileName,
                                      java.lang.StringBuffer decryptedString,
                                      java.lang.String charsetName)
                               throws java.io.IOException,
                                      PGPException
Deprecated. Due to misleading return value. Please use decryptAndVerify(String, String, String, String, StringBuffer, String) instead

Decrypts and verifies an OpenPGP one pass signed end encrypted message.

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class DecryptAndVerifyStringDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = ""; // Fill here the OpenPGP encrypted and signed message
         StringBuffer decryptedMessage = new StringBuffer();

         // The public key of the sender, used to verify the message  
         String publicKeyFile = "c:\\public_key.asc";  
         
         String privateKeyFile = "c:\\my_private_key.asc";
         String privateKeyPassword = "my passsword";
         
         // verify and extract the signed content
         String messageCharSet = "UTF-8";
         boolean validSignature = pgp.decryptAndVerifyString(openpgpMessage,
                                                               privateKeyFile,
                                                               privateKeyPassword, 
                                                               publicKeyFile, 
                                                               decryptedMessage, 
                                                               messageCharSet);      
         if (validSignature) {
             System.out.println("The signature is valid.");
         } else {
             System.out.println("The signature is invalid!");
         }
         
         System.out.println("plain message: " + decryptedMessage.toString());
     }
 }
 

Parameters:
message - OpenPGP signed message
privateKeyFile - Private key used for decryption or the key as ASCII armored string
privateKeyPassword - The password of the private key
publicKeyFileName - The public key of the sender, used to verify the message or the key as ASCII armored string
decryptedString - Output string for the extracted signed content
charsetName - the name of a supported charset
Returns:
true if signed correctly, false if not signed with this public key
Throws:
java.io.IOException - if a file/stream operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
NoPublicKeyFoundException - if the supplied public key source does not contain a public key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted

decryptAndVerify

public SignatureCheckResult decryptAndVerify(java.lang.String message,
                                             java.lang.String privateKeyFileName,
                                             java.lang.String privateKeyPassword,
                                             java.lang.String publicKeyFileName,
                                             java.lang.StringBuffer decryptedString)
                                      throws java.io.IOException,
                                             PGPException,
                                             FileIsEncryptedException
Decrypts and verifies an OpenPGP one pass signed end encrypted message.

Note: The embedded plain text message is converted into String assuming it is UTF-8 encoded. Use the overloaded message with charset parameter if it uses different encoding.

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class DecryptAndVerifyStringDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = ""; // Fill here the OpenPGP encrypted and signed message
         StringBuffer decryptedMessage = new StringBuffer();

         // The public key of the sender, used to verify the message  
         String publicKeyFile = "c:\\public_key.asc";  
         
         String privateKeyFile = "c:\\my_private_key.asc";
         String privateKeyPassword = "my passsword";
         
         // verify and extract the signed content
         SignatureCheckResult signatureCheck = pgp.decryptAndVerify(openpgpMessage,
                                                               privateKeyFile,
                                                               privateKeyPassword, 
                                                               publicKeyFile, 
                                                               decryptedMessage);
                                                                     
         if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
         } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
         } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("Signature not matching provided public key (the message is from another sender)");
         } else {
                  System.out.println("No signature found in message");
         }
         
         System.out.println("plain message: " + decryptedMessage.toString());
     }
 }
 

Parameters:
message - OpenPGP signed message
privateKeyFile - Private key used for decryption or the key as ASCII armored string
privateKeyPassword - The password of the private key
publicKeyFileName - The public key of the sender, used to verify the message or the key as ASCII armored string
decryptedString - Output string for the uncompressed signed content
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - if a file/stream operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
NoPublicKeyFoundException - if the supplied public key source does not contain a public key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
FileIsEncryptedException
Since:
3.1.0

decryptAndVerify

public SignatureCheckResult decryptAndVerify(java.lang.String message,
                                             java.lang.String privateKeyFileName,
                                             java.lang.String privateKeyPassword,
                                             java.lang.String publicKeyFileName,
                                             java.lang.StringBuffer decryptedString,
                                             java.lang.String charsetName)
                                      throws java.io.IOException,
                                             PGPException
Decrypts and verifies an OpenPGP one pass signed end encrypted message.

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class DecryptAndVerifyStringDemo {
     public static void main(String[] args) throws Exception {
         // create an instance of the library
         PGPLib pgp = new PGPLib();

         String openpgpMessage = ""; // Fill here the OpenPGP encrypted and signed message
         StringBuffer decryptedMessage = new StringBuffer();

         // The public key of the sender, used to verify the message  
         String publicKeyFile = "c:\\public_key.asc";  
         
         String privateKeyFile = "c:\\my_private_key.asc";
         String privateKeyPassword = "my passsword";
         
         // verify and extract the signed content
         String messageCharSet = "UTF-8";
         SignatureCheckResult signatureCheck = pgp.decryptAndVerify(openpgpMessage,
                                                               privateKeyFile,
                                                               privateKeyPassword, 
                                                               publicKeyFile, 
                                                               decryptedMessage, 
                                                               messageCharSet);
                                                                     
         if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
         } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
         } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("Signature not matching provided public key (the message is from another sender)");
         } else {
                  System.out.println("No signature found in message");
         }
         
         System.out.println("plain message: " + decryptedMessage.toString());
     }
 }
 

Parameters:
message - OpenPGP signed message
privateKeyFile - Private key used for decryption or the key as ASCII armored string
privateKeyPassword - The password of the private key
publicKeyFileName - The public key of the sender, used to verify the message or the key as ASCII armored string
decryptedString - Output string for the uncompressed signed content
charsetName - the name of a supported charset
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - if a file/stream operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
NoPublicKeyFoundException - if the supplied public key source does not contain a public key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
Since:
3.1.0

decryptAndVerifyFile

public boolean decryptAndVerifyFile(java.lang.String encryptedFileName,
                                    KeyStore keyStore,
                                    java.lang.String privateKeyPassword,
                                    java.lang.String outputFileName)
                             throws PGPException,
                                    java.io.IOException
Deprecated. Due to misleading return value. Please use decryptAndVerify(String, KeyStore, String, String) instead

Decrypts and verifies one pass encrypted and signed OpenPGP file
Supports OpenPGP version 3 format too (used by PGP 6.5 and below).

Parameters:
encryptedFileName - File name to be decrypted (absolute or relative path)
keyStore - Key store containing the Private Key for decryption and the other party Public key for verification
privateKeyPassword - Private key password
outputFileName - File name of the Output decrypted file (absolute or relative path).
Returns:
true if signature is valid, false if signature is invalid
Throws:
java.io.IOException - if a file/stream operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
See Also:
signAndEncryptFile(String, KeyStore, String, String, String, String, boolean, boolean)

decryptAndVerify

public SignatureCheckResult decryptAndVerify(java.lang.String encryptedFileName,
                                             java.lang.String privateKeyFileName,
                                             java.lang.String privateKeyPassword,
                                             java.lang.String publicKeyFile,
                                             java.lang.String outputFileName)
                                      throws PGPException,
                                             java.io.IOException
Decrypts and verifies an OpenPGP encrypted and signed file
Supports OpenPGP version 3 format too (used by PGP(r) 5 and below).

Example:
 import com.didisoft.pgp.*;
 
 public class DecryptAndVerifyFileDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         // verify and extract the signed content
         SignatureCheckResult signatureCheck = pgp.decryptAndVerify("encrypted.pgp",
                                                           "decryption_private_key.asc",
                                                           "decryption key password",   
                                                           "sender_public_key.asc", 
                                                           "OUTPUT.txt");      
         if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
         } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
         } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("Signature not matching provided public key (the message is from another sender)");
         } else {
                  System.out.println("No signature found in message");
         }
     }
 }
 

Parameters:
encryptedFileName - File name to be decrypted (absolute or relative path)
privateKeyFileName - Private key file name used for decryption (absolute or relative path) or the key as ASCII armored string
privateKeyPassword - Private key password
publicKeyFile - Public key file name used for verification of the signature (absolute or relative path)
outputFileName - File name of the output decrypted file (absolute or relative path) or the key as ASCII armored string
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - if a file/stream operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
NoPublicKeyFoundException - if the supplied public key source does not contain a public key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
Since:
3.1.0
See Also:
signAndEncryptFile(String, String, String, String, String, boolean, boolean)

decryptAndVerify

public SignatureCheckResult decryptAndVerify(java.lang.String encryptedFileName,
                                             KeyStore keyStore,
                                             java.lang.String privateKeyPassword,
                                             java.lang.String outputFileName)
                                      throws PGPException,
                                             java.io.IOException
Decrypts and verifies one pass encrypted and signed OpenPGP file
Supports OpenPGP version 3 format too (used by PGP 6.5 and below).

Example:
 import com.didisoft.pgp.*;
 
 public class DecryptAndVerifyFileDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         // initialize the KeyStore
         KeyStore keyStore = new KeyStore("mykeys.keystore", "password");
         
         // verify and extract the signed content
         SignatureCheckResult signatureCheck = pgp.decryptAndVerify("encrypted.pgp",
                                                           keyStore,
                                                           "decryption key password",   
                                                           "OUTPUT.txt");      
         if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
         } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
         } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("No matching public key was found in the KeyStore");
         } else {
                  System.out.println("No signature found in message");
         }
     }
 }
 

Parameters:
encryptedFileName - File name to be decrypted (absolute or relative path)
keyStore - Key store containing the Private Key for decryption and the other party Public key for verification
privateKeyPassword - Private key password
outputFileName - File name of the Output decrypted file (absolute or relative path).
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - if a file/stream operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
Since:
3.1.0
See Also:
signAndEncryptFile(String, KeyStore, String, String, String, String, boolean, boolean)

decryptAndVerifyFileTo

public boolean decryptAndVerifyFileTo(java.lang.String encryptedFileName,
                                      KeyStore keyStore,
                                      java.lang.String privateKeyPassword,
                                      java.lang.String outputFolder)
                               throws PGPException,
                                      java.io.IOException
Deprecated. Due to misleading return value. Please use decryptAndVerify(String, KeyStore, String, String) instead

Decrypts and verifies one pass encrypted and signed OpenPGP file
Supports OpenPGP version 3 format too (used by PGP 6.5 and below).

Parameters:
encryptedFileName - File name to be decrypted (absolute or relative path)
keyStore - Key store containing the Private Key for decryption and the other party Public key for verification
privateKeyPassword - Private key password
outputFileName - File name of the Output decrypted file (absolute or relative path).
Returns:
true if signature is valid, false if signature is invalid
Throws:
java.io.IOException - if a file/stream operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
See Also:
signAndEncryptFile(String, KeyStore, String, String, String, String, boolean, boolean)

decryptAndVerifyTo

public SignatureCheckResult decryptAndVerifyTo(java.lang.String encryptedFileName,
                                               KeyStore keyStore,
                                               java.lang.String privateKeyPassword,
                                               java.lang.String outputFolder)
                                        throws PGPException,
                                               java.io.IOException
Verifies the signature and decrypts a one pass signed and encrypted OpenPGP file into a folder
Supports OpenPGP version 3 format too (used by PGP 6.5 and below).

Parameters:
encryptedFileName - File name to be decrypted (absolute or relative path)
keyStore - Key store containing the Private Key for decryption and the other party Public key for verification
privateKeyPassword - Private key password
outputFileName - File name of the Output decrypted file (absolute or relative path).
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - if a file/stream operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
Since:
3.1.0
See Also:
signAndEncryptFile(String, KeyStore, String, String, String, String, boolean, boolean)

decryptAndVerifyStream

public boolean decryptAndVerifyStream(java.io.InputStream encryptedStream,
                                      KeyStore keyStore,
                                      java.lang.String privateKeyPassword,
                                      java.io.OutputStream outputStream)
                               throws PGPException,
                                      java.io.IOException
Deprecated. Due to misleading return value. Please use decryptAndVerifyStream(InputStream, KeyStore, String, OutputStream) instead

Decrypts and verifies OpenPGP encrypted and signed stream.
Supports OpenPGP version 3 format too (used by PGP 2.x systems).

Parameters:
encryptedStream - Input stream with the encrypted content
keyStore - Key store instance containing the Private Key for decryption and the other party Public key for verification
privateKeyPassword - Private Key password
outputStream - Output stream for the decrypted content
Returns:
true if signature is valid, false if signature is invalid
Throws:
java.io.IOException - if a file/stream operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
NoPublicKeyFoundException - if the supplied public key source does not contain a public key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
See Also:
signAndEncryptStream(InputStream, String, KeyStore, String, String, String, OutputStream, boolean, boolean)

decryptAndVerify

public SignatureCheckResult decryptAndVerify(java.io.InputStream encryptedStream,
                                             KeyStore keyStore,
                                             java.lang.String privateKeyPassword,
                                             java.io.OutputStream outputStream)
                                      throws PGPException,
                                             java.io.IOException
Decrypts and verifies OpenPGP encrypted and signed stream.
Supports OpenPGP version 3 format too (used by PGP 2.x systems).

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class DecryptAndVerifyStreamDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         InputStream dataStream = new FileInputStream("signed.pgp");
         KeyStore keyStore = new KeyStore("mylocal.keystore", "my password");
         OutputStream outputStream = new FileOutputStream("OUTPUT.txt");
         
         try {
           // verify and extract the signed content
           SignatureCheckResult signatureCheck = pgp.decryptAndVerify(dataStream,
                                                             keyStore,
                                                             "decryption key password",    
                                                             outputStream);      
                if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
                } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
                } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("No matching public key was found in the KeyStore");
                } else {
                  System.out.println("No signature found in message");
                }
         } finally {
           dataStream.close();
           outputStream.close();
         }         
     }
 }
 

Parameters:
encryptedStream - Input stream with the encrypted content
keyStore - Key store instance containing the Private Key for decryption and the other party Public key for verification
privateKeyPassword - Private Key password
outputStream - Output stream for the decrypted content
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - if a file/stream operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
NoPublicKeyFoundException - if the supplied public key source does not contain a public key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
Since:
3.1.0
See Also:
signAndEncryptStream(InputStream, String, KeyStore, String, String, String, OutputStream, boolean, boolean)

decryptAndVerifyFile

public boolean decryptAndVerifyFile(java.lang.String encryptedFileName,
                                    java.lang.String privateKeyFileName,
                                    java.lang.String privateKeyPassword,
                                    java.lang.String publicKeyFile,
                                    java.lang.String outputFileName)
                             throws PGPException,
                                    java.io.IOException
Deprecated. Due to misleading return value. Please use decryptAndVerifyFile(String, String, String, String, String) instead

Decrypts and verifies an OpenPGP encrypted and signed file
Supports OpenPGP version 3 format too (used by PGP(r) 5 and below).

Example:
 import com.didisoft.pgp.*;
 
 public class DecryptAndVerifyFileDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         // verify and extract the signed content
         boolean validSignature = pgp.decryptAndVerifyFile("encrypted.pgp",
                                                           "decryption_private_key.asc",
                                                           "decryption key password",   
                                                           "sender_public_key.asc", 
                                                           "OUTPUT.txt");      
         if (validSignature) {
             System.out.println("Signature is valid.");
         } else {
             System.out.println("!Signature is invalid!");
         }
     }
 }
 

Parameters:
encryptedFileName - File name to be decrypted (absolute or relative path)
privateKeyFileName - Private key file name used for decryption (absolute or relative path) or the key as ASCII armored string
privateKeyPassword - Private key password
publicKeyFile - Public key file name used for verification of the signature (absolute or relative path)
outputFileName - File name of the output decrypted file (absolute or relative path) or the key as ASCII armored string
Returns:
true if signature is valid, false if signature is invalid
Throws:
java.io.IOException - if a file/stream operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
NoPublicKeyFoundException - if the supplied public key source does not contain a public key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
See Also:
signAndEncryptFile(String, String, String, String, String, boolean, boolean)

decryptAndVerifyFileTo

public boolean decryptAndVerifyFileTo(java.lang.String encryptedFileName,
                                      java.lang.String privateKeyFileName,
                                      java.lang.String privateKeyPassword,
                                      java.lang.String publicKeyFile,
                                      java.lang.String outputFolder)
                               throws PGPException,
                                      java.io.IOException
Deprecated. Due to misleading return value. Please use decryptAndVerifyTo(String, String, String, String, String) instead

Decrypts and verifies an OpenPGP encrypted and signed file to a folder
This methods is very suitable for multi file PGP archives. Supports OpenPGP version 3 format too (used by PGP 5.6 and below).

Example:
 import com.didisoft.pgp.*;
 
 public class DecryptAndVerifyFileToDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         String outputFolder = "c:\\Temp";
         
         // verify and extract the signed content
         boolean validSignature = pgp.decryptAndVerifyFileTo("encrypted.pgp",
                                                           "decryption_private_key.asc",
                                                           "decryption key password",   
                                                           "sender_public_key.asc", 
                                                           outputFolder);      
         if (validSignature) {
             System.out.println("Signature is valid.");
         } else {
             System.out.println("!Signature is invalid!");
         }
     }
 }
 

Parameters:
encryptedFileName - File name to be decrypted (absolute or relative path)
privateKeyFileName - Private key file name used for decryption (absolute or relative path)
privateKeyPassword - Private key password
publicKeyFile - Public key file name used for verification of the signature (absolute or relative path)
outputFolder - Output folder where the decrypted file(s) will be stored
Returns:
true if signature is valid, false if signature is invalid
Throws:
java.io.IOException - if a file/stream operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
NoPublicKeyFoundException - if the supplied public key source does not contain a public key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
See Also:
signAndEncryptFile(String, String, String, String, String, boolean, boolean)

decryptAndVerifyTo

public SignatureCheckResult decryptAndVerifyTo(java.lang.String encryptedFileName,
                                               java.lang.String privateKeyFileName,
                                               java.lang.String privateKeyPassword,
                                               java.lang.String publicKeyFile,
                                               java.lang.String outputFolder)
                                        throws PGPException,
                                               java.io.IOException
Decrypts and verifies an OpenPGP encrypted and signed file to a folder
This methods is very suitable for multi file PGP archives. Supports OpenPGP version 3 format too (used by PGP 5.6 and below).

Example:
 import com.didisoft.pgp.*;
 
 public class DecryptAndVerifyFileToDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         String outputFolder = "c:\\Temp";
         
         // verify and extract the signed content
         SignatureCheckResult signatureCheck = pgp.decryptAndVerifyTo("encrypted.pgp",
                                                           "decryption_private_key.asc",
                                                           "decryption key password",   
                                                           "sender_public_key.asc", 
                                                           outputFolder);
                                                                 
         if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
         } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
         } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("Signature not matching provided public key (the message is from another sender)");
         } else {
                  System.out.println("No signature found in message");
         }
     }
 }
 

Parameters:
encryptedFileName - File name to be decrypted (absolute or relative path)
privateKeyFileName - Private key file name used for decryption (absolute or relative path)
privateKeyPassword - Private key password
publicKeyFile - Public key file name used for verification of the signature (absolute or relative path)
outputFolder - Output folder where the decrypted file(s) will be stored
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - if a file/stream operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
NoPublicKeyFoundException - if the supplied public key source does not contain a public key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
Since:
3.1.0
See Also:
signAndEncryptFile(String, String, String, String, String, boolean, boolean)

decryptAndVerifyStream

public boolean decryptAndVerifyStream(java.io.InputStream encryptedStream,
                                      java.io.InputStream privateKeyStream,
                                      java.lang.String privateKeyPassword,
                                      java.io.InputStream publicKeyStream,
                                      java.io.OutputStream outputStream)
                               throws PGPException,
                                      java.io.IOException
Deprecated. Due to misleading return value. Please use decryptAndVerify(InputStream, InputStream, String, InputStream, OutputStream) instead

Decrypts and verifies OpenPGP encrypted and signed stream.
Supports OpenPGP version 3 format too (used by PGP 6.5 and below).

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class DecryptAndVerifyStreamDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         InputStream dataStream = new FileInputStream("signed.pgp");
         InputStream decryptionKeyStream = new FileInputStream("decryption_private_key.asc");
         InputStream verificationKeyStream = new FileInputStream("sender_public_key.asc");
         OutputStream outputStream = new FileOutputStream("OUTPUT.txt");
         
         try {
           // verify and extract the signed content
           boolean validSignature = pgp.decryptAndVerifyStream(dataStream,
                                                             decryptionKeyStream,
                                                             "decryption key password",   
                                                             verificationKeyStream, 
                                                             outputStream);      
           if (validSignature) {
             System.out.println("Signature is valid.");
           } else {
             System.out.println("!Signature is invalid!");
           }
         } finally {
           dataStream.close();
           decryptionKeyStream.close();
           verificationKeyStream.close();
           outputStream.close();
         }         
     }
 }
 

Parameters:
encryptedStream - Input stream with the encrypted and signed content
privateKeyStream - Private Key stream used for decryption. This is usually our own private key
privateKeyPassword - Private Key password
publicKeyStream - Public Key stream used for signature verification. This is usually the public key of the sender
outputStream - Output stream for the decrypted content
Returns:
true if signature is valid, false if signature is invalid
Throws:
java.io.IOException - if a file/stream operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
NoPublicKeyFoundException - if the supplied public key source does not contain a public key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
See Also:
signAndEncryptStream(InputStream, String, InputStream, String, InputStream, OutputStream, boolean, boolean)

decryptAndVerify

public SignatureCheckResult decryptAndVerify(java.io.InputStream encryptedStream,
                                             java.io.InputStream privateKeyStream,
                                             java.lang.String privateKeyPassword,
                                             java.io.InputStream publicKeyStream,
                                             java.io.OutputStream outputStream)
                                      throws PGPException,
                                             java.io.IOException
Decrypts and verifies OpenPGP encrypted and signed stream.
Supports OpenPGP version 3 format too (used by PGP 6.5 and below).

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class DecryptAndVerifyStreamDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         InputStream dataStream = new FileInputStream("signed.pgp");
         InputStream decryptionKeyStream = new FileInputStream("decryption_private_key.asc");
         InputStream verificationKeyStream = new FileInputStream("sender_public_key.asc");
         OutputStream outputStream = new FileOutputStream("OUTPUT.txt");
         
         try {
           // verify and extract the signed content
           SignatureCheckResult signatureCheck = pgp.decryptAndVerify(dataStream,
                                                             decryptionKeyStream,
                                                             "decryption key password",   
                                                             verificationKeyStream, 
                                                             outputStream);      
                if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
                } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
                } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("Signature not matching provided public key (the message is from another sender)");
                } else {
                  System.out.println("No signature found in message");
                }
         } finally {
           dataStream.close();
           decryptionKeyStream.close();
           verificationKeyStream.close();
           outputStream.close();
         }         
     }
 }
 

Parameters:
encryptedStream - Input stream with the encrypted and signed content
privateKeyStream - Private Key stream used for decryption. This is usually our own private key
privateKeyPassword - Private Key password
publicKeyStream - Public Key stream used for signature verification. This is usually the public key of the sender
outputStream - Output stream for the decrypted content
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - if a file/stream operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
NoPublicKeyFoundException - if the supplied public key source does not contain a public key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
Since:
3.1.0
See Also:
signAndEncryptStream(InputStream, String, InputStream, String, InputStream, OutputStream, boolean, boolean)

decryptAndVerifyStreamTo

public boolean decryptAndVerifyStreamTo(java.io.InputStream encryptedStream,
                                        java.io.InputStream privateKeyStream,
                                        java.lang.String privateKeyPassword,
                                        java.io.InputStream publicKeyStream,
                                        java.lang.String outputFolder)
                                 throws PGPException,
                                        java.io.IOException
Deprecated. Due to misleading return value. Please use decryptAndVerifyTo(InputStream, InputStream, String, InputStream, String) instead

Decrypts and verifies OpenPGP encrypted and signed stream.
Supports OpenPGP version 3 format too (used by PGP 6.5 and below).

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class DecryptAndVerifyStreamToDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         InputStream dataStream = new FileInputStream("signed.pgp");
         InputStream decryptionKeyStream = new FileInputStream("decryption_private_key.asc");
         InputStream verificationKeyStream = new FileInputStream("sender_public_key.asc");
         
         String outputFolder = "c:\\Temp";
         
         try {
           // verify and extract the signed content
           boolean validSignature = pgp.decryptAndVerifyStreamTo(dataStream,
                                                             decryptionKeyStream,
                                                             "decryption key password",   
                                                             verificationKeyStream, 
                                                             outputFolder);      
           if (validSignature) {
             System.out.println("Digital signature is valid.");
           } else {
             System.out.println("!Digital signature is invalid!");
           }
         } finally {
           dataStream.close();
           decryptionKeyStream.close();
           verificationKeyStream.close();
           outputStream.close();
         }         
     }
 }
 

Parameters:
encryptedStream - Input stream with the encrypted and signed content
privateKeyStream - Private Key stream used for decryption. This is usually our own private key
privateKeyPassword - Private Key password
publicKeyStream - Public Key stream used for signature verification. This is usually the public key of the sender
outputFolder - Output folder where the decrypted file(s) will be stored
Returns:
true if signature is valid, false if signature is invalid
Throws:
java.io.IOException - if a file/stream operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
NoPublicKeyFoundException - if the supplied public key source does not contain a public key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
See Also:
signAndEncryptStream(InputStream, String, InputStream, String, InputStream, OutputStream, boolean, boolean)

decryptAndVerifyTo

public SignatureCheckResult decryptAndVerifyTo(java.io.InputStream encryptedStream,
                                               java.io.InputStream privateKeyStream,
                                               java.lang.String privateKeyPassword,
                                               java.io.InputStream publicKeyStream,
                                               java.lang.String outputFolder)
                                        throws PGPException,
                                               java.io.IOException
Verifies the signature and decrypts an OpenPGP encrypted and signed stream contents into a folder
Supports OpenPGP version 3 format too (used by PGP 6.5 and below).

Example:
 import java.io.*;
 import com.didisoft.pgp.*;
 
 public class DecryptAndVerifyStreamToDemo {
     public static void main(String[] args) throws Exception{
         // create an instance of the library
         PGPLib pgp = new PGPLib();
         
         InputStream dataStream = new FileInputStream("signed.pgp");
         InputStream decryptionKeyStream = new FileInputStream("decryption_private_key.asc");
         InputStream verificationKeyStream = new FileInputStream("sender_public_key.asc");
         
         String outputFolder = "c:\\Temp";
         
         try {
           // verify and extract the signed content
           SignatureCheckResult signatureCheck = pgp.decryptAndVerifyTo(dataStream,
                                                             decryptionKeyStream,
                                                             "decryption key password",   
                                                             verificationKeyStream, 
                                                             outputFolder);      
                if (signatureCheck == SignatureCheckResult.SignatureVerified) {
             System.out.println("The signature is valid.");
                } else if (signatureCheck == SignatureCheckResult.SignatureBroken) {
             System.out.println("Message corrupted or signature forged");
                } else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching) {
             System.out.println("Signature not matching provided public key (the message is from another sender)");
                } else {
                  System.out.println("No signature found in message");
                }
         } finally {
           dataStream.close();
           decryptionKeyStream.close();
           verificationKeyStream.close();
           outputStream.close();
         }         
     }
 }
 

Parameters:
encryptedStream - Input stream with the encrypted and signed content
privateKeyStream - Private Key stream used for decryption. This is usually our own private key
privateKeyPassword - Private Key password
publicKeyStream - Public Key stream used for signature verification. This is usually the public key of the sender
outputFolder - Output folder where the decrypted file(s) will be stored
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - if a file/stream operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
NoPublicKeyFoundException - if the supplied public key source does not contain a public key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
Since:
3.1.0
See Also:
signAndEncryptStream(InputStream, String, InputStream, String, InputStream, OutputStream, boolean, boolean)

decryptAndVerifyStreamTo

public boolean decryptAndVerifyStreamTo(java.io.InputStream encryptedStream,
                                        KeyStore keyStore,
                                        java.lang.String privateKeyPassword,
                                        java.lang.String outputFolder)
                                 throws PGPException,
                                        java.io.IOException
Deprecated. Due to misleading return value. Please use decryptAndVerifyTo(InputStream, KeyStore, String, String) instead

Decrypts and verifies OpenPGP encrypted and signed stream.
Supports OpenPGP version 3 format too (used by PGP 2.x systems).

Parameters:
encryptedStream - Input stream with the encrypted content
keyStore - Key store instance containing the Private Key for decryption and the other party Public key for verification
privateKeyPassword - Private Key password
outputFolder - Output folder where the decrypted file(s) will be stored
Returns:
true if signature is valid, false if signature is invalid
Throws:
java.io.IOException - if a file/stream operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
NoPublicKeyFoundException - if the supplied public key source does not contain a public key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
See Also:
signAndEncryptStream(InputStream, String, KeyStore, String, String, String, OutputStream, boolean, boolean)

decryptAndVerifyTo

public SignatureCheckResult decryptAndVerifyTo(java.io.InputStream encryptedStream,
                                               KeyStore keyStore,
                                               java.lang.String privateKeyPassword,
                                               java.lang.String outputFolder)
                                        throws PGPException,
                                               java.io.IOException
Decrypts and verifies OpenPGP encrypted and signed stream.
Supports OpenPGP version 3 format too (used by PGP 2.x systems).

Parameters:
encryptedStream - Input stream with the encrypted content
keyStore - Key store instance containing the Private Key for decryption and the other party Public key for verification
privateKeyPassword - Private Key password
outputFolder - Output folder where the decrypted file(s) will be stored
Returns:
SignatureCheckResult representing the signature verification result
Throws:
java.io.IOException - if a file/stream operation throws an exception
PGPException - general OpenPGP error
NonPGPDataException - if the encrypted input is not a valid OpenPGP encrypted message
NoPrivateKeyFoundException - if the supplied private key source does not contain a private key or is corrupted
NoPublicKeyFoundException - if the supplied public key source does not contain a public key or is corrupted
WrongPrivateKeyException - if the encrypted input was not encrypted with this private key.
WrongPasswordException - if the password for this private key is misspelled.
FileIsPBEEncryptedException - if the encrypted input is a password encrypted (PBE) OpenPGP archive
DetachedSignatureException - if the encrypted input is a detached OpenPGP signature
IntegrityCheckException - if the encrypted input is corrupted
Since:
3.1.0
See Also:
signAndEncryptStream(InputStream, String, KeyStore, String, String, String, OutputStream, boolean, boolean)

isTrialVersion

public boolean isTrialVersion()
Checks is this an evaluation instance of the library

Returns:
true if this version is an evaluation copy, false if it is a production version

isPgp2Compatible

public boolean isPgp2Compatible()
Checks is PGP 2.x encryption and signing compatibility mode enabled

This is useful only when exchanging data with very old PGP 2.x systems

The default is false.

Returns:
is PGP 2.x encryption and signing compatibility mode enabled
See Also:
setPgp2Compatible(boolean)

setPgp2Compatible

public void setPgp2Compatible(boolean pgp2Compatible)
Sets PGP 2.x encryption and signing compatibility mode

This is useful to be set to true only when exchanging data with very old PGP 2.x systems.

For more information check RFC 1991 - http://www.ietf.org/rfc/rfc1991.txt

Parameters:
pgp2Compatible - if true, the .pgp archives generated by the library will be compatible with PGP 2.x systems, otherwise only PGP 6.x and newer versions can read the produced encrypted output

Example:

 PGPLib pgp = new PGPLib();
 pgp.setPgp2Compatible(true);
 // now the produced .pgp output will be accepted by ancient PGP 2.x systems 
 

isExtractTarFiles

public boolean isExtractTarFiles()
Checks is the library set to extract embedded TAR files

This is useful only when we want to manually extract TAR files

The default is true.

Returns:
is the library set to extract embedded TAR files
See Also:
setExtractTarFiles(boolean)

setExtractTarFiles

public void setExtractTarFiles(boolean extractTarFiles)
Sets should the library extract embedded TAR files

This is useful to be set to false when e want to manually handle encrypted TAR files

Parameters:
extractTarFiles - if true, encrypted .tar files will be extracted with decryptFileTo(String, String, String, String) otherwise they will be decrypted intact

Example:

 PGPLib pgp = new PGPLib();
 pgp.setExtractTarFiles(false);
 // now encrypted .tar files will be kept intact 
 

isOverrideKeyAlgorithmPreferences

public boolean isOverrideKeyAlgorithmPreferences()
returns will the algorithms choosed with setCompression(String), setCypher(String), setHash(String) override the used key preferences

Returns:
will the algorithms choosed with setCompression(String), setCypher(String), setHash(String) override the used key preferences

setOverrideKeyAlgorithmPreferences

public void setOverrideKeyAlgorithmPreferences(boolean overrideKeyAlgorithmPreferences)
Sets will the algorithms choosed with setCompression(String), setCypher(String), setHash(String) override the used key preferences

Parameters:
overrideKeyAlgorithmPreferences - if true, the key algorithm preferences will be ignored. Default is false.


Copyright © 2006-2017 DidiSoft Ltd. All Rights Reserved.