1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 01:03:35 +00:00

implement crypto functions in more places

This commit is contained in:
Kyle Spearrin
2018-04-21 23:55:21 -04:00
parent fc1114a6bd
commit 5e7115f78d
6 changed files with 26 additions and 43 deletions

View File

@@ -26,6 +26,18 @@ export class Utils {
}
}
static fromHexToArray(str: string): Uint8Array {
if (Utils.isNode) {
return new Uint8Array(Buffer.from(str, 'hex'));
} else {
const bytes = new Uint8Array(str.length / 2);
for (let i = 0; i < str.length; i += 2) {
bytes[i / 2] = parseInt(str.substr(i, 2), 16);
}
return bytes;
}
}
static fromUtf8ToArray(str: string): Uint8Array {
if (Utils.isNode) {
return new Uint8Array(Buffer.from(str, 'utf8'));