restore cryptokey class with node ref

This commit is contained in:
Kyle Spearrin 2018-01-09 15:38:33 -05:00
parent bf35cf3588
commit 9a74f3e4ea
1 changed files with 6 additions and 7 deletions

View File

@ -1,3 +1,5 @@
import * as forge from 'node-forge';
import { EncryptionType } from '../../enums/encryptionType';
import { SymmetricCryptoKeyBuffers } from './symmetricCryptoKeyBuffers';
@ -11,20 +13,17 @@ export class SymmetricCryptoKey {
macKey: string;
encType: EncryptionType;
keyBuf: SymmetricCryptoKeyBuffers;
forge: any;
constructor(keyBytes: string, b64KeyBytes?: boolean, encType?: EncryptionType) {
this.forge = (window as any).forge;
if (b64KeyBytes) {
keyBytes = this.forge.util.decode64(keyBytes);
keyBytes = forge.util.decode64(keyBytes);
}
if (!keyBytes) {
throw new Error('Must provide keyBytes');
}
const buffer = this.forge.util.createBuffer(keyBytes);
const buffer = (forge as any).util.createBuffer(keyBytes);
if (!buffer || buffer.length() === 0) {
throw new Error('Couldn\'t make buffer');
}
@ -42,7 +41,7 @@ export class SymmetricCryptoKey {
}
this.key = keyBytes;
this.keyB64 = this.forge.util.encode64(keyBytes);
this.keyB64 = forge.util.encode64(keyBytes);
this.encType = encType;
if (encType === EncryptionType.AesCbc256_B64 && bufferLength === 32) {
@ -59,7 +58,7 @@ export class SymmetricCryptoKey {
}
}
getBuffers() {
getBuffers(): SymmetricCryptoKeyBuffers {
if (this.keyBuf) {
return this.keyBuf;
}