Key Management
PGP requires a pair of keys: private and public. Use the Public Key
to encrypt the message and use the Private Key
to decrypt it. The Private Key
can be protected by the passphrase.
Upload keys
If you already have a pair of keys, simply upload them to the internal storage.
Step 1. Create a new Server storage Connection.
Step 2. Use the Etlworks Explorer to upload keys.
Generate keys
To generate a pair of keys, use the following JavaScript code:
importPackage(com.toolsverse.util.encryption.pgp);
importPackage(com.toolsverse.config);
// the user, the password, the key length
var publicPrivate = PgpKeyPairGenerator.generateKeyPair("user", "password",
2048);
etlConfig.log("Public key: " + publicPrivate.getKey());
etlConfig.log("Private key: " + publicPrivate.getValue());
Encrypt and Decrypt the message using uploaded keys
To encrypt/decrypt the message using the keys stored in the file, use the following JavaScript code:
importPackage(com.toolsverse.util.encryption.pgp);
importPackage(com.toolsverse.config);
var publicKeyFileName = SystemConfig.instance().getDataFolderName() +
"public_key_file_name";
var privateKeyFileName = SystemConfig.instance().getDataFolderName() +
"private_key_file_name";
var encryped = PgpUtils.encryptStringWithPublicKyeFileName(originalString,
publicKeyFileName);
var decrypted = PgpUtils.decryptStringWithPrivateKeyFileName(encryped,
privateKeyFileName, "password");
Encrypt and Decrypt the message using generated keys
To encrypt/decrypt the message using generated keys, use the following JavaScript code:
importPackage(com.toolsverse.util.encryption.pgp);
importPackage(com.toolsverse.config);
// the user, the password, the key length
var publicPrivate = PgpKeyPairGenerator.generateKeyPair("user", "password",
2048);
var encryped = PgpUtils.encryptStringWithPublicKey(originalString,
publicPrivate.getKey());
var decrypted = PgpUtils.decryptStringWithPrivateKey(encryped,
publicPrivate.getValue(), "password");
Comments
0 comments
Please sign in to leave a comment.