diff --git a/src/utils/crypto/aes.ts b/src/utils/crypto/aes.ts deleted file mode 100644 index cf8b82411..000000000 --- a/src/utils/crypto/aes.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { base64ToUint8, binToBase64 } from './common'; - -/** - * Takes base64 encoded binary data, key and iv and returns - * base64 encoded encrypted binary message. - * @param data - * @param key - * @param iv - */ -export async function encrypt(data: string, key: string, iv: string) { - const cryptoKey = await crypto.subtle.importKey( - 'raw', base64ToUint8(key), { name: 'AES-CBC' }, - false, ['encrypt', 'decrypt'] - ); - - const result = await crypto.subtle.encrypt( - { - name: "AES-CBC", - iv: base64ToUint8(iv), - }, - cryptoKey, - base64ToUint8(data), - ); - - return binToBase64(result); -} - -/** - * Takes base64 encoded binary data, key and iv and returns - * base64 encoded decrypted binary message. - * @param data - * @param key - * @param iv - */ -export async function decrypt(data: string, key: string, iv: string) { - const cryptoKey = await crypto.subtle.importKey( - 'raw', base64ToUint8(key), { name: 'AES-CBC' }, - false, ['encrypt', 'decrypt'] - ); - - const result = await crypto.subtle.decrypt( - { - name: "AES-CBC", - iv: base64ToUint8(iv), - }, - cryptoKey, - base64ToUint8(data), - ); - - return binToBase64(result); -} \ No newline at end of file diff --git a/src/utils/crypto/common.ts b/src/utils/crypto/common.ts deleted file mode 100644 index b87c6e784..000000000 --- a/src/utils/crypto/common.ts +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Converts base64 encoded string to Uint8 Array. - * @param str - */ -export const base64ToUint8 = (str: string) => Uint8Array.from(atob(str), c => c.charCodeAt(0)); - -/** - * Converts string to Uint8 Array. - * @param str - */ -export const strToUint8 = (str: string) => Uint8Array.from(str, c => c.charCodeAt(0)); - -/** - * Converts binary data to base64 encoded string. - * @param bin - */ -export const binToBase64 = (bin: Uint8Array | ArrayBuffer) => btoa( - String.fromCharCode(...new Uint8Array(bin))); - -/** - * Generates base64 encoded string of random bytes of given length. - * @param length - */ -export const secureRandomString = (length: number) => binToBase64( - crypto.getRandomValues(new Uint8Array(length))); \ No newline at end of file diff --git a/src/utils/crypto/scrypt.ts b/src/utils/crypto/scrypt.ts deleted file mode 100644 index 27aaa320d..000000000 --- a/src/utils/crypto/scrypt.ts +++ /dev/null @@ -1,7 +0,0 @@ -import * as scrypt from 'scrypt-js'; -import { binToBase64 } from './common'; - -export const hash = async (passphrase: Uint8Array, salt: Uint8Array) => { - const result = await scrypt.scrypt(passphrase, salt, 16384, 16, 1, 32); - return binToBase64(result); -}