MCPcopy Create free account
hub / github.com/allocnode/oh-my-sage / encrypt

Method encrypt

ref/gateway_client.js:37–49  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

35 }
36
37 encrypt(data) {
38 const counter = this.encryptCounter++;
39 const iv = this._makeIV(counter);
40 const cipher = crypto.createCipheriv('aes-128-gcm', this.key, iv);
41 const encrypted = Buffer.concat([cipher.update(data), cipher.final()]);
42 const tag = cipher.getAuthTag();
43
44 const result = Buffer.alloc(4 + encrypted.length + tag.length);
45 result.writeUInt32LE(counter, 0);
46 encrypted.copy(result, 4);
47 tag.copy(result, 4 + encrypted.length);
48 return result;
49 }
50
51 decrypt(data) {
52 if (data.length < 20) throw new Error('Data too short');

Callers 2

authenticateMethod · 0.95
callApiMethod · 0.45

Calls 1

_makeIVMethod · 0.95

Tested by

no test coverage detected