encrypt

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package encrypt 提供AES ECB模式的加密解密功能

Package encrypt 提供RSA非对称加密解密和数字签名功能

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AesEcbDecrypt

func AesEcbDecrypt(cryptText string, key string, isPad ...bool) (string, error)

AesEcbDecrypt AES ECB模式解密 cryptText: base64编码的密文 key: 解密密钥,长度必须为16、24或32字节 isPad: 是否使用padding填充,默认为true 返回: 解密后的明文和错误信息

func AesEcbEncrypt

func AesEcbEncrypt(plainText string, key string, isPad ...bool) (string, error)

AesEcbEncrypt AES ECB模式加密 plainText: 待加密的明文 key: 加密密钥,长度必须为16、24或32字节 isPad: 是否使用padding填充,默认为true 返回: base64编码的加密结果和错误信息

func RsaDecrypt

func RsaDecrypt(privateKey *rsa.PrivateKey, cipherBytes []byte) ([]byte, error)

RsaDecrypt 使用RSA私钥解密数据 privateKey: RSA私钥对象 cipherBytes: 待解密的密文字节数组 返回: 解密后的明文字节数组和错误信息

func RsaDecryptFromBase64

func RsaDecryptFromBase64(privateKey *rsa.PrivateKey, cipherText string) (string, error)

RsaDecryptFromBase64 使用RSA私钥解密base64编码的密文 privateKey: RSA私钥对象 cipherText: base64编码的密文 返回: 解密后的明文和错误信息

func RsaEncrypt

func RsaEncrypt(publicKey *rsa.PublicKey, plainText string) ([]byte, error)

RsaEncrypt 使用RSA公钥加密数据 publicKey: RSA公钥对象 plainText: 待加密的明文 返回: 加密后的字节数组和错误信息

func RsaEncrypt2Base64

func RsaEncrypt2Base64(publicKey *rsa.PublicKey, plainText string) (string, error)

RsaEncrypt2Base64 使用RSA公钥加密数据并返回base64编码的密文 publicKey: RSA公钥对象 plainText: 待加密的明文 返回: base64编码的加密结果和错误信息

func RsaGeneratePrivateKey

func RsaGeneratePrivateKey(bits int) (*rsa.PrivateKey, error)

RsaGeneratePrivateKey 生成指定长度的RSA私钥 bits: 密钥长度,建议使用2048或4096位 返回: RSA私钥对象和错误信息

func RsaReadPrivatePem

func RsaReadPrivatePem(filePath string) (*rsa.PrivateKey, error)

RsaReadPrivatePem 从文件中读取PEM格式的RSA私钥 filePath: 私钥文件路径 返回: RSA私钥对象和错误信息

func RsaReadPublicPem

func RsaReadPublicPem(filePath string) (*rsa.PublicKey, error)

RsaReadPublicPem 从文件中读取PEM格式的RSA公钥 filePath: 公钥文件路径 返回: RSA公钥对象和错误信息

func RsaSavePrivatePem

func RsaSavePrivatePem(privateKey *rsa.PrivateKey, filePath string) error

RsaSavePrivatePem 将RSA私钥保存为PEM格式文件 privateKey: RSA私钥对象 filePath: 保存路径 返回: 错误信息

func RsaSavePublicPem

func RsaSavePublicPem(publicKey *rsa.PublicKey, filePath string) error

RsaSavePublicPem 将RSA公钥保存为PEM格式文件 publicKey: RSA公钥对象 filePath: 保存路径 返回: 错误信息

func RsaSign

func RsaSign(privateKey *rsa.PrivateKey, plaintext string) ([]byte, error)

RsaSign 使用RSA私钥对数据进行数字签名 privateKey: RSA私钥对象 plaintext: 待签名的明文 返回: 签名字节数组和错误信息

func RsaSign2Base64

func RsaSign2Base64(privateKey *rsa.PrivateKey, plaintext string) (string, error)

RsaSign2Base64 使用RSA私钥对数据进行数字签名并返回base64编码 privateKey: RSA私钥对象 plaintext: 待签名的明文 返回: base64编码的签名和错误信息

func RsaValidSign

func RsaValidSign(publicKey *rsa.PublicKey, ciphertext string, signBytes []byte) error

RsaValidSign 使用RSA公钥验证数字签名 publicKey: RSA公钥对象 ciphertext: 原始明文 signBytes: 签名字节数组 返回: 验证结果错误信息

func RsaValidSignFromBase64

func RsaValidSignFromBase64(publicKey *rsa.PublicKey, ciphertext string, sign string) error

RsaValidSignFromBase64 使用RSA公钥验证base64编码的数字签名 publicKey: RSA公钥对象 ciphertext: 原始明文 sign: base64编码的签名 返回: 验证结果错误信息

Types

This section is empty.

Jump to

Keyboard shortcuts

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