weixin-ts / cdn/src / decryptAesEcb
Function: decryptAesEcb()
decryptAesEcb(
ciphertext,key):Promise<Uint8Array<ArrayBufferLike>>
Defined in: cdn/src/aes-ecb.ts:134
Decrypt data using AES-128-ECB.
Strategy: Use AES-CBC decrypt on the full ciphertext, then undo the CBC chaining. CBC_DEC gives: P[0] = DEC(C[0]) ^ IV, P[i] = DEC(C[i]) ^ C[i-1] ECB_DEC gives: P[i] = DEC(C[i]) Therefore: ECB_P[0] = CBC_P[0] (since IV=0), ECB_P[i] = CBC_P[i] ^ C[i-1]
To handle WebCrypto's mandatory PKCS7 unpadding, we append a known block that will decrypt to valid PKCS7 padding.
Parameters
ciphertext
Uint8Array
Encrypted data (must be multiple of 16 bytes)
key
Uint8Array
16-byte AES key
Returns
Promise<Uint8Array<ArrayBufferLike>>
Decrypted plaintext (PKCS7 padding removed)
Example
ts
const decrypted = await decryptAesEcb(encrypted, key)