utils

package
v0.0.0-...-67ab1fb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RSASignUtil

type RSASignUtil struct{}

RSASignUtil RSA签名工具类

func NewRSASignUtil

func NewRSASignUtil() *RSASignUtil

NewRSASignUtil 创建RSA签名工具实例 返回值: *RSASignUtil - RSA签名工具实例

func (*RSASignUtil) GenerateRSAKeyPair

func (r *RSASignUtil) GenerateRSAKeyPair(bits int) (string, string, error)

GenerateRSAKeyPair 生成RSA密钥对 功能: 生成指定位数的RSA密钥对 参数:

  • bits: 密钥位数,建议2048或4096

返回值:

  • string: PEM格式的私钥
  • string: PEM格式的公钥
  • error: 错误信息

func (*RSASignUtil) GenerateSignature

func (r *RSASignUtil) GenerateSignature(jsonBody, appId string, timestamp int64, nonce, privateKeyPEM string) (string, error)

GenerateSignature 生成RSA签名 功能: 根据请求体、应用ID、时间戳、随机数和RSA私钥生成base64编码的签名 参数:

  • jsonBody: JSON格式的请求体
  • appId: 应用ID
  • timestamp: 时间戳
  • nonce: 随机数
  • privateKeyPEM: PEM格式的RSA私钥

返回值:

  • string: base64编码的签名结果
  • error: 错误信息

func (*RSASignUtil) VerifySignature

func (r *RSASignUtil) VerifySignature(jsonBody, appId string, timestamp int64, nonce, signature, publicKeyPEM string) (bool, error)

VerifySignature 验证RSA签名 功能: 验证签名是否正确 参数:

  • jsonBody: JSON格式的请求体
  • appId: 应用ID
  • timestamp: 时间戳
  • nonce: 随机数
  • signature: base64编码的签名
  • publicKeyPEM: PEM格式的RSA公钥

返回值:

  • bool: 验证结果,true表示验证成功
  • error: 错误信息

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL