import { createCipherDecrypt } from './createCipherDecrypt' ; import type { CipherDecrypt } from './createCipherDecrypt' ; import { createCipherEncrypt } from './createCipherEncrypt' ; import type { CipherEncrypt } from './createCipherEncrypt' ; import { createCipherSignature } from './createCipherSignature' ; import type { CipherSignature } from './createCipherSignature' ; export interface CipherOptions { /**
     * Token that generated by wechat-work
     */ token : string ; /**
     * EncodingAesKey that generated by wechat-work
     */ encodingAesKey : string ; } see https export interface Cipher { signature : CipherSignature ; decrypt : CipherDecrypt ; encrypt : CipherEncrypt ; } export const createCipher = ( { token , encodingAesKey , } ) : Cipher => { /**
     * Used for cipher & decipher
     */ const aesKey = Buffer . from ( `${ encodingAesKey }=` , 'base64' ) ; /**
     * Used for cipher & decipher
     */ const iv = aesKey . slice ( 0 , 16 ) ; const signature = createCipherSignature ( { token } ) ; const decrypt = createCipherDecrypt ( { aesKey , iv , } ) ; const encrypt = createCipherEncrypt ( { aesKey , iv , } ) ; return { signature , decrypt , encrypt , } ; } ;