Class FeishuCrypto

java.lang.Object
io.agentscope.extensions.channel.feishu.FeishuCrypto

public final class FeishuCrypto extends Object
Implements Feishu callback encryption + signature verification.

Feishu encrypts the callback body when an Encrypt Key is configured in the developer console. The wire format is JSON {"encrypt":"<base64-ciphertext>"}. The AES key is derived as SHA-256(encryptKey) (32 bytes). The ciphertext layout is:

 | 16 bytes IV | AES-CBC + PKCS#7 padded body |
 

The signature header X-Lark-Signature is computed as SHA-256(timestamp + nonce + encryptKey + rawBody) where rawBody is the raw HTTP request body (the JSON-stringified envelope, not the decrypted plaintext).

See Also:
  • Constructor Details

    • FeishuCrypto

      public FeishuCrypto(String encryptKey)
  • Method Details

    • verifySignature

      public boolean verifySignature(String signature, String timestamp, String nonce, String body)
      Verifies the SHA-256 signature: hex(SHA-256(timestamp + nonce + encryptKey + body)). Returns false when any argument is null or the digest mismatches.
    • decrypt

      public String decrypt(String encryptBase64)
      Decrypts the encrypt string from a Feishu callback. Returns the JSON plaintext as a UTF-8 string.

      Layout after base64-decoding:

       | 16 bytes IV | AES-256-CBC + PKCS#7 padded plaintext |