@gdjiami/jsonrpc-encryption
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

jsonrpc-encryption

介绍

基于 @gdjiami/jsonrpc 封装了加解密操作

加密算法: RSA + AES

在接口请求时能够自动完成上传数据的加密与接收数据的解密, 前端开发无需过多考虑数据的加解密操作

安装

yarn add @gdjiami/jsonrpc-encryption

使用

// rpc.ts 生成rpc实例
const rpc = getInstance(root, { ignoreProtocolError: true })
// 在入口文件处初始化加解密密钥,与后台进行协商
useOnMount(async () => {
  try {
    return await rpc.initial()
  } catch (error) {
    message.error(error.message)
  }
  return null
})
// 使用 encryptRequest 进行加密请求, 其返回数据已自动解密处理
const authResult = await rpc.encryptRequest('auth.login', { account, password })

注意事项

  • 前后端的加解密操作必须保持一致, 否则会出现解密失败

  • 只要是刷新 securityId 报错, 就会重新进行协商密钥

  • 其他请求返回错误码为 642, 会重新进行协商密钥

参考

JSONRPC 协议

License

This project is licensed under the terms of the MIT license.

Package Sidebar

Install

npm i @gdjiami/jsonrpc-encryption

Weekly Downloads

1

Version

1.2.0

License

MIT

Unpacked Size

89.2 kB

Total Files

12

Last publish

Collaborators

  • jiami
  • carney520
  • wenson-jay