/* * @Author: zcxb chen13157379235@outlook.com * @Date: 2022-09-21 09:41:45 * @LastEditors: huyang huyang@myun.info * @LastEditTime: 2022-10-13 00:32:11 * @FilePath: \jd-openapi-serviced:\work\Myun\repos\github\LuLuCodes\easy-front-core-sdk\packages\jos\src\security\common\KeyEncryption.ts * @Description: * * Copyright (c) 2022 by zcxb chen13157379235@outlook.com, All Rights Reserved. */ import { Mkey } from '../Mkey' import * as crypto from 'crypto' export class KeyEncryption { static IV_SIZE = 16 static aes_decrypt(m_key: Mkey, ct: Buffer) { const iv = ct.subarray(0, KeyEncryption.IV_SIZE) const crypted = ct.subarray(this.IV_SIZE).toString('binary') let decipher = crypto.createDecipheriv('aes-128-cbc', m_key.s_key, iv) // 设置自动 padding 为 true,删除填充补位 decipher.setAutoPadding(true) let decoded = decipher.update(crypted, 'binary', 'utf8') decoded += decipher.final('utf8') return decoded // const result = decoded.substring(0, -decoded.charCodeAt(decoded.length - 1)) // return result } }