2023-06-16 07:26:35 -07:00
|
|
|
import set from 'lodash/set';
|
2022-03-27 01:48:31 -07:00
|
|
|
|
2023-01-27 03:22:44 -08:00
|
|
|
import type {
|
2023-03-09 09:13:15 -08:00
|
|
|
IExecuteFunctions,
|
2020-01-28 14:39:43 -08:00
|
|
|
INodeExecutionData,
|
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
2022-03-27 01:48:31 -07:00
|
|
|
JsonObject,
|
2020-01-28 14:39:43 -08:00
|
|
|
} from 'n8n-workflow';
|
2023-06-02 02:22:21 -07:00
|
|
|
import { deepCopy, BINARY_ENCODING } from 'n8n-workflow';
|
2020-01-28 14:39:43 -08:00
|
|
|
|
2023-01-27 03:22:44 -08:00
|
|
|
import type { BinaryToTextEncoding } from 'crypto';
|
|
|
|
import { createHash, createHmac, createSign, getHashes, randomBytes } from 'crypto';
|
2023-06-02 02:22:21 -07:00
|
|
|
import stream from 'stream';
|
|
|
|
import { promisify } from 'util';
|
2020-01-28 14:39:43 -08:00
|
|
|
|
2022-03-27 01:48:31 -07:00
|
|
|
import { v4 as uuid } from 'uuid';
|
|
|
|
|
2023-06-02 02:22:21 -07:00
|
|
|
const pipeline = promisify(stream.pipeline);
|
|
|
|
|
2023-06-02 06:23:28 -07:00
|
|
|
const unsupportedAlgorithms = [
|
|
|
|
'RSA-MD4',
|
|
|
|
'RSA-MDC2',
|
|
|
|
'md4',
|
|
|
|
'md4WithRSAEncryption',
|
|
|
|
'mdc2',
|
|
|
|
'mdc2WithRSA',
|
|
|
|
];
|
|
|
|
|
|
|
|
const supportedAlgorithms = getHashes()
|
|
|
|
.filter((algorithm) => !unsupportedAlgorithms.includes(algorithm))
|
|
|
|
.map((algorithm) => ({ name: algorithm, value: algorithm }));
|
|
|
|
|
2020-01-28 14:39:43 -08:00
|
|
|
export class Crypto implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
|
|
|
displayName: 'Crypto',
|
|
|
|
name: 'crypto',
|
|
|
|
icon: 'fa:key',
|
|
|
|
group: ['transform'],
|
|
|
|
version: 1,
|
2020-02-07 22:33:53 -08:00
|
|
|
subtitle: '={{$parameter["action"]}}',
|
2020-01-28 14:39:43 -08:00
|
|
|
description: 'Provide cryptographic utilities',
|
|
|
|
defaults: {
|
|
|
|
name: 'Crypto',
|
|
|
|
color: '#408000',
|
|
|
|
},
|
|
|
|
inputs: ['main'],
|
|
|
|
outputs: ['main'],
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
displayName: 'Action',
|
|
|
|
name: 'action',
|
|
|
|
type: 'options',
|
|
|
|
options: [
|
2022-03-27 01:48:31 -07:00
|
|
|
{
|
|
|
|
name: 'Generate',
|
|
|
|
description: 'Generate random string',
|
|
|
|
value: 'generate',
|
2022-07-10 13:50:51 -07:00
|
|
|
action: 'Generate random string',
|
2022-03-27 01:48:31 -07:00
|
|
|
},
|
2020-01-28 14:39:43 -08:00
|
|
|
{
|
|
|
|
name: 'Hash',
|
2023-06-02 02:22:21 -07:00
|
|
|
description: 'Hash a text or file in a specified format',
|
2020-10-22 06:46:03 -07:00
|
|
|
value: 'hash',
|
2023-06-02 02:22:21 -07:00
|
|
|
action: 'Hash a text or file in a specified format',
|
2020-01-28 14:39:43 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Hmac',
|
2023-06-02 02:22:21 -07:00
|
|
|
description: 'Hmac a text or file in a specified format',
|
2020-10-22 06:46:03 -07:00
|
|
|
value: 'hmac',
|
2023-06-02 02:22:21 -07:00
|
|
|
action: 'HMAC a text or file in a specified format',
|
2020-01-28 14:39:43 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Sign',
|
2022-03-27 01:48:31 -07:00
|
|
|
description: 'Sign a string using a private key',
|
2020-10-22 06:46:03 -07:00
|
|
|
value: 'sign',
|
2022-07-10 13:50:51 -07:00
|
|
|
action: 'Sign a string using a private key',
|
2020-01-28 14:39:43 -08:00
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'hash',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Type',
|
|
|
|
name: 'type',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-01 13:47:55 -07:00
|
|
|
action: ['hash'],
|
2020-01-28 14:39:43 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
type: 'options',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'MD5',
|
|
|
|
value: 'MD5',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'SHA256',
|
|
|
|
value: 'SHA256',
|
|
|
|
},
|
2022-10-07 10:15:11 -07:00
|
|
|
{
|
|
|
|
name: 'SHA3-256',
|
|
|
|
value: 'SHA3-256',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'SHA3-384',
|
|
|
|
value: 'SHA3-384',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'SHA3-512',
|
|
|
|
value: 'SHA3-512',
|
|
|
|
},
|
2021-01-10 03:24:18 -08:00
|
|
|
{
|
|
|
|
name: 'SHA384',
|
|
|
|
value: 'SHA384',
|
|
|
|
},
|
2020-01-28 14:39:43 -08:00
|
|
|
{
|
|
|
|
name: 'SHA512',
|
|
|
|
value: 'SHA512',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'MD5',
|
|
|
|
description: 'The hash type to use',
|
|
|
|
required: true,
|
|
|
|
},
|
2023-06-02 02:22:21 -07:00
|
|
|
{
|
|
|
|
displayName: 'Binary Data',
|
|
|
|
name: 'binaryData',
|
|
|
|
type: 'boolean',
|
|
|
|
default: false,
|
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
action: ['hash', 'hmac'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
description: 'Whether the data to hashed should be taken from binary field',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Binary Property Name',
|
|
|
|
name: 'binaryPropertyName',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
action: ['hash', 'hmac'],
|
|
|
|
binaryData: [true],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
type: 'string',
|
|
|
|
default: 'data',
|
|
|
|
description: 'Name of the binary property which contains the input data',
|
|
|
|
required: true,
|
|
|
|
},
|
2020-01-28 14:39:43 -08:00
|
|
|
{
|
2020-02-07 22:33:53 -08:00
|
|
|
displayName: 'Value',
|
|
|
|
name: 'value',
|
2020-01-28 14:39:43 -08:00
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-01 13:47:55 -07:00
|
|
|
action: ['hash'],
|
2023-06-02 02:22:21 -07:00
|
|
|
binaryData: [false],
|
2020-01-28 14:39:43 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
2022-03-27 01:48:31 -07:00
|
|
|
description: 'The value that should be hashed',
|
2020-01-28 14:39:43 -08:00
|
|
|
required: true,
|
|
|
|
},
|
2020-02-07 22:33:53 -08:00
|
|
|
{
|
|
|
|
displayName: 'Property Name',
|
|
|
|
name: 'dataPropertyName',
|
|
|
|
type: 'string',
|
|
|
|
default: 'data',
|
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-01 13:47:55 -07:00
|
|
|
action: ['hash'],
|
2020-02-07 22:33:53 -08:00
|
|
|
},
|
|
|
|
},
|
2022-03-27 01:48:31 -07:00
|
|
|
description: 'Name of the property to which to write the hash',
|
2020-02-07 22:33:53 -08:00
|
|
|
},
|
2020-01-28 14:39:43 -08:00
|
|
|
{
|
|
|
|
displayName: 'Encoding',
|
|
|
|
name: 'encoding',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-01 13:47:55 -07:00
|
|
|
action: ['hash'],
|
2020-01-28 14:39:43 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
type: 'options',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'BASE64',
|
|
|
|
value: 'base64',
|
|
|
|
},
|
2020-02-07 22:33:53 -08:00
|
|
|
{
|
|
|
|
name: 'HEX',
|
|
|
|
value: 'hex',
|
|
|
|
},
|
2020-01-28 14:39:43 -08:00
|
|
|
],
|
|
|
|
default: 'hex',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Type',
|
|
|
|
name: 'type',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-01 13:47:55 -07:00
|
|
|
action: ['hmac'],
|
2020-01-28 14:39:43 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
type: 'options',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'MD5',
|
|
|
|
value: 'MD5',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'SHA256',
|
|
|
|
value: 'SHA256',
|
|
|
|
},
|
2022-10-07 10:15:11 -07:00
|
|
|
{
|
|
|
|
name: 'SHA3-256',
|
|
|
|
value: 'SHA3-256',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'SHA3-384',
|
|
|
|
value: 'SHA3-384',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'SHA3-512',
|
|
|
|
value: 'SHA3-512',
|
|
|
|
},
|
2021-01-10 03:24:18 -08:00
|
|
|
{
|
|
|
|
name: 'SHA384',
|
|
|
|
value: 'SHA384',
|
|
|
|
},
|
2020-01-28 14:39:43 -08:00
|
|
|
{
|
|
|
|
name: 'SHA512',
|
|
|
|
value: 'SHA512',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'MD5',
|
|
|
|
description: 'The hash type to use',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
{
|
2020-02-07 22:33:53 -08:00
|
|
|
displayName: 'Value',
|
|
|
|
name: 'value',
|
2020-01-28 14:39:43 -08:00
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-01 13:47:55 -07:00
|
|
|
action: ['hmac'],
|
2023-06-02 02:22:21 -07:00
|
|
|
binaryData: [false],
|
2020-01-28 14:39:43 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
2022-03-27 01:48:31 -07:00
|
|
|
description: 'The value of which the hmac should be created',
|
2020-01-28 14:39:43 -08:00
|
|
|
required: true,
|
|
|
|
},
|
2020-02-07 22:33:53 -08:00
|
|
|
{
|
|
|
|
displayName: 'Property Name',
|
|
|
|
name: 'dataPropertyName',
|
|
|
|
type: 'string',
|
|
|
|
default: 'data',
|
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-01 13:47:55 -07:00
|
|
|
action: ['hmac'],
|
2020-02-07 22:33:53 -08:00
|
|
|
},
|
|
|
|
},
|
2022-03-27 01:48:31 -07:00
|
|
|
description: 'Name of the property to which to write the hmac',
|
2020-02-07 22:33:53 -08:00
|
|
|
},
|
2020-01-28 14:39:43 -08:00
|
|
|
{
|
|
|
|
displayName: 'Secret',
|
|
|
|
name: 'secret',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-01 13:47:55 -07:00
|
|
|
action: ['hmac'],
|
2020-01-28 14:39:43 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Encoding',
|
|
|
|
name: 'encoding',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-01 13:47:55 -07:00
|
|
|
action: ['hmac'],
|
2020-01-28 14:39:43 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
type: 'options',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'BASE64',
|
|
|
|
value: 'base64',
|
|
|
|
},
|
2020-02-07 22:33:53 -08:00
|
|
|
{
|
|
|
|
name: 'HEX',
|
|
|
|
value: 'hex',
|
|
|
|
},
|
2020-01-28 14:39:43 -08:00
|
|
|
],
|
|
|
|
default: 'hex',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
{
|
2020-02-07 22:33:53 -08:00
|
|
|
displayName: 'Value',
|
|
|
|
name: 'value',
|
2020-01-28 14:39:43 -08:00
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-01 13:47:55 -07:00
|
|
|
action: ['sign'],
|
2023-06-02 02:22:21 -07:00
|
|
|
binaryData: [false],
|
2020-01-28 14:39:43 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
2022-03-27 01:48:31 -07:00
|
|
|
description: 'The value that should be signed',
|
2020-01-28 14:39:43 -08:00
|
|
|
required: true,
|
|
|
|
},
|
2020-02-07 22:33:53 -08:00
|
|
|
{
|
|
|
|
displayName: 'Property Name',
|
|
|
|
name: 'dataPropertyName',
|
|
|
|
type: 'string',
|
|
|
|
default: 'data',
|
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-01 13:47:55 -07:00
|
|
|
action: ['sign'],
|
2020-02-07 22:33:53 -08:00
|
|
|
},
|
|
|
|
},
|
2022-03-27 01:48:31 -07:00
|
|
|
description: 'Name of the property to which to write the signed value',
|
2020-02-07 22:33:53 -08:00
|
|
|
},
|
2020-01-28 14:39:43 -08:00
|
|
|
{
|
2022-06-03 10:23:49 -07:00
|
|
|
displayName: 'Algorithm Name or ID',
|
2020-01-28 14:39:43 -08:00
|
|
|
name: 'algorithm',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-01 13:47:55 -07:00
|
|
|
action: ['sign'],
|
2020-01-28 14:39:43 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
type: 'options',
|
2022-08-01 13:47:55 -07:00
|
|
|
description:
|
|
|
|
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
2023-06-02 06:23:28 -07:00
|
|
|
options: supportedAlgorithms,
|
2020-01-28 14:39:43 -08:00
|
|
|
default: '',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Encoding',
|
|
|
|
name: 'encoding',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-01 13:47:55 -07:00
|
|
|
action: ['sign'],
|
2020-01-28 14:39:43 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
type: 'options',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'BASE64',
|
|
|
|
value: 'base64',
|
|
|
|
},
|
2020-02-07 22:33:53 -08:00
|
|
|
{
|
|
|
|
name: 'HEX',
|
|
|
|
value: 'hex',
|
|
|
|
},
|
2020-01-28 14:39:43 -08:00
|
|
|
],
|
|
|
|
default: 'hex',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Private Key',
|
|
|
|
name: 'privateKey',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-01 13:47:55 -07:00
|
|
|
action: ['sign'],
|
2020-01-28 14:39:43 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
type: 'string',
|
2022-03-27 01:48:31 -07:00
|
|
|
description: 'Private key to use when signing the string',
|
2020-01-28 14:39:43 -08:00
|
|
|
default: '',
|
|
|
|
required: true,
|
|
|
|
},
|
2022-03-27 01:48:31 -07:00
|
|
|
{
|
|
|
|
displayName: 'Property Name',
|
|
|
|
name: 'dataPropertyName',
|
|
|
|
type: 'string',
|
|
|
|
default: 'data',
|
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-01 13:47:55 -07:00
|
|
|
action: ['generate'],
|
2022-03-27 01:48:31 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
description: 'Name of the property to which to write the random string',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Type',
|
|
|
|
name: 'encodingType',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-01 13:47:55 -07:00
|
|
|
action: ['generate'],
|
2022-03-27 01:48:31 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
type: 'options',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'ASCII',
|
|
|
|
value: 'ascii',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'BASE64',
|
|
|
|
value: 'base64',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'HEX',
|
|
|
|
value: 'hex',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'UUID',
|
|
|
|
value: 'uuid',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'uuid',
|
|
|
|
description: 'Encoding that will be used to generate string',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Length',
|
|
|
|
name: 'stringLength',
|
|
|
|
type: 'number',
|
|
|
|
default: 32,
|
|
|
|
description: 'Length of the generated string',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-01 13:47:55 -07:00
|
|
|
action: ['generate'],
|
|
|
|
encodingType: ['ascii', 'base64', 'hex'],
|
2022-03-27 01:48:31 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-01-28 14:39:43 -08:00
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
const items = this.getInputData();
|
2020-02-07 22:55:58 -08:00
|
|
|
|
|
|
|
const returnData: INodeExecutionData[] = [];
|
2022-04-22 09:29:51 -07:00
|
|
|
const length = items.length;
|
2020-02-07 22:33:53 -08:00
|
|
|
const action = this.getNodeParameter('action', 0) as string;
|
|
|
|
|
2020-02-07 22:55:58 -08:00
|
|
|
let item: INodeExecutionData;
|
2020-01-28 14:39:43 -08:00
|
|
|
for (let i = 0; i < length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
|
|
|
item = items[i];
|
2023-01-06 06:09:32 -08:00
|
|
|
const dataPropertyName = this.getNodeParameter('dataPropertyName', i);
|
2022-03-27 01:48:31 -07:00
|
|
|
const value = this.getNodeParameter('value', i, '') as string;
|
2021-07-19 23:58:54 -07:00
|
|
|
let newValue;
|
2023-06-02 02:22:21 -07:00
|
|
|
let binaryProcessed = false;
|
2020-02-07 22:55:58 -08:00
|
|
|
|
2022-03-27 01:48:31 -07:00
|
|
|
if (action === 'generate') {
|
2023-01-06 06:09:32 -08:00
|
|
|
const encodingType = this.getNodeParameter('encodingType', i);
|
2022-03-27 01:48:31 -07:00
|
|
|
if (encodingType === 'uuid') {
|
|
|
|
newValue = uuid();
|
|
|
|
} else {
|
|
|
|
const stringLength = this.getNodeParameter('stringLength', i) as number;
|
|
|
|
if (encodingType === 'base64') {
|
2022-08-01 13:47:55 -07:00
|
|
|
newValue = randomBytes(stringLength)
|
|
|
|
.toString(encodingType as BufferEncoding)
|
|
|
|
.replace(/\W/g, '')
|
|
|
|
.slice(0, stringLength);
|
2022-03-27 01:48:31 -07:00
|
|
|
} else {
|
2022-08-01 13:47:55 -07:00
|
|
|
newValue = randomBytes(stringLength)
|
|
|
|
.toString(encodingType as BufferEncoding)
|
|
|
|
.slice(0, stringLength);
|
2022-03-27 01:48:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-02 02:22:21 -07:00
|
|
|
|
|
|
|
if (action === 'hash' || action === 'hmac') {
|
2021-07-19 23:58:54 -07:00
|
|
|
const type = this.getNodeParameter('type', i) as string;
|
|
|
|
const encoding = this.getNodeParameter('encoding', i) as BinaryToTextEncoding;
|
2023-06-02 02:22:21 -07:00
|
|
|
const hashOrHmac =
|
|
|
|
action === 'hash'
|
|
|
|
? createHash(type)
|
|
|
|
: createHmac(type, this.getNodeParameter('secret', i) as string);
|
|
|
|
if (this.getNodeParameter('binaryData', i)) {
|
|
|
|
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
|
|
|
|
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
|
|
|
|
if (binaryData.id) {
|
|
|
|
const binaryStream = this.helpers.getBinaryStream(binaryData.id);
|
|
|
|
hashOrHmac.setEncoding(encoding);
|
|
|
|
await pipeline(binaryStream, hashOrHmac);
|
|
|
|
newValue = hashOrHmac.read();
|
|
|
|
} else {
|
|
|
|
newValue = hashOrHmac
|
|
|
|
.update(Buffer.from(binaryData.data, BINARY_ENCODING))
|
|
|
|
.digest(encoding);
|
|
|
|
}
|
|
|
|
binaryProcessed = true;
|
|
|
|
} else {
|
|
|
|
newValue = hashOrHmac.update(value).digest(encoding);
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2023-06-02 02:22:21 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (action === 'sign') {
|
|
|
|
const algorithm = this.getNodeParameter('algorithm', i) as string;
|
|
|
|
const encoding = this.getNodeParameter('encoding', i) as BinaryToTextEncoding;
|
|
|
|
const privateKey = this.getNodeParameter('privateKey', i) as string;
|
|
|
|
const sign = createSign(algorithm);
|
2022-12-02 12:54:28 -08:00
|
|
|
sign.write(value);
|
2021-07-19 23:58:54 -07:00
|
|
|
sign.end();
|
|
|
|
newValue = sign.sign(privateKey, encoding);
|
|
|
|
}
|
|
|
|
|
|
|
|
let newItem: INodeExecutionData;
|
|
|
|
if (dataPropertyName.includes('.')) {
|
|
|
|
// Uses dot notation so copy all data
|
|
|
|
newItem = {
|
2022-10-21 08:24:58 -07:00
|
|
|
json: deepCopy(item.json),
|
2022-06-03 08:25:07 -07:00
|
|
|
pairedItem: {
|
|
|
|
item: i,
|
|
|
|
},
|
2021-07-19 23:58:54 -07:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
// Does not use dot notation so shallow copy is enough
|
|
|
|
newItem = {
|
|
|
|
json: { ...item.json },
|
2022-06-03 08:25:07 -07:00
|
|
|
pairedItem: {
|
|
|
|
item: i,
|
|
|
|
},
|
2021-07-19 23:58:54 -07:00
|
|
|
};
|
|
|
|
}
|
2020-02-07 22:55:58 -08:00
|
|
|
|
2023-06-02 02:22:21 -07:00
|
|
|
if (item.binary !== undefined && !binaryProcessed) {
|
2021-07-19 23:58:54 -07:00
|
|
|
newItem.binary = item.binary;
|
|
|
|
}
|
2020-02-07 22:55:58 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
set(newItem, `json.${dataPropertyName}`, newValue);
|
|
|
|
|
|
|
|
returnData.push(newItem);
|
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
2022-06-03 08:25:07 -07:00
|
|
|
returnData.push({
|
|
|
|
json: {
|
|
|
|
error: (error as JsonObject).message,
|
|
|
|
},
|
|
|
|
pairedItem: {
|
|
|
|
item: i,
|
|
|
|
},
|
|
|
|
});
|
2021-07-19 23:58:54 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
|
|
|
}
|
2020-01-28 14:39:43 -08:00
|
|
|
}
|
2020-02-07 22:55:58 -08:00
|
|
|
return this.prepareOutputData(returnData);
|
2020-01-28 14:39:43 -08:00
|
|
|
}
|
|
|
|
}
|