Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions pgp-decrypt/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
export function getDescription() {
return {
description: "PGP Decrypt.",
input: [
{
id: "fileToDecrypt",
displayName: "File to be decrypted",
description: "File to be decrypted.",
type: "InputResource",
required: true,
defaultValue: "blob://file.encrypted",
},
{
id: "privateCertificate",
displayName: "Private Certificate",
description: "Private certificate used for decryption.",
type: "Certificate",
required: true,
},
{
id: "decryptedFile",
displayName: "Decrypted file",
description: "Contains the decrypted data (type Connector is used because this files is written and read in this example).",
type: "Connector",
required: true,
defaultValue: "blob://decryptedFile.txt",
},
],
output: [],
} as const satisfies ScriptDescription;
}

export async function execute(context: Context): Promise<Output> {
const fileToDecrypt = context.getFile(context.parameters.fileToDecrypt);
const decryptedFile = context.getFile(context.parameters.decryptedFile);

const privateKey = await importPrivateKey(context);
console.log("Private key imported");

await crypto.subtle.decrypt("PGP", privateKey, fileToDecrypt, decryptedFile);
console.log("File decrypted");

// Only for an example purpose
await checkDecrypted(decryptedFile);
}

async function importPrivateKey(context: Context): Promise<CryptoKey> {
const algorithmParams: PgpParams = { name: "PGP" };
const keyUse: KeyUsage = ["decrypt"];

return await crypto.subtle.importKey("pkcs8fromparameterinput", context.parameters.privateCertificate, algorithmParams, false, keyUse);
}

async function checkDecrypted(decryptedFile: IFile): Promise<void> {
const decryptedData = await decryptedFile.read();
const expectedData = "this will be encrypted"; // This is the original data used in the encryption example

console.log(`Decrypted data: '${decryptedData}' is the same as the original data: '${expectedData}' -> '${decryptedData === expectedData}'`);
if (decryptedData !== expectedData) {
throw new Error("Decrypted data does not match the original data.");
}
}
8 changes: 8 additions & 0 deletions pgp-decrypt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "pgp-decrypt",
"displayName": "PGP Decrypt operation",
"description": "Decrypts a file using PGP.",
"fromVersion": "25.06.1.1",
"toVersion": null,
"private": true
}
68 changes: 68 additions & 0 deletions pgp-encrypt/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
export function getDescription() {
return {
description: "PGP Encrypt.",
input: [
{
id: "fileToEncrypt",
displayName: "File to be encrypted",
description: "File to be encrypted (type Connector used because this files is written and read in this example).",
type: "Connector",
required: true,
defaultValue: "blob://fileToEncrypt.txt",
},
{
id: "publicCertificate",
displayName: "Public Certificate",
description: "Public certificate used for encryption.",
type: "Certificate",
required: true,
},
{
id: "symmetricAlgorithmName",
displayName: "Symmetric algorithm name (Idea, TripleDes, Cast5, Blowfish, Des, Aes128, Aes192, Aes256, Twofish, Camellia128, Camellia192, Camellia256)",
description: "Name of the RSA hash algorithm (Idea, TripleDes, Cast5, Blowfish, Des, Aes128, Aes192, Aes256, Twofish, Camellia128, Camellia192, Camellia256).",
type: "String",
defaultValue: "Aes256",
required: true,
},
{
id: "encryptedFile",
displayName: "Encrypted file",
description: "Contains the encrypted data (type Connector is used because this files is written and read in this example).",
type: "Connector",
required: true,
defaultValue: "blob://file.encrypted",
},
],
output: [],
} as const satisfies ScriptDescription;
}

export async function execute(context: Context): Promise<Output> {
const fileToEncrypt = context.getFile(context.parameters.fileToEncrypt);
const encryptedFile = context.getFile(context.parameters.encryptedFile);

// Example data to encrypt; only for an example purpose
await fileToEncrypt.write("this will be encrypted");
console.log("Example data written to the file for the encryption");

const publicKey = await importPublicKey(context);
console.log("Public key imported");

await crypto.subtle.encrypt("PGP", publicKey, fileToEncrypt, encryptedFile);
console.log("File encrypted");
}

