From 69ca2d541dc1e5dbec346869382e47488ea1f340 Mon Sep 17 00:00:00 2001 From: vakarisz Date: Tue, 28 Jun 2022 16:05:49 +0300 Subject: [PATCH] UI: Create password based encryptor using crypto-js library Password based encryptor is required for configuration encryption --- monkey/monkey_island/cc/ui/package-lock.json | 11 +++++++++++ monkey/monkey_island/cc/ui/package.json | 1 + .../src/components/utils/PasswordBasedEncryptor.tsx | 11 +++++++++++ 3 files changed, 23 insertions(+) create mode 100644 monkey/monkey_island/cc/ui/src/components/utils/PasswordBasedEncryptor.tsx diff --git a/monkey/monkey_island/cc/ui/package-lock.json b/monkey/monkey_island/cc/ui/package-lock.json index 2d92658bc..4b6f83089 100644 --- a/monkey/monkey_island/cc/ui/package-lock.json +++ b/monkey/monkey_island/cc/ui/package-lock.json @@ -20,6 +20,7 @@ "bootstrap": "^4.5.3", "classnames": "^2.3.1", "core-js": "^3.18.2", + "crypto-js": "^4.1.1", "d3": "^5.14.1", "downloadjs": "^1.4.7", "fetch": "^1.1.0", @@ -4191,6 +4192,11 @@ "semver": "bin/semver" } }, + "node_modules/crypto-js": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.1.1.tgz", + "integrity": "sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==" + }, "node_modules/css-loader": { "version": "6.7.1", "resolved": "https://registry.npmjs.org/css-loader/-/css-loader-6.7.1.tgz", @@ -19166,6 +19172,11 @@ } } }, + "crypto-js": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.1.1.tgz", + "integrity": "sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==" + }, "css-loader": { "version": "6.7.1", "resolved": "https://registry.npmjs.org/css-loader/-/css-loader-6.7.1.tgz", diff --git a/monkey/monkey_island/cc/ui/package.json b/monkey/monkey_island/cc/ui/package.json index b244113df..b18bda191 100644 --- a/monkey/monkey_island/cc/ui/package.json +++ b/monkey/monkey_island/cc/ui/package.json @@ -76,6 +76,7 @@ "bootstrap": "^4.5.3", "classnames": "^2.3.1", "core-js": "^3.18.2", + "crypto-js": "^4.1.1", "d3": "^5.14.1", "downloadjs": "^1.4.7", "fetch": "^1.1.0", diff --git a/monkey/monkey_island/cc/ui/src/components/utils/PasswordBasedEncryptor.tsx b/monkey/monkey_island/cc/ui/src/components/utils/PasswordBasedEncryptor.tsx new file mode 100644 index 000000000..500ca7729 --- /dev/null +++ b/monkey/monkey_island/cc/ui/src/components/utils/PasswordBasedEncryptor.tsx @@ -0,0 +1,11 @@ +import AES from 'crypto-js/aes'; +import Utf8 from 'crypto-js/enc-utf8'; + +export function encryptText(content: string, password: string): string { + return AES.encrypt(content, password).toString(); +} + +export function decryptText(ciphertext: string, password: string): string { + let bytes = AES.decrypt(ciphertext, password); + return bytes.toString(Utf8); +}