Axios wrapper for encrypting request parameters with SM4 and SM2, and decrypting response data from backend format.
- Encrypts all request payload into a single
encDatafield - Supports SM4 symmetric encryption with SM2 public-key encryption of the SM4 key
- Automatically decrypts backend responses with
code === 200 - Throws on
code !== 200
import { createSMCryptoAxios } from 'axios-sm-crypto';
const client = createSMCryptoAxios({
sm2PublicKey: '04...',
sm2PrivateKey: '...'
});
const response = await client.post('/api/example', { foo: 'bar' });
console.log(response.data);The request body will be rewritten as:
{
"encData": "..."
}Expects backend response like:
{
"code": 200,
"data": "xxxxx",
"msg": ""
}If code is 200, the package decrypts data and returns parsed JSON.