MCPcopy Index your code
hub / github.com/SuperMap/iClient-JavaScript / AESGCMDecrypt

Function AESGCMDecrypt

src/common/util/RequestcryptUtil.js:42–59  ·  view source on GitHub ↗
(key, iv, cipherText)

Source from the content-addressed store, hash-verified

40 * @returns {boolean|string} 解密成功返回明文,解密失败返回false
41 */
42export function AESGCMDecrypt (key, iv, cipherText) {
43 const cipherStrAndMac = window.atob(cipherText);
44 const cipherStr = cipherStrAndMac.substring(0, cipherStrAndMac.length - 16);
45 const mac = cipherStrAndMac.substring(cipherStrAndMac.length - 16);
46 const decipher = cipher.createDecipher('AES-GCM', util.createBuffer(key));
47 decipher.start({
48 iv: util.createBuffer(iv),
49 additionalData: '', // optional
50 tagLength: 128, // optional, defaults to 128 bits
51 tag: mac // authentication tag from encryption
52 });
53 decipher.update(util.createBuffer(cipherStr));
54 const pass = decipher.finish();
55 if (pass) {
56 return util.decodeUtf8(decipher.output.data);
57 }
58 return false;
59}
60
61/**
62 * @private

Callers 1

requestMethod · 0.90

Calls 3

finishMethod · 0.80
startMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected