Remove unused crypto utils

This commit is contained in:
Vishnu Mohandas 2020-10-01 17:18:52 +05:30
parent d7ed746658
commit ff72a22a78
3 changed files with 0 additions and 83 deletions

View file

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

View file

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

View file

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