async function importPublicKey(context: Context): Promise<CryptoKey> {
const algorithmParams: PgpParams = {
name: "PGP",
symmetricKeyAlgorithm: context.parameters.symmetricAlgorithmName as PgpSymmetricKeyAlgorithm,
enableArmor: false,
enableIntegrityCheck: true,
compressionAlgorithm: "zlib",
compressionLevel: 6,
};
const keyUse: KeyUsage[] = ["encrypt"];

return await crypto.subtle.importKey("spkifromparameterinput", context.parameters.publicCertificate, algorithmParams, false, keyUse);
}
8 changes: 8 additions & 0 deletions pgp-encrypt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "pgp-encrypt",
"displayName": "PGP Encrypt operation",
"description": "Encrypts a data using PGP.",
"fromVersion": "25.06.1.1",
"toVersion": null,
"private": true
}
70 changes: 70 additions & 0 deletions rsa-decrypt/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
export function getDescription() {
return {
description: "RSA Decrypt.",
input: [
{
id: "fileToDecrypt",
displayName: "File to be decrypted",
description: "File to be decrypted.",
type: "InputResource",
required: true,
defaultValue: "blob://file.encrypted",
},
{
id: "privateCertificate",
displayName: "Private Certificate",
description: "Private certificate used for decryption.",
type: "Certificate",
required: true,
},
{
id: "rsaHashAlgorithmName",
displayName: "RSA hash algorithm name (SHA-1, SHA-256, SHA-384, SHA-512)",
description: "Name of the RSA hash algorithm (SHA-1, SHA-256, SHA-384, SHA-512).",
type: "String",
defaultValue: "SHA-256",
required: true,
},
{
id: "decryptedFile",
displayName: "Decrypted file",
description: "Contains the decrypted data (type Connector is used because this files is written and read in this example).",
type: "Connector",
required: true,
defaultValue: "blob://decryptedFile.txt",
},
],
output: [],
} as const satisfies ScriptDescription;
}

export async function execute(context: Context): Promise<Output> {
const fileToDecrypt = context.getFile(context.parameters.fileToDecrypt);
const decryptedFile = context.getFile(context.parameters.decryptedFile);

const privateKey = await importPrivateKey(context);
console.log("Private key imported");

await crypto.subtle.decrypt("RSA-OAEP", privateKey, fileToDecrypt, decryptedFile);
console.log("File decrypted");

// Only for an example purpose
await checkDecrypted(decryptedFile);
}

async function importPrivateKey(context: Context): Promise<CryptoKey> {
const algorithmParams: RsaOaepParams = { name: "RSA-OAEP", hash: context.parameters.rsaHashAlgorithmName };
const keyUse: KeyUsage = ["decrypt"];

return await crypto.subtle.importKey("pkcs8fromparameterinput", context.parameters.privateCertificate, algorithmParams, false, keyUse);
}

async function checkDecrypted(decryptedFile: IFile): Promise<void> {
const decryptedData = await decryptedFile.read();
const expectedData = "this will be encrypted"; // This is the original data used in the encryption example

console.log(`Decrypted data: '${decryptedData}' is the same as the original data: '${expectedData}' -> '${decryptedData === expectedData}'`);
if (decryptedData !== expectedData) {
throw new Error("Decrypted data does not match the original data.");
}
}
8 changes: 8 additions & 0 deletions rsa-decrypt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "rsa-decrypt",
"displayName": "RSA Decrypt operation",
"description": "Decrypts a file using RSA.",
"fromVersion": "25.06.1.1",
"toVersion": null,
"private": true
}
61 changes: 61 additions & 0 deletions rsa-encrypt/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
export function getDescription() {
return {
description: "RSA Encrypt.",
input: [
{
id: "fileToEncrypt",
displayName: "File to be encrypted",
description: "File to be encrypted (type Connector used because this files is written and read in this example).",
type: "Connector",
required: true,
defaultValue: "blob://fileToEncrypt.txt",
},
{
id: "publicCertificate",
displayName: "Public Certificate",
description: "Public certificate used for encryption.",
type: "Certificate",
required: true,
},
{
id: "rsaHashAlgorithmName",
displayName: "RSA hash algorithm name (SHA-1, SHA-256, SHA-384, SHA-512)",
description: "Name of the RSA hash algorithm (SHA-1, SHA-256, SHA-384, SHA-512).",
type: "String",
defaultValue: "SHA-256",
required: true,
},
{
id: "encryptedFile",
displayName: "Encrypted file",
description: "Contains the encrypted data (type Connector is used because this files is written and read in this example).",
type: "Connector",
required: true,
defaultValue: "blob://file.encrypted",
},
],
output: [],
} as const satisfies ScriptDescription;
}

export async function execute(context: Context): Promise<Output> {
const fileToEncrypt = context.getFile(context.parameters.fileToEncrypt);
const encryptedFile = context.getFile(context.parameters.encryptedFile);

// Example data to encrypt; only for an example purpose
await fileToEncrypt.write("this will be encrypted");
console.log("Example data written to the file for the encryption");

const publicKey = await importPublicKey(context);
console.log("Public key imported");

await crypto.subtle.encrypt("RSA-OAEP", publicKey, fileToEncrypt, encryptedFile);
console.log("File encrypted");
}

async function importPublicKey(context: Context): Promise<CryptoKey> {
const algorithmParams: RsaOaepParams = { name: "RSA-OAEP", hash: context.parameters.rsaHashAlgorithmName };
const keyUse: KeyUsage[] = ["encrypt"];

return await crypto.subtle.importKey("spkifromparameterinput", context.parameters.publicCertificate, algorithmParams, false, keyUse);
}
8 changes: 8 additions & 0 deletions rsa-encrypt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "rsa-encrypt",
"displayName": "RSA Encrypt operation",
"description": "Encrypts a data using RSA.",
"fromVersion": "25.06.1.1",
"toVersion": null,
"private": true
}