Skip to content

qie.pgpDecryptFileWithVerify

Signature: qie.pgpDecryptFileWithVerify(inputFile, outputFile, privateKey, privateKeyPassphrase, publicKey)

Returns: Boolean succeeded - true if decryption was successful

Decrypts inputFile using PGP encryption with the supplied private key and verifies the signature using supplied public key. The output is written to the outputFile.

Note

The privateKey and publicKey must be generated from a system that can generate valid PGP key pairs.

Parameters

Type Name Description Default
String, File inputFile the file to be encrypted
String, File outputFile the output file containing decrypted data
String, File, or byte[] privateKey the PGP private key to use for decrypting data
String privateKeyPassphrase password to unlock the private key for decryption
String, File, or byte[] publicKey the PGP public key to use for signature validation

Example

// Example: inputFile as String path, outputFile as String path,
// privateKey as String path, publicKey as String path
var success = qie.pgpDecryptFileWithVerify(
   "/tmp/encryptedFoot.txt",
   "/tmp/decryptedFoot.dcm",
   "/tmp/pgpPrivate.key",
   "changeit",
   "/tmp/pgpPublic.key"
);

if (success) {
   // File successfully decrypted and signature verified.
} else {
   // Decryption or signature verification failed.
}


// Example: inputFile as File, outputFile as File,
// privateKey as File, publicKey as File
var encryptedFile = qie.newFile("/tmp/encryptedFoot.txt");     // java.io.File
var decryptedFile = qie.newFile("/tmp/decryptedFoot-file.dcm");// java.io.File
var pgpPrivateKeyFile = qie.newFile("/tmp/pgpPrivate.key");    // java.io.File
var pgpPublicKeyFile = qie.newFile("/tmp/pgpPublic.key");      // java.io.File

var successWithFiles = qie.pgpDecryptFileWithVerify(
   encryptedFile,
   decryptedFile,
   pgpPrivateKeyFile,
   "changeit",
   pgpPublicKeyFile
);

if (successWithFiles) {
   // File successfully decrypted and signature verified.
} else {
   // Decryption or signature verification failed.
}


// Example: inputFile as String path, outputFile as String path,
// privateKey as byte[], publicKey as byte[]
var pgpPrivateKeyBytes = qie.readFile("/tmp/pgpPrivate.key");  // byte[]
var pgpPublicKeyBytes = qie.readFile("/tmp/pgpPublic.key");    // byte[]

var successWithByteKeys = qie.pgpDecryptFileWithVerify(
   "/tmp/encryptedFoot.txt",
   "/tmp/decryptedFoot-bytes.dcm",
   pgpPrivateKeyBytes,
   "changeit",
   pgpPublicKeyBytes
);

if (successWithByteKeys) {
   // File successfully decrypted and signature verified.
} else {
   // Decryption or signature verification failed.
}