Skip to content
Snippets Groups Projects
Commit 580c7e5c authored by Zdravko Iliev's avatar Zdravko Iliev
Browse files

add optional key and iv for AES-GSM encryption

parent 8a6115c5
No related branches found
No related tags found
1 merge request!85Resolve "[Document Sealing] Add document proto buffers"
Pipeline #51035 passed
...@@ -48,10 +48,12 @@ const getBytes = (value, encoding) => { ...@@ -48,10 +48,12 @@ const getBytes = (value, encoding) => {
return bytes; return bytes;
}; };
class CryptoServiceNode { class CryptoServiceNode {
encryptAESGCM(data) { encryptAESGCM(data, key, iv) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const key = crypto.randomBytes(32); if (!key && !iv) {
const iv = crypto.randomBytes(12); key = crypto.randomBytes(32);
iv = crypto.randomBytes(12);
}
const cipher = crypto.createCipheriv(AES_GCM_ALGO, key, iv); const cipher = crypto.createCipheriv(AES_GCM_ALGO, key, iv);
let encrypted; let encrypted;
if (typeof data === "string") { if (typeof data === "string") {
......
...@@ -26,10 +26,15 @@ class CryptoServiceNode implements ICryptoService { ...@@ -26,10 +26,15 @@ class CryptoServiceNode implements ICryptoService {
public async encryptAESGCM(data: string): Promise<AESGCMOutput>; public async encryptAESGCM(data: string): Promise<AESGCMOutput>;
public async encryptAESGCM(data: ArrayBuffer): Promise<AESGCMOutput>; public async encryptAESGCM(data: ArrayBuffer): Promise<AESGCMOutput>;
public async encryptAESGCM( public async encryptAESGCM(
data: string | ArrayBuffer data: string | ArrayBuffer,
key?: Buffer,
iv?: Buffer
): Promise<AESGCMOutput> { ): Promise<AESGCMOutput> {
const key = crypto.randomBytes(32); if (!key && !iv) {
const iv = crypto.randomBytes(12); key = crypto.randomBytes(32);
iv = crypto.randomBytes(12);
}
const cipher = crypto.createCipheriv(AES_GCM_ALGO, key, iv); const cipher = crypto.createCipheriv(AES_GCM_ALGO, key, iv);
let encrypted; let encrypted;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment