MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / AESGCMEncrypt

Function AESGCMEncrypt

src/common/util/RequestcryptUtil.js:70–86  ·  view source on GitHub ↗
(key, iv, msg)

Source from the content-addressed store, hash-verified

68 * @returns {boolean|string} 加密成功返回明文,加密失败返回false
69 */
70export function AESGCMEncrypt (key, iv, msg) {
71 msg = util.encodeUtf8(msg);
72 const cipherInstance = cipher.createCipher('AES-GCM', key);
73 cipherInstance.start({
74 iv: iv,
75 additionalData: '', // 'binary-encoded string', // optional
76 tagLength: 128 // optional, defaults to 128 bits
77 });
78 cipherInstance.update(util.createBuffer(msg));
79 const pass = cipherInstance.finish();
80 if (pass) {
81 const encrypted = cipherInstance.output;
82 const tag = cipherInstance.mode.tag;
83 return window.btoa(encrypted.data + tag.data);
84 }
85 return false;
86}
87
88/**
89 * @private

Callers 1

requestMethod · 0.90

Calls 3

finishMethod · 0.80
startMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected