Class WeComCrypto

java.lang.Object
io.agentscope.extensions.channel.wecom.WeComCrypto

public final class WeComCrypto extends Object
Implements WeCom's URL-handshake signature + AES-CBC + PKCS#7 encrypt / decrypt scheme. See WeCom callback specification.

Inputs:

  • token — the developer-supplied callback token.
  • encodingAesKey — 43-character base64 (no padding). Decoded with appended "=" to yield a 32-byte AES key. The first 16 bytes are also used as the CBC IV.
  • receiveId — the corp id (for self-built apps) or suite id (for ISV apps). Decryption verifies the trailing receive-id against this value.
  • Constructor Details

    • WeComCrypto

      public WeComCrypto(String token, String encodingAesKey, String receiveId)
  • Method Details

    • verifySignature

      public boolean verifySignature(String signature, String timestamp, String nonce, String encrypt)
      Verifies the SHA-1 signature produced by sorting [token, timestamp, nonce, encrypt], concatenating, and hashing.
    • decrypt

      public String decrypt(String encryptBase64)
      Decrypts the Encrypt body and returns the inner XML payload as a UTF-8 string.

      WeCom plaintext layout after AES-CBC decrypt + PKCS#7 unpad:

       | 16 bytes random | 4 bytes msg_len (big-endian) | msg (XML, msg_len bytes) | receive_id |