@strapi/data-transfer
Version:
Data transfer capabilities for Strapi
1 lines • 3.66 kB
Source Map (JSON)
{"version":3,"file":"decrypt.mjs","sources":["../../../src/utils/encryption/decrypt.ts"],"sourcesContent":["import { Cipher, scryptSync, CipherKey, BinaryLike, createDecipheriv } from 'crypto';\nimport { EncryptionStrategy, Strategies, Algorithm } from '../../../types';\n\n// different key values depending on algorithm chosen\nconst getDecryptionStrategy = (algorithm: Algorithm): EncryptionStrategy => {\n const strategies: Strategies = {\n 'aes-128-ecb'(key: string): Cipher {\n const hashedKey = scryptSync(key, '', 16);\n const initVector: BinaryLike | null = null;\n const securityKey: CipherKey = hashedKey;\n return createDecipheriv(algorithm, securityKey, initVector);\n },\n aes128(key: string): Cipher {\n const hashedKey = scryptSync(key, '', 32);\n const initVector: BinaryLike | null = hashedKey.slice(16);\n const securityKey: CipherKey = hashedKey.slice(0, 16);\n return createDecipheriv(algorithm, securityKey, initVector);\n },\n aes192(key: string): Cipher {\n const hashedKey = scryptSync(key, '', 40);\n const initVector: BinaryLike | null = hashedKey.slice(24);\n const securityKey: CipherKey = hashedKey.slice(0, 24);\n return createDecipheriv(algorithm, securityKey, initVector);\n },\n aes256(key: string): Cipher {\n const hashedKey = scryptSync(key, '', 48);\n const initVector: BinaryLike | null = hashedKey.slice(32);\n const securityKey: CipherKey = hashedKey.slice(0, 32);\n return createDecipheriv(algorithm, securityKey, initVector);\n },\n };\n\n return strategies[algorithm];\n};\n\n/**\n * It creates a cipher instance used for decryption\n *\n * @param key - The decryption key\n * @param algorithm - The algorithm to use to create the Cipher\n *\n * @returns A {@link Cipher} instance created with the given key & algorithm\n */\nexport const createDecryptionCipher = (\n key: string,\n algorithm: Algorithm = 'aes-128-ecb'\n): Cipher => {\n return getDecryptionStrategy(algorithm)(key);\n};\n"],"names":["getDecryptionStrategy","algorithm","strategies","key","hashedKey","scryptSync","initVector","securityKey","createDecipheriv","aes128","slice","aes192","aes256","createDecryptionCipher"],"mappings":";;AAGA;AACA,MAAMA,wB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