| 40 | * @returns {boolean|string} 解密成功返回明文,解密失败返回false |
| 41 | */ |
| 42 | export 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 |