diff --git a/packages/nodes-base/nodes/Crypto/Crypto.node.ts b/packages/nodes-base/nodes/Crypto/Crypto.node.ts index f8cd3cec7f33d..fe80f3326169d 100644 --- a/packages/nodes-base/nodes/Crypto/Crypto.node.ts +++ b/packages/nodes-base/nodes/Crypto/Crypto.node.ts @@ -14,6 +14,8 @@ import { createHmac, createSign, getHashes, + randomBytes, + randomUUID, } from 'crypto'; export class Crypto implements INodeType { @@ -52,6 +54,11 @@ export class Crypto implements INodeType { description: 'Sign a string using a private key.', value: 'sign', }, + { + name: 'Generate', + description: 'Generate random data.', + value: 'generate', + }, ], default: 'hash', }, @@ -332,6 +339,73 @@ export class Crypto implements INodeType { default: '', required: true, }, + { + displayName: 'Property Name', + name: 'dataPropertyName', + type: 'string', + default: 'data', + required: true, + displayOptions: { + show: { + action: [ + 'generate', + ], + }, + }, + description: 'Name of the property to which to write the random string.', + }, + { + displayName: 'Type', + name: 'type', + displayOptions: { + show: { + action: [ + 'generate', + ], + }, + }, + type: 'options', + options: [ + { + name: 'ASCII', + value: 'ascii', + }, + { + name: 'Base64', + value: 'base64', + }, + { + name: 'Hex', + value: 'hex', + }, + { + name: 'UUID', + value: 'uuid', + }, + ], + default: 'uuid', + description: 'The random string type to generate.', + required: true, + }, + { + displayName: 'Length', + name: 'stringLength', + displayOptions: { + show: { + action: [ + 'generate', + ], + type: [ + 'ascii', + 'base64', + 'hex', + ], + }, + }, + type: 'number', + default: 32, + description: 'Length of the random string.', + }, ], }; @@ -369,6 +443,24 @@ export class Crypto implements INodeType { item = items[i]; const dataPropertyName = this.getNodeParameter('dataPropertyName', i) as string; + + if (action === 'generate') { + const type = this.getNodeParameter('type', i) as string; + const newItem = { json: {}} as INodeExecutionData; + if ( type === 'uuid') { + newItem.json[dataPropertyName] = randomUUID(); + } else { + const stringLength = this.getNodeParameter('stringLength', i) as number; + if (type === 'base64') { + newItem.json[dataPropertyName] = randomBytes(stringLength).toString(type as BufferEncoding).replace(/\W/g, '').slice(0, stringLength); + } else { + newItem.json[dataPropertyName] = randomBytes(stringLength).toString(type as BufferEncoding).slice(0, stringLength); + } + } + returnData.push(newItem); + continue; + } + const value = this.getNodeParameter('value', i) as string; let newValue;