$cipher
Alias: $crypto
Ensemble de méthodes de chiffrement.
Chiffrement et signature PGP
Le moteur supporte le chiffrement, le déchiffrement, la signature et la
vérification de signature PGP. Un exemple est donné plus bas dans ce
document. Avant d'effectuer ces opérations, il est nécessaire de posséder
une paire de clés PGP.
Pour créer la paire de clé, nous utilisons l'outil gpg en ligne de
commande. Cette opération est à effectuer en-dehors de Ewt, dans un terminal:
| $ gpg --full-generate-key
|
Exemple de méthodes ewts:
| var PRIVKEY = $file.read("/path/to/example.privkey");
var PRIVPWD = "changeit";
var PUBKEY = $file.read("/path/to/example.pubkey");
// chiffrement
var tmp = $cipher.encrypt("/tmp/sourcefile.txt", {
dest: "/tmp/encrypted.pgp",
algo: "PGP",
pubkey: PUBKEY
});
$logger.info("encrypt: " & tmp);
// ➡️ encrypt: /tmp/encrypted.pgp
// déchiffrement
tmp = $cipher.decrypt("/tmp/encrypted.pgp", {
dest: "/tmp/decrypted.txt",
algo: "PGP",
privkey: PRIVKEY,
password: PRIVPWD
});
$logger.info("decrypt: " & tmp);
// ➡️ decrypt: /tmp/decrypted.txt
// signature
tmp = $cipher.sign("/tmp/sourcefile.txt", {
dest: "/tmp/signed.pgp",
algo: "PGP",
privkey: PRIVKEY,
password: PRIVPWD
});
$logger.info("sign: " & tmp);
// ➡️ sign: /tmp/signed.pgp
// signature détachée (armored)
tmp = $cipher.sign("/tmp/sourcefile.txt", {
dest: "/tmp/sourcefile-signature.asc",
algo: "PGP",
privkey: PRIVKEY,
password: PRIVPWD,
detached: true,
armoredOut: true
});
$logger.info("detached sign: " & tmp);
// ➡️ detached sign: /tmp/sourcefile-signature.asc
// vérification de signature
tmp = $cipher.verify("/tmp/signed.pgp", {
algo: "PGP",
pubkey: PUBKEY
});
$logger.info("verify: " & tmp);
// ➡️ verify: true
// vérification de signature détachée
tmp = $cipher.verify("/tmp/sourcefile.txt", {
algo: "PGP",
pubkey: PUBKEY,
signature: "/tmp/sourcefile-signature.asc",
armoredSignature: true
});
$logger.info("verify detached: " & tmp);
// ➡️ verify detached: true
|