Skip to content

woodhans/api-crypto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

axios-sm-crypto

Axios wrapper for encrypting request parameters with SM4 and SM2, and decrypting response data from backend format.

Features

  • Encrypts all request payload into a single encData field
  • Supports SM4 symmetric encryption with SM2 public-key encryption of the SM4 key
  • Automatically decrypts backend responses with code === 200
  • Throws on code !== 200

Usage

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);

Request format

The request body will be rewritten as:

{
  "encData": "..."
}

Response format

Expects backend response like:

{
  "code": 200,
  "data": "xxxxx",
  "msg": ""
}

If code is 200, the package decrypts data and returns parsed JSON.

About

Axios wrapper with SM2 and SM4 encryption for API requests

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors