|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.didisoft.pgp.bc.BaseLib
com.didisoft.pgp.PGPLib
public class PGPLib
OpenPGP Library for Android.
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 Android versions: 2.1, 2.2, 2.3, 3.0, 4.0
Copyright DidiSoft Ltd.
www.didisoft.com
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,
HashAlgorithm hashingAlgorithm,
java.lang.String outputFileName)
OpenPGP clear signs a file. |
void |
clearSignFileVersion3(java.lang.String inputFileName,
java.lang.String privateKeyFileName,
java.lang.String privateKeyPassword,
HashAlgorithm 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,
HashAlgorithm hashingAlgorithm)
OpenPGP clear signs a String Example usage: |
java.lang.String |
clearSignStringVersion3(java.lang.String stringToSign,
java.lang.String privateKeyFileName,
java.lang.String privateKeyPassword,
HashAlgorithm 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. |
boolean |
decryptAndVerifyFile(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). |
boolean |
decryptAndVerifyFile(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). |
boolean |
decryptAndVerifyFileTo(java.lang.String encryptedFileName,
KeyStore keyStore,
java.lang.String privateKeyPassword,
java.lang.String outputFolder)
Decrypts and verifies one pass encrypted and signed OpenPGP file Supports OpenPGP version 3 format too (used by PGP 6.5 and below). |
boolean |
decryptAndVerifyFileTo(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. |
boolean |
decryptAndVerifyStream(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. |
boolean |
decryptAndVerifyStream(java.io.InputStream encryptedStream,
KeyStore keyStore,
java.lang.String privateKeyPassword,
java.io.OutputStream outputStream)
Decrypts and verifies OpenPGP encrypted and signed stream. |
boolean |
decryptAndVerifyStreamTo(java.io.InputStream encryptedStream,
java.io.InputStream privateKeyStream,
java.lang.String privateKeyPassword,
java.io.InputStream publicKeyStream,
java.lang.String outputFolder)
Decrypts and verifies OpenPGP encrypted and signed stream. |
boolean |
decryptAndVerifyStreamTo(java.io.InputStream encryptedStream,
KeyStore keyStore,
java.lang.String privateKeyPassword,
java.lang.String outputFolder)
Decrypts and verifies OpenPGP encrypted and signed stream. |
boolean |
decryptAndVerifyString(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. |
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)
Decrypts and verifies an OpenPGP one pass signed end encrypted message. |
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 Private key input stream. |
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. |
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 data stream contents. |
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. |
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(CompressionAlgorithm)
Symmetric cipher algorithm used is the one specified with setCypher(CypherAlgorithm)
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(CompressionAlgorithm)
Symmetric cipher algorithm used is the one specified with setCypher(CypherAlgorithm)
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(CompressionAlgorithm)
Symmetric cipher algorithm used is the one specified with setCypher(CypherAlgorithm)
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(CompressionAlgorithm)
Symmetric cipher algorithm used is the one specified with setCypher(CypherAlgorithm)
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(CompressionAlgorithm) 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(CompressionAlgorithm)
Symmetric cipher algorithm used is the one specified with setCypher(CypherAlgorithm)
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(CompressionAlgorithm)
Symmetric cipher algorithm used is the one specified with setCypher(CypherAlgorithm)
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 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(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(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(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,
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(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,
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(CompressionAlgorithm) 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(CompressionAlgorithm) if supported
by the public key, otherwise the first supported by the key algorithm is used. |
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 |
CompressionAlgorithm |
getCompression()
Returns the preferred compression algorithm used by all methods that produce OpenPGP messages (e.g Encrypt, Sign, etc.) Default is ZIP |
CypherAlgorithm |
getCypher()
Returns the preferred symmetric key algorithm used by all methods that produce OpenPGP messages (e.g Encrypt, Sign, etc.) Default is CAST5 |
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(CompressionAlgorithm compression)
Sets the preferred compression algorithm used by all methods that produce OpenPGP messages (e.g Encrypt, Sign, etc.) |
void |
setCypher(CypherAlgorithm cypher)
Sets the preferred symmetric key algorithm used by all methods that produce OpenPGP messages (e.g Encrypt, Sign, etc.) |
void |
setHash(HashAlgorithm hash)
Sets the preferred hashing algorithm used by all methods that produce OpenPGP signature (all Sign and SigneAndEncrypt methods) |
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(CompressionAlgorithm)
Symmetric cipher algorithm used is the one specified with setCypher(CypherAlgorithm)
Hashing algorithm used is the one specified with setHash(HashAlgorithm)
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(CompressionAlgorithm)
Symmetric cipher algorithm used is the one specified with setCypher(CypherAlgorithm)
Hashing algorithm used is the one specified with setHash(HashAlgorithm)
Example: |
void |
signAndEncryptStream(java.io.InputStream dataFileStream,
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 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 stream in one pass. |
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(CompressionAlgorithm)
Symmetric cipher algorithm used is the one specified with setCypher(CypherAlgorithm)
Hashing algorithm used is the one specified with setHash(HashAlgorithm)
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(CompressionAlgorithm)
Symmetric cipher algorithm used is the one specified with setCypher(CypherAlgorithm)
Hashing algorithm used is the one specified with setHash(HashAlgorithm)
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(CompressionAlgorithm)
Symmetric cipher algorithm used is the one specified with setCypher(CypherAlgorithm)
Hashing algorithm used is the one specified with setHash(HashAlgorithm)
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(CompressionAlgorithm)
Symmetric cipher algorithm used is the one specified with setCypher(CypherAlgorithm)
Hashing algorithm used is the one specified with setHash(HashAlgorithm)
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(CompressionAlgorithm)
Hashing algorithm used is the one specified with setHash(HashAlgorithm)
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(CompressionAlgorithm)
Hashing algorithm used is the one specified with setHash(HashAlgorithm)
Example: |
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)
Verifies the incoming file as being correctly signed. |
boolean |
verifyFile(java.lang.String dataFileName,
java.lang.String publicKeyFileName)
Verifies the incoming file as being correctly signed. |
boolean |
verifyFile(java.lang.String dataFileName,
java.lang.String publicKeyFileName,
java.lang.String outputFileName)
Verifies the incoming file as being correctly signed. |
boolean |
verifyStream(java.io.InputStream dataFileStream,
java.io.InputStream publicKeyStream)
Verifies the incoming stream as being correctly signed. |
boolean |
verifyStream(java.io.InputStream dataFileStream,
java.io.InputStream publicKeyStream,
java.io.OutputStream outputFileStream)
Verifies the incoming stream as being correctly signed. |
boolean |
verifyStream(java.io.InputStream dataFileStream,
KeyStore keyStore,
java.io.OutputStream outputFileStream)
Verifies the incoming stream as being correctly signed. |
boolean |
verifyString(java.lang.String message,
java.lang.String publicKeyFileName,
java.lang.StringBuffer decryptedString)
Verifies an OpenPGP signed only message. |
boolean |
verifyString(java.lang.String message,
java.lang.String publicKeyFileName,
java.lang.StringBuffer decryptedString,
java.lang.String charsetName)
Verifies an OpenPGP signed only message. |
Methods inherited from class com.didisoft.pgp.bc.BaseLib |
---|
isForVerification, makeKeyFromPassPhrase, makeKeyFromPassPhrase |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PGPLib()
Method Detail |
---|
public boolean isUseExpiredKeys()
public void setUseExpiredKeys(boolean value)
public boolean isUseRevokedKeys()
public void setUseRevokedKeys(boolean value)
public void setHash(HashAlgorithm hash)
HashAlgorithm
public CypherAlgorithm getCypher()
CypherAlgorithm
public java.lang.String getAsciiCommentHeader()
public java.lang.String getAsciiVersionHeader()
public void setAsciiVersionHeader(java.lang.String creator)
PGPLib pgp = new PGPLib(); pgp.setAsciiVersionHeader("My Application 1.1"); // Now in ASCII armored output will be printed "Version: My Application 1.1"
creator
- Program name and version that will be written in ASCII armored output Version: fieldpublic void setCypher(CypherAlgorithm cypher)
CypherAlgorithm
public CompressionAlgorithm getCompression()
CompressionAlgorithm
public void setCompression(CompressionAlgorithm compression)
CompressionAlgorithm
public boolean detachedVerifyStream(java.io.InputStream dataFileStream, java.io.InputStream detachedSignatureStream, java.io.InputStream publicKeyStream) throws PGPException, java.io.IOException
dataFileStream
- Input stream from the File to be verifieddetachedSignatureStream
- Detached signature as streampublicKeyStream
- Input stream from the Public key
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 messagepublic boolean detachedVerifyStream(java.io.InputStream dataFileStream, java.io.InputStream detachedSignatureStream, KeyStore keyStore) throws PGPException, java.io.IOException
dataFileStream
- Input stream from the File to be verifieddetachedSignatureStream
- Detached signature as streamkeyStore
- KeyStore containing a public key that can verify the signature
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 messagepublic 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
setHash(HashAlgorithm)
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.detachedSignStream(dataFileName, privateKeyFileName, "private key password", detachedSignatureFile, asciiArmor); } }
dataFileName
- File name for which an OpenPGP detached signature will be created (absolute or relative path)privateKeyFileName
- Private key file (absolute or relative path)privateKeyPassword
- Private key passworddetachedSignatureFileName
- 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
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 incorrectpublic 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
setHash(HashAlgorithm)
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(); } } }
dataStream
- Data stream for which a detached signature is to be createdprivateKeyStream
- Private key as stream, used for signingprivateKeyPassword
- Private key passwordoutStream
- Output stream where the detached signature will be storedasciiArmor
- if true, output file is in ASCII armored format
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 incorrectpublic 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
setHash(HashAlgorithm)
dataStream
- Data stream for which a detached signature is to be createdkeyStore
- KeyStore instance containing the private key used for signingkeyId
- Key Id of the private key that will be used for signingprivateKeyPassword
- Private key passwordoutStream
- Output stream where the detached signature will be storedasciiArmor
- if true, output file is in ASCII armored format
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 incorrectpublic void detachedSignStream(java.io.InputStream dataStream, KeyStore keyStore, java.lang.String userId, java.lang.String privateKeyPassword, java.io.OutputStream outStream, boolean asciiArmor) throws PGPException, java.io.IOException
setHash(HashAlgorithm)
dataStream
- Data stream for which a detached signature is to be createdkeyStore
- KeyStore instance containing the private key used for signinguserId
- The first private key with this User Id will be used for signing.privateKeyPassword
- Private key passwordoutStream
- Output stream where the detached signature will be storedasciiArmor
- if true, output file is in ASCII armored format
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 incorrectpublic void clearSignFile(java.lang.String inputFileName, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, HashAlgorithm hashingAlgorithm, java.lang.String outputFileName) throws PGPException, java.io.IOException, WrongPasswordException
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"); } }
inputFileName
- File name to be clear signed (absolute or relative path)privateKeyFileName
- Private Key file (absolute or relative path)privateKeyPassword
- Private key passwordhashingAlgorithm
- Hashing algorithm, one of: SHA256, SHA384, SHA512, SHA224, SHA1, MD5, RIPEMD160, MD2outputFileName
- Output file name (absolute or relative path)
java.io.IOException
- If a file/stream operation throws an exception
org.spongycastle.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
HashAlgorithm
public void clearSignFileVersion3(java.lang.String inputFileName, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, HashAlgorithm hashingAlgorithm, java.lang.String outputFileName) throws PGPException, java.io.IOException, WrongPasswordException
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"); } }
inputFileName
- File name to be clear signed (absolute or relative path)privateKeyFileName
- Private Key file (absolute or relative path)privateKeyPassword
- Private key passwordhashingAlgorithm
- Hashing algorithm, one of: SHA256, SHA384, SHA512, SHA224, SHA1, MD5, RIPEMD160, MD2outputFileName
- Output file name (absolute or relative path)
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
HashAlgorithm
,
#clearSignString(String, String, String, String)
public java.lang.String clearSignString(java.lang.String stringToSign, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, HashAlgorithm hashingAlgorithm) throws PGPException, java.io.IOException, WrongPasswordException
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); } }
stringToSign
- String message to be signedprivateKeyFileName
- Private Key file (absolute or relative path)privateKeyPassword
- Private key passwordhashingAlgorithm
- Hashing algorithm, one of: SHA256, SHA384, SHA512, SHA224, SHA1, MD5, RIPEMD160, MD2
java.io.IOException
- If a file/stream operation throws an exception
org.spongycastle.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
#clearSignStringVersion3(String, String, String, String)
,
HashAlgorithm
public java.lang.String clearSignStringVersion3(java.lang.String stringToSign, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword, HashAlgorithm hashingAlgorithm) throws PGPException, java.io.IOException, WrongPasswordException
stringToSign
- String message to be signedprivateKeyFileName
- Private Key file (absolute or relative path)privateKeyPassword
- Private key passwordhashingAlgorithm
- Hashing algorithm, one of: SHA256, SHA384, SHA512, SHA224, SHA1, MD5, RIPEMD160, MD2.
HashAlgorithm
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
#clearSignFileVersion3(String, String, String, String, String)
,
verifyFile(String, String, String)
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
setCompression(CompressionAlgorithm)
setHash(HashAlgorithm)
dataFileName
- File name to be encrypted (absolute or relative path)keyStore
- Key store instance containing the private key to be used for signingkeyIdHex
- key ID of the Public Key in Hex formatprivateKeyPassword
- Private key passwordoutputFileName
- File name of the Output encrypted file (absolute or relative path)
PGPException
- OpenPGP encryption error
WrongPasswordException
- If the private key password is incorrect
java.io.IOException
- I/O error
KeyIsExpiredException
- If the key is expired. Extends PGPException
KeyIsRevokedException
- If the key is revoked. Extends PGPException
verifyFile(String, String, String)
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
setCompression(CompressionAlgorithm)
setHash(HashAlgorithm)
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"); } }
dataFileName
- File name to be encrypted (absolute or relative path)keyStore
- Key store containing the private key to be used for signingprivateKeyId
- Key Id of the private key to be used for signingprivateKeyPassword
- Private key passwordoutputFileName
- File name of the output signed file (absolute or relative path)
org.spongycastle.openpgp.PGPException
- OpenPGP encryption error
WrongPasswordException
- If the private key password is incorrect
java.io.IOException
- I/O error
KeyIsExpiredException
- If the key is expired. Extends PGPException
KeyIsRevokedException
- If the key is revoked. Extends PGPException
PGPException
verifyFile(String, KeyStore, String)
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
setCompression(CompressionAlgorithm)
setHash(HashAlgorithm)
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); } }
dataFileName
- File name to be encrypted (absolute or relative path)keyStore
- Key store containing the private key to be used for signingprivateKeyUserId
- signing key User IdprivateKeyPassword
- signing key passwordoutputFileName
- 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
org.spongycastle.openpgp.PGPException
- OpenPGP encryption error
WrongPasswordException
- If the private key password is incorrect
java.io.IOException
- I/O error
KeyIsExpiredException
- If the key is expired. Extends PGPException
KeyIsRevokedException
- If the key is revoked. Extends PGPException
PGPException
verifyFile(String, KeyStore, String)
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
setCompression(CompressionAlgorithm)
setHash(HashAlgorithm)
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); } }
dataFileName
- File name to be encrypted (absolute or relative path)keyStore
- Key store containing the private key to be used for signingprivateKeyId
- signing key IdprivateKeyPassword
- signing key passwordoutputFileName
- 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
PGPException
- OpenPGP encryption error
WrongPasswordException
- If the private key password is incorrect
java.io.IOException
- I/O error
KeyIsExpiredException
- If the key is expired. Extends PGPException
KeyIsRevokedException
- If the key is revoked. Extends PGPException
verifyFile(String, KeyStore, String)
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
setCompression(CompressionAlgorithm)
setHash(HashAlgorithm)
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); } }
inputFileName
- File Name to be OpenPGP Signed (absolute or relative path)privateKeyFileName
- Private Key file (absolute or relative path)privateKeyPassword
- Private key passwordoutputFileName
- 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
java.io.IOException
- If a file/stream operation throws an exception
PGPException
- OpenPGP encryption error
WrongPasswordException
- If the private key password is incorrect
NoPrivateKeyFoundException
- If privateKeyFileName does not contain an OpenPGP private key. Extends PGPException
KeyIsExpiredException
- If the key is expired. Extends PGPException
KeyIsRevokedException
- If the key is revoked. Extends PGPException
verifyFile(InputStream, InputStream)
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
setCompression(CompressionAlgorithm)
setHash(HashAlgorithm)
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); } }
fileName
- File Name to be signed (absolute or relative path)privateKeyStream
- Private Key input streamout
- Output Stream signedprivateKeyPassword
- Private key passwordasciiArmor
- if true
output stream is in ASCII armored format,
when false
output stream is in binary format
java.io.IOException
- If a file/stream operation throws an exception
PGPException
- OpenPGP encryption error
NoPrivateKeyFoundException
- If privateKeyStream does not contain an OpenPGP private key. Extends PGPException
WrongPasswordException
- If the specified password for the private key is incorrect
KeyIsExpiredException
- If the key is expired. Extends PGPException
KeyIsRevokedException
- If the key is revoked. Extends PGPException
verifyStream(InputStream, InputStream, OutputStream)
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
setCompression(CompressionAlgorithm)
setHash(HashAlgorithm)
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); } }
dataInputStream
- InputStream containing data to be signedfileNameLabel
- File name string to be associated with the data stream in the produced OpenPGP archive.privateKeyStream
- Private key input streamsignedStream
- Output stream signedprivateKeyPassword
- Private key passwordasciiArmor
- if true
output stream is in ASCII armored format,
when false
output stream is in binary format
java.io.IOException
- If a file/stream operation throws an exception
PGPException
- OpenPGP encryption error
NoPrivateKeyFoundException
- If privateKeyStream does not contain an OpenPGP private key. Extends PGPException
WrongPasswordException
- If the specified password for the private key is incorrect
KeyIsExpiredException
- If the key is expired. Extends PGPException
KeyIsRevokedException
- If the key is revoked. Extends PGPException
verifyStream(InputStream, InputStream, OutputStream)
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
setCompression(CompressionAlgorithm)
setHash(HashAlgorithm)
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); } }
dataInputStream
- InputStream containing data to be signedfileNameLabel
- File name string to be associated with the data stream in the produced OpenPGP archive.keyStore
- KeyStore containing the private key for signingsigningKeyUserId
- Primary User Id of the private keyprivateKeyPassword
- Private key passwordsignedStream
- Output stream signedasciiArmor
- if true
output stream is in ASCII armored format,
when false
output stream is in binary format
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
verifyStream(InputStream, KeyStore, OutputStream)
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
setCompression(CompressionAlgorithm)
setHash(HashAlgorithm)
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); } }
dataInputStream
- InputStream containing data to be signedfileNameLabel
- File name string to be associated with the data stream in the produced OpenPGP archive.keyStore
- KeyStore containing the private key for signingsigningKeyId
- Key Id of the private keyprivateKeyPassword
- Private key passwordsignedStream
- Output stream signedasciiArmor
- if true
output stream is in ASCII armored format,
when false
output stream is in binary format
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
verifyStream(InputStream, KeyStore, OutputStream)
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
setCompression(CompressionAlgorithm)
setHash(HashAlgorithm)
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); } }
fileName
- File Name to be signed (absolute or relative path)privateKeyFileName
- Private Key file (absolute or relative path)privateKeyPassword
- Private Key passwordoutputFileName
- 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
java.io.IOException
- I/O error
PGPException
- OpenPGP encryption error
NoPrivateKeyFoundException
- If privateKeyFileName does not contain an OpenPGP private key. Extends PGPException
WrongPasswordException
- If the specified password for the private key is incorrect. Extends PGPException
KeyIsExpiredException
- If the key is expired. Extends PGPException
KeyIsRevokedException
- If the key is revoked. Extends PGPException
verifyFile(String, String, String)
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
setCompression(CompressionAlgorithm)
setHash(HashAlgorithm)
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); } }
dataFileStream
- File data input stream, to be signedinternalFileName
- File name to be associated with the data stream in the produced OpenPGP archiveprivateKeyStream
- Private Key input streamout
- Output Stream signedprivateKeyPassword
- Private key passwordasciiArmor
- if true
output is in ASCII armored format,
when false
output is in binary format
java.io.IOException
- If a file/stream operation throws an exception
org.spongycastle.openpgp.PGPException
- OpenPGP encryption error
NoPrivateKeyFoundException
- If privateKeyStream does not contain an OpenPGP private key. Extends PGPException
WrongPasswordException
- If the specified password for the private key is incorrect
KeyIsExpiredException
- If the key is expired. Extends PGPException
KeyIsRevokedException
- If the key is revoked. Extends PGPException
PGPException
verifyStream(InputStream, InputStream, OutputStream)
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
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
setHash(HashAlgorithm)
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); } }
dataFileName
- File Name to be OpenPGP signed and encrypted (absolute or relative path)privateKeyFileName
- Private Key file (absolute or relative path), used for signingprivateKeyPassword
- Private key passwordpublicKeyFile
- Public key file (absolute or relative path), used for encryptionoutputFileName
- 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
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
NoPublicKeyFoundException
- If publicKeyFileName does not contain an OpenPGP public key. Extends PGPException
WrongPasswordException
- If the specified password for the private key is incorrect. Extends PGPException
KeyIsExpiredException
- If the public (encryption) or private (signing) key is expired. Extends PGPException
KeyIsRevokedException
- If the public (encryption) or private (signing) key is revoked. Extends PGPException
decryptAndVerifyFile(String, String, String, String, String)
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
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
setHash(HashAlgorithm)
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); } }
dataFileName
- File Name to be OpenPGP signed and encrypted (absolute or relative path)privateKeyFileName
- Private Key file (absolute or relative path), used for signingprivateKeyPassword
- Private key passwordpublicKeyFile
- Public key file (absolute or relative path), used for encryptionoutputFileName
- 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 formatwithIntegrityCheck
- Should integrity check be added to the output file.
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
NoPublicKeyFoundException
- If publicKeyFileName does not contain an OpenPGP public key. Extends PGPException
WrongPasswordException
- If the specified password for the private key is incorrect. Extends PGPException
KeyIsExpiredException
- If the public (encryption) or private (signing) key is expired. Extends PGPException
KeyIsRevokedException
- If the public (encryption) or private (signing) key is revoked. Extends PGPException
decryptAndVerifyFile(String, String, String, String, String)
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
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
setHash(HashAlgorithm)
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); } }
dataFileName
- File Name to be OpenPGP signed and encrypted (absolute or relative path)privateKeyFileName
- Private Key file (absolute or relative path), used for signingprivateKeyPassword
- Private key passwordpublicKeyFiles
- Public key files that will be used for encryption (absolute or relative paths)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 formatwithIntegrityCheck
- Should integrity check be added to the output file.
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
NoPublicKeyFoundException
- If publicKeyFileName does not contain an OpenPGP public key. Extends PGPException
WrongPasswordException
- If the specified password for the private key is incorrect. Extends PGPException
KeyIsExpiredException
- If the public (encryption) or private (signing) key is expired. Extends PGPException
KeyIsRevokedException
- If the public (encryption) or private (signing) key is revoked. Extends PGPException
decryptAndVerifyFile(String, String, String, String, String)
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
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
setHash(HashAlgorithm)
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); } }
fileName
- File Name to be OpenPGP Signed (absolute or relative path)privateKeyStream
- Private Key input stream (used for signing)privateKeyPassword
- Private key passwordpublicKeyStream
- Public Key input stream (used for encryption)outputStream
- Output Stream signed and encryptedasciiArmor
- if true
output is in ASCII armored format,
when false
output is in binary formatwithIntegrityCheck
- Should integrity check be added to the file.
java.io.IOException
- If a file/stream operation throws an exception
PGPException
- OpenPGP encryption error
NoPrivateKeyFoundException
- If privateKeyStream does not contain an OpenPGP private key. Extends PGPException
NoPublicKeyFoundException
- If publicKeyStream does not contain an OpenPGP public key. Extends PGPException
WrongPasswordException
- If the private key password is incorrect. Extends PGPException
KeyIsExpiredException
- If the public (encryption) or private (signing) key is expired. Extends PGPException
KeyIsRevokedException
- If the public (encryption) or private (signing) key is revoked. Extends PGPException
decryptAndVerifyStream(InputStream, InputStream, String, InputStream, OutputStream)
public void signAndEncryptStream(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, NoPublicKeyFoundException, NoPrivateKeyFoundException
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
setHash(HashAlgorithm)
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); } }
dataFileStream
- Data input stream to be signedinternalFileName
- 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 passwordpublicKeyStream
- Public Key input stream (used for encryption)outputStream
- Output Stream signed and encryptedasciiArmor
- if true
output is in ASCII armored format, when false
output is in binary formatwithIntegrityCheck
- Should integrity check be added to the file.
java.io.IOException
- If a file/stream operation throws an exception
PGPException
- OpenPGP encryption error
NoPrivateKeyFoundException
- If privateKeyStream does not contain an OpenPGP private key. Extends PGPException
NoPublicKeyFoundException
- If publicKeyStream does not contain an OpenPGP public key. Extends PGPException
WrongPasswordException
- If the private key password is incorrect. Extends PGPException
KeyIsExpiredException
- If the public (encryption) or private (signing) key is expired. Extends PGPException
KeyIsRevokedException
- If the public (encryption) or private (signing) key is revoked. Extends PGPException
decryptAndVerifyStream(InputStream, InputStream, String, InputStream, OutputStream)
public void signAndEncryptStream(java.io.InputStream dataFileStream, 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
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
setHash(HashAlgorithm)
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); } }
dataFileStream
- Data input stream to be signedinternalFileName
- 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 passwordpublicKeyStreams
- Public Key input streams (used for encryption)outputStream
- Output Stream signed and encryptedasciiArmor
- if true
output is in ASCII armored format, when false
output is in binary formatwithIntegrityCheck
- Should integrity check be added to the file.
java.io.IOException
- If a file/stream operation throws an exception
PGPException
- OpenPGP encryption error
NoPrivateKeyFoundException
- If privateKeyStream does not contain an OpenPGP private key. Extends PGPException
NoPublicKeyFoundException
- If publicKeyStream does not contain an OpenPGP public key. Extends PGPException
WrongPasswordException
- If the private key password is incorrect. Extends PGPException
KeyIsExpiredException
- If the public (encryption) or private (signing) key is expired. Extends PGPException
KeyIsRevokedException
- If the public (encryption) or private (signing) key is revoked. Extends PGPException
decryptAndVerifyStream(InputStream, InputStream, String, InputStream, OutputStream)
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
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
setHash(HashAlgorithm)
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); } }
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 encryptionsignUserId
- User Id of the private key for signing of the form "name (comment) <email address>"privateKeyPassword
- Private key passwordencUserId
- User Id of the public encryption key of the form "name (comment) <email address>"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 formatwithIntegrityCheck
- if true
integrity check information is added to the output file.
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
verifyFile(String, String, String)
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
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
setHash(HashAlgorithm)
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); } }
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 encryptionsignUserId
- User Id of the private key for signing of the form "name (comment) <email address>"privateKeyPassword
- Private key passwordencUserIds
- Array of User Id's of the public keys that will be used for encryptionoutputFileName
- 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 formatwithIntegrityCheck
- if true
integrity check information is added to the output file.
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
decryptAndVerifyFileTo(String, KeyStore, String, String)
,
decryptAndVerifyFile(String, KeyStore, String, String)
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
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
setHash(HashAlgorithm)
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); } }
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 encryptionsignKeyId
- Key Id of the private key for signingprivateKeyPassword
- Private key passwordencKeyIds
- Key Id's of the public keys that will be used for encryptionoutputFileName
- 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 formatwithIntegrityCheck
- if true
integrity check information is added to the output file.
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
decryptAndVerifyFileTo(String, KeyStore, String, String)
,
decryptAndVerifyFile(String, KeyStore, String, String)
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
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
setHash(HashAlgorithm)
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); } }
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 encryptionsignKeyId
- Key Id of the private key for signingprivateKeyPassword
- Private key passwordencKeyId
- Key Id of the public encryption keyoutputFileName
- 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 formatwithIntegrityCheck
- if true
integrity check information is added to the output file.
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
decryptAndVerifyFileTo(String, KeyStore, String, String)
,
decryptAndVerifyFile(String, KeyStore, String, String)
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
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
setHash(HashAlgorithm)
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); } }
dataFileStream
- File data input stream, to be signedinternalFileName
- 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 encryptionsignUserId
- userId of the private key for signing of the form "name (comment) <email address>"privateKeyPassword
- Private key passwordencUserId
- userId of the public key for encryption of the form "name (comment) <email address>"outputStream
- Output Stream signed and encryptedasciiArmor
- if true
output is in ASCII armored format,
when false
output is in binary formatwithIntegrityCheck
- should integrity check be added to the file.
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
verifyStream(InputStream, KeyStore, OutputStream)
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
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
setHash(HashAlgorithm)
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); } }
dataFileName
- File Name to be OpenPGP signed and encrypted (absolute or relative path)privateKeyFileName
- Private Key file (absolute or relative path), used for signingprivateKeyPassword
- Private key passwordpublicKeyFile
- Public key file (absolute or relative path), used for encryptionoutputFileName
- 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
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
decryptAndVerifyFile(String, String, String, String, String)
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
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
setHash(HashAlgorithm)
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); } }
dataFileName
- File Name to be OpenPGP signed and encrypted (absolute or relative path)privateKeyFileName
- Private Key file (absolute or relative path), used for signingprivateKeyPassword
- Private key passwordpublicKeyFile
- Public key file (absolute or relative path), used for encryptionoutputFileName
- 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 formatwithIntegrityCheck
- 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.
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
decryptAndVerifyFile(String, String, String, String, String)
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
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
setHash(HashAlgorithm)
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); } }
dataFileStream
- File data input stream, to be signedinternalFileName
- 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 passwordpublicKeyStream
- Public Key input stream (used for encryption)outputStream
- Output Stream signed and encryptedasciiArmor
- if true
output is in ASCII armored format,
when false
output is in binary format
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
NoPublicKeyFoundException
- If publicKeyFileName does not contain an OpenPGP public key. Extends PGPException
WrongPasswordException
- If the private key password is incorrect
KeyIsExpiredException
- If the public (encryption) or private (signing) key is expired. Extends PGPException
KeyIsRevokedException
- If the public (encryption) or private (signing) key is revoked. Extends PGPException
decryptAndVerifyStream(InputStream, InputStream, String, InputStream, OutputStream)
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
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
setHash(HashAlgorithm)
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); } }
dataFileStream
- File data input stream, to be signedinternalFileName
- 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 passwordpublicKeyStream
- Public Key input stream (used for encryption)outputStream
- Output Stream signed and encryptedasciiArmor
- if true
output is in ASCII armored format,
when false
output is in binary formatwithIntegrityCheck
- 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.
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
decryptAndVerifyStream(InputStream, InputStream, String, InputStream, OutputStream)
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
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
setHash(HashAlgorithm)
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); } }
stringToEncrypt
- String message to be signed and encrypted in one passprivateKeyFileName
- Private Key (used for signing)privateKeyPassword
- Private key passwordpublicKeyFileName
- Public Key (used for encryption)
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
NoPublicKeyFoundException
- If publicKeyFileName does not contain an OpenPGP public key. Extends PGPException
WrongPasswordException
- If the private key password is incorrect. Extends PGPException
KeyIsExpiredException
- If the public (encryption) or private (signing) key is expired. Extends PGPException
KeyIsRevokedException
- If the public (encryption) or private (signing) key is revoked. Extends PGPException
decryptAndVerifyStream(InputStream, InputStream, String, InputStream, OutputStream)
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
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
setHash(HashAlgorithm)
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); } }
stringToEncrypt
- String message to be signed and encrypted in one passprivateKeyFileName
- Private Key (used for signing)privateKeyPassword
- Private key passwordpublicKeyFileName
- Public Key (used for encryption)
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
NoPublicKeyFoundException
- If publicKeyFileName does not contain an OpenPGP public key. Extends PGPException
WrongPasswordException
- If the private key password is incorrect. Extends PGPException
KeyIsExpiredException
- If the public (encryption) or private (signing) key is expired. Extends PGPException
KeyIsRevokedException
- If the public (encryption) or private (signing) key is revoked. Extends PGPException
decryptAndVerifyStream(InputStream, InputStream, String, InputStream, OutputStream)
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
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
setHash(HashAlgorithm)
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); } }
stringToEncrypt
- String message to be signed and encrypted in one passprivateKeyFileName
- Private Key (used for signing)privateKeyPassword
- Private key passwordpublicKeyFileName
- Public Key (used for encryption)charsetName
- the name of a supported
charset
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
NoPublicKeyFoundException
- If publicKeyFileName does not contain an OpenPGP public key. Extends PGPException
WrongPasswordException
- If the private key password is incorrect. Extends PGPException
KeyIsExpiredException
- If the public key is expired. Extends PGPException
KeyIsRevokedException
- If the public key is revoked. Extends PGPException
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
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
setHash(HashAlgorithm)
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); } }
stringToEncrypt
- String message to be signed and encrypted in one passprivateKeyFileName
- Private Key (used for signing)privateKeyPassword
- Private key passwordpublicKeyFileName
- Public Key (used for encryption)charsetName
- the name of a supported
charset
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
NoPublicKeyFoundException
- If publicKeyFileName does not contain an OpenPGP public key. Extends PGPException
WrongPasswordException
- If the private key password is incorrect. Extends PGPException
KeyIsExpiredException
- If the public key is expired. Extends PGPException
KeyIsRevokedException
- If the public key is revoked. Extends PGPException
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
encryptedStream
- Input stream to be decryptedprivateKeyStream
- Private key input streamprivateKeyPassword
- Private key passwordoutputStream
- Output stream for the decrypted contents
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 corruptedencryptStream(InputStream, String, InputStream, OutputStream, boolean, boolean)
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
encryptedStream
- Input stream to be decryptedprivateKeyStream
- Private key input streamprivateKeyPassword
- Private key passwordoutputFolder
- Output folder where the decrypted file(s) will be stored
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 corruptedencryptFiles(String[], String[], String, boolean, boolean)
public java.lang.String[] decryptStreamTo(java.io.InputStream encryptedStream, KeyStore keyStore, java.lang.String privateKeyPassword, java.lang.String outputFolder) throws PGPException, java.io.IOException
encryptedStream
- Input stream to be decryptedkeyStore
- KeyStore containing the decryption private keyprivateKeyPassword
- Private key passwordoutputFolder
- Output folder where the decrypted file(s) will be stored
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 corruptedencryptFiles(String[], KeyStore, String[], String, boolean, boolean)
,
encryptFiles(String[], KeyStore, long[], String, boolean, boolean)
public java.lang.String decryptStream(java.io.InputStream encryptedStream, KeyStore pgpKeyStore, java.lang.String privateKeyPassword, java.io.OutputStream outputStream) throws PGPException, java.io.IOException
encryptedStream
- Input Stream to be decryptedpgpKeyStore
- Instance of KeyStore
, that should contain the Private key to decrypt encryptedStreamprivateKeyPassword
- Private key passwordoutputStream
- Output Stream for the decrypted contents
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 corruptedencryptStream(InputStream, String, KeyStore, String, OutputStream, boolean, boolean)
,
encryptStream(InputStream, String, KeyStore, long, OutputStream, boolean, boolean)
public java.lang.String decryptFile(java.lang.String encryptedFileName, KeyStore pgpKeyStore, java.lang.String privateKeyPassword, java.lang.String outputFileName) throws PGPException, java.io.IOException
encryptedFileName
- File name to be decrypted (absolute or relative path)pgpKeyStore
- Key store object. See KeyStore
privateKeyPassword
- Private key passwordoutputFileName
- File name of the Output decrypted file (absolute or relative path)
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 corruptedencryptFile(String, KeyStore, String, String)
,
encryptFile(String, KeyStore, long, String)
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
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"); }
encryptedFileName
- File name to be decrypted (absolute or relative path)privateKeyFileName
- Private Key file name (absolute or relative path)privateKeyPassword
- Private key passwordoutputFileName
- File name of the Output decrypted file (absolute or relative path).
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 corruptedencryptFile(String, String, String, boolean, boolean)
public java.lang.String decryptFilePBE(java.lang.String encryptedFileName, java.lang.String decryptionPassword, java.lang.String outputFileName) throws PGPException, java.io.IOException
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.decryptFile("encrypted.pgp", "decryption password", "OUTPUT.txt"); } }
encryptedFileName
- File name to be decrypted (absolute or relative path)decryptionPassword
- Password used for symmetric encryption of the input fileoutputFileName
- File name of the Output decrypted file (absolute or relative path).
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 corruptedencryptFilePBE(String, String, String, String, boolean, boolean)
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
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)privateKeyPassword
- Private key passwordoutputFolder
- 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 exceptionPGPException
- if a problem has occurred while decrypting dataNonPGPDataException
- if the encrypted input is not a valid OpenPGP encrypted messageNoPrivateKeyFoundException
- if the supplied private key source does not contain a private key or is corruptedWrongPrivateKeyException
- 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 archiveDetachedSignatureException
- if the encrypted input is a detached OpenPGP signatureIntegrityCheckException
- if the encrypted input is corrupted- See Also:
encryptFiles(String[], String[], String, boolean, boolean)
public java.lang.String[] decryptFileTo(java.lang.String encryptedFileName, KeyStore keyStore, java.lang.String privateKeyPassword, java.lang.String outputFolder) throws PGPException, java.io.IOException
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 keyprivateKeyPassword
- Private key passwordoutputFolder
- 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 exceptionPGPException
- if a problem has occurred while decrypting dataNonPGPDataException
- if the encrypted input is not a valid OpenPGP encrypted messageNoPrivateKeyFoundException
- if the supplied private key source does not contain a private key or is corruptedWrongPrivateKeyException
- 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 archiveDetachedSignatureException
- if the encrypted input is a detached OpenPGP signatureIntegrityCheckException
- if the encrypted input is corrupted- See Also:
encryptFiles(String[], KeyStore, String[], String, boolean, boolean)
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
encryptedFileName
- File name to be decrypted (absolute or relative path)privateKeyStream
- Private Key input streamprivateKeyPassword
- Private key passwordoutputFileName
- File name of the Output decrypted file (absolute or relative path).
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 corruptedencryptFile(String, String, String, boolean, boolean)
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
setCompression(CompressionAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
setCypher(CypherAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
dataStream
- Input Stream to be encryptedfileName
- 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 encryptedpublicKeyFileName
- Key ring file name (absolute or relative path)out
- Output Stream OpenPGP encryptedasciiArmor
- if true
output is in ASCII armored format,
when false
output is in binary format
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
decryptStream(InputStream, InputStream, String, OutputStream)
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
setCompression(CompressionAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
setCypher(CypherAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
dataStream
- Input Stream to be encryptedfileName
- 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 encryptedpublicKeyFileName
- Key ring file name (absolute or relative path)out
- Output Stream OpenPGP encryptedasciiArmor
- if true
output is in ASCII armored format,
when false
output is in binary formatwithIntegrityCheck
- Should integrity check be added to the file.
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
decryptStream(InputStream, InputStream, String, OutputStream)
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
setCompression(CompressionAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
setCypher(CypherAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
dataStream
- Input Stream to be encryptedfileName
- 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 of the form "name (comment) <email address>" (can be seen using KeyStore.listKeys()
)out
- Output Stream OpenPGP encryptedasciiArmor
- 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.
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
decryptStream(InputStream, KeyStore, String, OutputStream)
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
setCompression(CompressionAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
setCypher(CypherAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
dataStream
- Input Stream to be encryptedfileName
- 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 Keyout
- Output Stream OpenPGP encryptedasciiArmor
- Should file be in Armored modewithIntegrityCheck
- Should integrity check be added to the file.
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
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
setCompression(CompressionAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
setCypher(CypherAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
dataStream
- Input Stream to be encryptedfileName
- 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 encryptedpublicKeyStream
- Input stream from the Public keyout
- Output Stream OpenPGP encryptedasciiArmor
- Should file be in Armored modewithIntegrityCheck
- Should integrity check be added to the file.
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
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
setCompression(CompressionAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
setCypher(CypherAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
dataStream
- Input Stream to be encryptedfileName
- 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 keyoutputStream
- Output OpenPGP encrypted streamasciiArmor
- 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.
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
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
setCompression(CompressionAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
setCypher(CypherAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
dataStream
- Input Stream to be encryptedfileName
- 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 keyoutputStream
- Output OpenPGP encrypted streamasciiArmor
- 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.
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
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
setCompression(CompressionAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
setCypher(CypherAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
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); } }
dataStream
- Input Stream to be encryptedfileNameLabel
- 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 storedasciiArmor
- 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.
PGPException
- PGP encryption error
java.io.IOException
- if an error occurs reading dataStreampublic 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
setCompression(CompressionAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
setCypher(CypherAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
dataFileName
- File name to be encrypted (absolute or relative path)publicKeyFileName
- Key ring file name (absolute or relative path)alternativePassword
- Additional passphrase that can be used to decrypt the file instead of using the private keyoutputFileName
- 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.
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
public void encryptFilePBE(java.lang.String dataFileName, java.lang.String password, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck) throws PGPException, java.io.IOException
setCompression(CompressionAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
setCypher(CypherAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
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); } }
dataFileName
- File name to be encrypted (absolute or relative path)password
- Passphrase used to encrypt and decrypt the fileoutputFileName
- 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.
PGPException
- OpenPGP encryption error
java.io.IOException
- in case of an I/O errorpublic void encryptFile(java.lang.String dataFileName, java.lang.String publicKeyFileName, java.lang.String outputFileName, boolean asciiArmor) throws PGPException, java.io.IOException
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
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); } }
dataFileName
- File name to be encrypted (absolute or relative path)publicKeyFileName
- Recipient public key file name (absolute or relative path)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)
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
public void encryptFile(java.lang.String dataFileName, java.lang.String publicKeyFileName, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck) throws PGPException, java.io.IOException
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
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); } }
dataFileName
- File name to be encrypted (absolute or relative path)publicKeyFileName
- Recipient public key file name (absolute or relative path)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.
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
public void encryptFile(java.lang.String dataFileName, java.lang.String[] publicKeysFileNames, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck) throws PGPException, java.io.IOException
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
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); } }
dataFileName
- File name to be encrypted (absolute or relative path)publicKeysFileNames
- Array of recipients' public keys file names (absolute or relative paths)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.
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
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
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
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); } }
dataFileName
- File name to be encrypted (absolute or relative path)keyStore
- KeyStore holding recipients' public keysrecipientsUserIds
- Array of recipients' public keys User Id'soutputFileName
- 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.
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
public void encryptFile(java.lang.String dataFileName, KeyStore keyStore, long[] recipientsKeyIds, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck) throws PGPException, java.io.IOException
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
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); } }
dataFileName
- File name to be encrypted (absolute or relative path)keyStore
- KeyStore holding recipients' public keysrecipientsKeyIds
- Array of recipients' public keys Key Id'soutputFileName
- 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.
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
public void encryptFiles(java.lang.String[] dataFileNames, java.lang.String publicKeyFileName, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck) throws PGPException, java.io.IOException
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
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); } }
dataFileNames
- File names to be encrypted (absolute or relative path)publicKeyFileName
- Recipients public key file name (absolute or relative path)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.
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
public void encryptFiles(java.lang.String[] dataFileNames, java.lang.String[] publicKeysFileNames, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck) throws PGPException, java.io.IOException
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
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); } }
dataFileNames
- File names to be encrypted (absolute or relative path)publicKeysFileNames
- Array of recipients' public keys file names (absolute or relative path)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.
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
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
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
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); } }
dataFileNames
- File names to be encrypted (absolute or relative path)keyStore
- KeyStore
containing the recipients public keysrecipientsUserIds
- Array of recipients' public keys User Id'soutputFileName
- 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.
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
public void encryptFiles(java.lang.String[] dataFileNames, KeyStore keyStore, long[] recipientsKeyIds, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck) throws PGPException, java.io.IOException
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
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); } }
dataFileNames
- File names to be encrypted (absolute or relative path)keyStore
- KeyStore
containing the recipients public keysrecipientsKeyIds
- Array of recipients' public keys Key Id'soutputFileName
- 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.
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
public void encryptFile(java.lang.String dataFileName, java.io.InputStream publicKeyStream, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck) throws PGPException, java.io.IOException
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
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(); } } }
dataFileName
- File name to be encrypted (absolute or relative path)publicKeyStream
- Input stream from the Public key, caller method is responsible for closing itoutputFileName
- 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.
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
public int encryptFileByUserId(KeyStore keyStore, java.lang.String dataFileName, java.lang.String userID, java.lang.String outputFileName)
instead
dataFileName
- File name to be encrypted (absolute or relative path)keyStore
- Key store object. See KeyStore
userID
- User ID of the form "name (comment) <email address>" (can be seen using KeyStore.listKeys()
)outputFileName
- File name of the Output encrypted file (absolute or relative path)
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
setCompression(CompressionAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
setCypher(CypherAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
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); } }
dataFileName
- File name to be encrypted (absolute or relative path)keyStore
- Key store object. See KeyStore
userId
- Recipient public key User Id of the form "name (comment) <email address>"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 formatwithIntegrityCheck
- if true integrity check information is added to the file.
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
decryptFile(String, KeyStore, String, String)
public void encryptFile(java.lang.String dataFileName, KeyStore keyStore, java.lang.String userId, java.lang.String outputFileName) throws PGPException, java.io.IOException
setCompression(CompressionAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
setCypher(CypherAlgorithm)
if supported
by the public key, otherwise the first supported by the key algorithm is used.
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"); } }
dataFileName
- File name to be encrypted (absolute or relative path)keyStore
- Key store object. See KeyStore
userId
- User ID of the form "name (comment) <email address>"outputFileName
- File name of the Output encrypted file (absolute or relative path)
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
decryptFile(String, KeyStore, String, String)
public int encryptFileByKeyId(KeyStore keyStore, java.lang.String dataFileName, java.lang.String keyIdHex, java.lang.String outputFileName)
instead
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 formatoutputFileName
- File name of the Output encrypted file (absolute or relative path)public void encryptFile(java.lang.String dataFileName, KeyStore keyStore, long keyId, java.lang.String outputFileName, boolean asciiArmor, boolean withIntegrityCheck) throws PGPException, java.io.IOException
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
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); } }
dataFileName
- File name to be encrypted (absolute or relative path)keyStore
- Key store object. See KeyStore
keyId
- Key Id of the recipient public keyoutputFileName
- 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 formatwithIntegrityCheck
- if true integrity check information is added to the file.
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
decryptFile(String, KeyStore, String, String)
public void encryptFile(java.lang.String dataFileName, KeyStore keyStore, long keyId, java.lang.String outputFileName) throws PGPException, java.io.IOException
setCompression(CompressionAlgorithm)
setCypher(CypherAlgorithm)
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"); } }
dataFileName
- File name to be encrypted (absolute or relative path)keyStore
- Key store object. See KeyStore
keyId
- Key Id of the Public KeyoutputFileName
- File name of the Output encrypted file (absolute or relative path)
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
decryptFile(String, String, String, String)
public boolean verifyFile(java.lang.String dataFileName, java.lang.String publicKeyFileName, java.lang.String outputFileName) throws PGPException, FileIsEncryptedException, java.io.IOException
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!"); } } }
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)outputFileName
- Output file name, extracted from the signed file (absolute or relative path)
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 signaturesignFile(String, String, String, String, boolean)
,
signFileVersion3(String, String, String, String, boolean)
public boolean verifyFile(java.lang.String dataFileName, KeyStore keyStore, java.lang.String outputFileName) throws PGPException, FileIsEncryptedException, java.io.IOException
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!"); } } }
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 verificationoutputFileName
- Output file name, extracted from the signed file (absolute or relative path)
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 signaturesignFile(String, KeyStore, String, String, String, boolean)
public boolean verifyFile(java.lang.String dataFileName, java.lang.String publicKeyFileName) throws PGPException, FileIsEncryptedException, java.io.IOException
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!"); } } }
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)
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 signaturesignFile(String, String, String, String, boolean)
public boolean verifyFile(java.io.InputStream dataFileStream, java.io.InputStream publicKeyStream) throws PGPException, java.io.IOException
verifyStream(InputStream, InputStream)
dataFileStream
- Input stream from the File to be verifiedpublicKeyStream
- Input stream from the Public key
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 signaturesignStream(InputStream, String, InputStream, String, OutputStream, boolean)
public boolean verifyStream(java.io.InputStream dataFileStream, java.io.InputStream publicKeyStream) throws PGPException, FileIsEncryptedException, java.io.IOException
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(); } } }
dataFileStream
- Input stream from the file to be verifiedpublicKeyStream
- Input stream from the sender public key
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 signaturesignStream(InputStream, String, InputStream, String, OutputStream, boolean)
public boolean verifyStream(java.io.InputStream dataFileStream, java.io.InputStream publicKeyStream, java.io.OutputStream outputFileStream) throws PGPException, FileIsEncryptedException, java.io.IOException
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(); } } }
dataFileStream
- Input stream from the File to be verifiedpublicKeyStream
- Input stream from the Public keyoutputFileStream
- Output Stream for the uncompressed signed content
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 signaturesignStream(InputStream, String, InputStream, String, OutputStream, boolean)
public boolean verifyStream(java.io.InputStream dataFileStream, KeyStore keyStore, java.io.OutputStream outputFileStream) throws PGPException, FileIsEncryptedException, java.io.IOException
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(); } } }
dataFileStream
- Input stream from the File to be verifiedkeyStore
- Key store instance containing the sender public key for verificationoutputFileStream
- Output Stream for the uncompressed signed content
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 signaturesignStream(InputStream, String, InputStream, String, OutputStream, boolean)
public boolean verifyString(java.lang.String message, java.lang.String publicKeyFileName, java.lang.StringBuffer decryptedString) throws java.io.IOException, PGPException, FileIsEncryptedException
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()); } }
message
- OpenPGP signed messagepublicKeyFileName
- The public key of the sender, used to verify the messagedecryptedString
- Output string for the uncompressed signed content
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 signaturepublic boolean verifyString(java.lang.String message, java.lang.String publicKeyFileName, java.lang.StringBuffer decryptedString, java.lang.String charsetName) throws java.io.IOException, PGPException, FileIsEncryptedException
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()); } }
message
- OpenPGP signed messagepublicKeyFileName
- The public key of the sender, used to verify the messagedecryptedString
- Output string for the uncompressed signed contentcharsetName
- the name of a supported
charset
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 signaturepublic 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
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()); } }
message
- OpenPGP signed messageprivateKeyFile
- Private key used for decryptionprivateKeyPassword
- The password of the private keypublicKeyFileName
- The public key of the sender, used to verify the messagedecryptedString
- Output string for the uncompressed signed content
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
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
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()); } }
message
- OpenPGP signed messageprivateKeyFile
- Private key used for decryptionprivateKeyPassword
- The password of the private keypublicKeyFileName
- The public key of the sender, used to verify the messagedecryptedString
- Output string for the uncompressed signed contentcharsetName
- the name of a supported
charset
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 corruptedpublic boolean decryptAndVerifyFile(java.lang.String encryptedFileName, KeyStore keyStore, java.lang.String privateKeyPassword, java.lang.String outputFileName) throws PGPException, java.io.IOException
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 verificationprivateKeyPassword
- Private key passwordoutputFileName
- File name of the Output decrypted file (absolute or relative path).
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 corruptedsignAndEncryptFile(String, KeyStore, String, String, String, String, boolean, boolean)
public boolean decryptAndVerifyFileTo(java.lang.String encryptedFileName, KeyStore keyStore, java.lang.String privateKeyPassword, java.lang.String outputFolder) throws PGPException, java.io.IOException
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 verificationprivateKeyPassword
- Private key passwordoutputFileName
- File name of the Output decrypted file (absolute or relative path).
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 corruptedsignAndEncryptFile(String, KeyStore, String, String, String, String, boolean, boolean)
public boolean decryptAndVerifyStream(java.io.InputStream encryptedStream, KeyStore keyStore, java.lang.String privateKeyPassword, java.io.OutputStream outputStream) throws PGPException, java.io.IOException
encryptedStream
- Input stream with the encrypted contentkeyStore
- Key store instance containing the Private Key for decryption and the other party Public key for verificationprivateKeyPassword
- Private Key passwordoutputStream
- Output stream for the decrypted content
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 corruptedsignAndEncryptStream(InputStream, String, KeyStore, String, String, String, OutputStream, boolean, boolean)
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
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!"); } } }
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 passwordpublicKeyFile
- 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).
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 corruptedsignAndEncryptFile(String, String, String, String, String, boolean, boolean)
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
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!"); } } }
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 passwordpublicKeyFile
- 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
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 corruptedsignAndEncryptFile(String, String, String, String, String, boolean, boolean)
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
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(); } } }
encryptedStream
- Input stream with the encrypted and signed contentprivateKeyStream
- Private Key stream used for decryption. This is usually our own private keyprivateKeyPassword
- Private Key passwordpublicKeyStream
- Public Key stream used for signature verification. This is usually the public key of the senderoutputStream
- Output stream for the decrypted content
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 corruptedsignAndEncryptStream(InputStream, String, InputStream, String, InputStream, OutputStream, boolean, boolean)
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
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(); } } }
encryptedStream
- Input stream with the encrypted and signed contentprivateKeyStream
- Private Key stream used for decryption. This is usually our own private keyprivateKeyPassword
- Private Key passwordpublicKeyStream
- Public Key stream used for signature verification. This is usually the public key of the senderoutputFolder
- Output folder where the decrypted file(s) will be stored
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 corruptedsignAndEncryptStream(InputStream, String, InputStream, String, InputStream, OutputStream, boolean, boolean)
public boolean decryptAndVerifyStreamTo(java.io.InputStream encryptedStream, KeyStore keyStore, java.lang.String privateKeyPassword, java.lang.String outputFolder) throws PGPException, java.io.IOException
encryptedStream
- Input stream with the encrypted contentkeyStore
- Key store instance containing the Private Key for decryption and the other party Public key for verificationprivateKeyPassword
- Private Key passwordoutputFolder
- Output folder where the decrypted file(s) will be stored
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 corruptedsignAndEncryptStream(InputStream, String, KeyStore, String, String, String, OutputStream, boolean, boolean)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |