瀏覽代碼

Remove unused crypto utils

Vishnu Mohandas 4 年之前
父節點
當前提交
ff72a22a78
共有 3 個文件被更改,包括 0 次插入83 次删除
  1. 0 51
      src/utils/crypto/aes.ts
  2. 0 25
      src/utils/crypto/common.ts
  3. 0 7
      src/utils/crypto/scrypt.ts

+ 0 - 51
src/utils/crypto/aes.ts

@@ -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);
-}

+ 0 - 25
src/utils/crypto/common.ts

@@ -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)));

+ 0 - 7
src/utils/crypto/scrypt.ts

@@ -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);
-}