qie.pgpSignEncryptBytes¶
Signature: qie.pgpSignEncryptBytes(inputBytes, publicKey, privateKey, privateKeyPassphrase, asciiArmored*, integrityCheck*)
Returns: byte[] encryptedBytes - the encrypted contents from the source bytes
Encrypts inputBytes using PGP encryption with the supplied public key, a signature using the supplied private key will be generated.
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[] | publicKey | the PGP public key to use for encryption | |
| String, File, or byte[] | privateKey | the PGP private key to use for signature generation | |
| String | privateKeyPassphrase | password to unlock the private key for signature generation | |
| 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¶
// Prepare input bytes to encrypt/sign
var messageBytes = new java.lang.String(
"Top secret message: The secret lies with Charlotte."
).getBytes("utf-8");
// Example: publicKey as String path, privateKey as String path
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 originalMessage = new java.lang.String(decryptedBytes, "utf-8");
// Example: publicKey as File, privateKey as File
var pgpPublicKeyFile = qie.newFile("/tmp/pgpPublic.key"); // java.io.File
var pgpPrivateKeyFile = qie.newFile("/tmp/pgpPrivate.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: publicKey as byte[], privateKey as byte[]
var pgpPublicKeyBytes = qie.readFile("/tmp/pgpPublic.key"); // byte[]
var pgpPrivateKeyBytes = qie.readFile("/tmp/pgpPrivate.key"); // byte[]
var encryptedBytesWithBytes = qie.pgpSignEncryptBytes(
messageBytes,
pgpPublicKeyBytes,
pgpPrivateKeyBytes,
"changeit",
true,
true
);
var decryptedBytesWithBytes = qie.pgpDecryptBytesWithVerify(
encryptedBytesWithBytes,
pgpPrivateKeyBytes,
"changeit",
pgpPublicKeyBytes
);
var originalMessageWithBytes = new java.lang.String(decryptedBytesWithBytes, "utf-8");