Skip to content

qie.pgpDecryptBytesWithVerify

Signature: qie.pgpDecryptBytesWithVerify(inputBytes, privateKey, privateKeyPassphrase, publicKey)

Returns: byte[] decryptedBytes - the decrypted contents from the source bytes

Decrypts inputBytes using PGP encryption with the supplied private key and verifies the signature using the supplied public key.

Note

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

Parameters

Type Name Description Default
byte[] inputBytes the bytes to be encrypted
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

// Prepare input bytes to encrypt/sign
var messageBytes = new java.lang.String(
   "Top secret message: The secret lies with Charlotte."
).getBytes("utf-8");


// Example: privateKey as String, publicKey as String (file path strings really)

var encryptedBytes = qie.pgpSignEncryptBytes(
   messageBytes,
   "/tmp/pgpPublic.key",
   "/tmp/pgpPrivate.key",
   "changeit",
   true,
   true
);
var decryptedBytes = qie.pgpDecryptBytesWithVerify(
   encryptedBytes,
   "/tmp/pgpPrivate.key",
   "changeit",
   "/tmp/pgpPublic.key"
);
var originalMessageDecrypted = new java.lang.String(decryptedBytes, "utf-8");


// Example: privateKey as File, publicKey as File
var pgpPrivateKeyFile = qie.newFile("/tmp/pgpPrivate.key"); // java.io.File
var pgpPublicKeyFile = qie.newFile("/tmp/pgpPublic.key");   // java.io.File

var encryptedBytesWithFiles = qie.pgpSignEncryptBytes(
   messageBytes,
   pgpPublicKeyFile,
   pgpPrivateKeyFile,
   "changeit",
   true,
   true
);
var decryptedBytesWithFiles = qie.pgpDecryptBytesWithVerify(
   encryptedBytesWithFiles,
   pgpPrivateKeyFile,
   "changeit",
   pgpPublicKeyFile
);
var originalMessageWithFiles = new java.lang.String(decryptedBytesWithFiles, "utf-8");


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

var encryptedBytesWithByteKeys = qie.pgpSignEncryptBytes(
   messageBytes,
   pgpPublicKeyBytes,
   pgpPrivateKeyBytes,
   "changeit",
   true,
   true
);
var decryptedBytesWithByteKeys = qie.pgpDecryptBytesWithVerify(
   encryptedBytesWithByteKeys,
   pgpPrivateKeyBytes,
   "changeit",
   pgpPublicKeyBytes
);
var originalMessageWithByteKeys = new java.lang.String(decryptedBytesWithByteKeys, "utf-8");