Skip to content

qie.pgpEncryptFileNoSig

Signature: qie.pgpEncryptFileNoSig(inputFile, outputFile, publicKey, asciiArmored*, integrityCheck*)

Returns: Boolean succeeded - true if encryption was successful

Encrypts inputFile using PGP encryption with the supplied public key, no signature will be generated. The output is written to the outputFile.

Note

The 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 the encrypted contents
String, File, or byte[] publicKey the PGP public key to use for encryption
Boolean asciiArmored* (optional) use PGP ascii armored, the encrypted text will be in standard ascii false
Boolean integrityCheck* (optional) use PGP packet integrity check false

Example

// Example: inputFile as String path, outputFile as String path,
// publicKey as String path
var successOnEncryption = qie.pgpEncryptFileNoSig(
   "/tmp/foot.dcm",
   "/tmp/encryptedFoot.txt",
   "/tmp/pgpPublic.key",
   true,
   false
);

var successOnDecryption = qie.pgpDecryptFileWithoutVerify(
   "/tmp/encryptedFoot.txt",
   "/tmp/decryptedFoot.dcm",
   "/tmp/pgpPrivate.key",
   "changeit"
);

if (!successOnEncryption || !successOnDecryption) {
   qie.error("PGP encryption or decryption failed");
}

// /tmp/decryptedFoot.dcm should now match the original /tmp/foot.dcm


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

var successOnEncryptionWithFiles = qie.pgpEncryptFileNoSig(
   inputFile,
   encryptedFile,
   pgpPublicKeyFile,
   true,
   false
);

var successOnDecryptionWithFiles = qie.pgpDecryptFileWithoutVerify(
   encryptedFile,
   decryptedFile,
   pgpPrivateKeyFile,
   "changeit"
);

if (!successOnEncryptionWithFiles || !successOnDecryptionWithFiles) {
   qie.error("PGP encryption or decryption failed");
}


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

var successOnEncryptionWithBytes = qie.pgpEncryptFileNoSig(
   "/tmp/foot.dcm",
   "/tmp/encryptedFoot-bytes.txt",
   pgpPublicKeyBytes,
   true,
   false
);

var successOnDecryptionWithByteKey = qie.pgpDecryptFileWithoutVerify(
   "/tmp/encryptedFoot-bytes.txt",
   "/tmp/decryptedFoot-bytes.dcm",
   pgpPrivateKeyBytes,
   "changeit"
);

if (!successOnEncryptionWithBytes || !successOnDecryptionWithByteKey) {
   qie.error("PGP encryption or decryption failed");
}