entronad / crypto-es

A cryptography algorithms library
Other
272 stars 30 forks source link

TS Error: keySize does not exist in type 'CipherCfg' #36

Closed FrankFang closed 1 year ago

FrankFang commented 1 year ago
CryptoJS.AES.decrypt(str, _key, {
    keySize: 16, // <---- Argument of type '{ keySize: number; iv: WordArray; mode: typeof ECB; padding: Padding; }' is not assignable to parameter of type 'CipherCfg'.
                 //       Object literal may only specify known properties, and 'keySize' does not exist in type 'CipherCfg'.ts(2345)
    iv: _iv,
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  }).toString(CryptoJS.enc.Utf8)
entronad commented 1 year ago

keySize seems not to be a cfg field for Cipher in CryptoJS (CryptoES keeps consistent with CryptoJS).

The keySize is set in sub cipher's definition body, image and passed into kdf.execute before the cipher's instance merging cfg: WeChat96c519835198966362a8bc7c815fad71 The cipher here in cipher.keySize is a constructor like CryptoJS.algo.AES, not a instance with cfg merged.

I tracked it in debug mode, when I passed a keySize: 16, it seemed still keySize 8(The value set in AES) is passed into kdf.execute. Will the keySize passed into cfg affects the result in your case?

(All this are tested in CryptoJS and CryptoES has same logic with it.)

FrankFang commented 1 year ago

It makes sense.