rsa

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeySize2048 = 2048
	KeySize4096 = 4096
)

Variables

This section is empty.

Functions

func BytesToPrivateKey

func BytesToPrivateKey(data []byte) (*rsa.PrivateKey, error)

BytesToPrivateKey 从 DER 字节恢复私钥

func BytesToPublicKey

func BytesToPublicKey(data []byte) (*rsa.PublicKey, error)

BytesToPublicKey 从 DER 字节恢复公钥

func Decrypt

func Decrypt(privateKey *rsa.PrivateKey, ciphertext []byte) ([]byte, error)

Decrypt 使用 RSA-OAEP (SHA-256) 解密

func DecryptWithLabel

func DecryptWithLabel(privateKey *rsa.PrivateKey, ciphertext, label []byte) ([]byte, error)

DecryptWithLabel 使用 RSA-OAEP (SHA-256) 解密,带标签

func Encrypt

func Encrypt(publicKey *rsa.PublicKey, plaintext []byte) ([]byte, error)

Encrypt 使用 RSA-OAEP (SHA-256) 加密

func EncryptWithLabel

func EncryptWithLabel(publicKey *rsa.PublicKey, plaintext, label []byte) ([]byte, error)

EncryptWithLabel 使用 RSA-OAEP (SHA-256) 加密,带标签

func GenerateKeyPair

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

GenerateKeyPair 生成指定大小的 RSA 密钥对

func GenerateKeyPair2048

func GenerateKeyPair2048() (*rsa.PrivateKey, error)

GenerateKeyPair2048 生成 RSA-2048 密钥对

func GenerateKeyPair4096

func GenerateKeyPair4096() (*rsa.PrivateKey, error)

GenerateKeyPair4096 生成 RSA-4096 密钥对

func PEMToPrivateKey

func PEMToPrivateKey(pemData []byte) (*rsa.PrivateKey, error)

PEMToPrivateKey 从 PEM 格式恢复私钥

func PEMToPublicKey

func PEMToPublicKey(pemData []byte) (*rsa.PublicKey, error)

PEMToPublicKey 从 PEM 格式恢复公钥

func PrivateKeyToBytes

func PrivateKeyToBytes(privateKey *rsa.PrivateKey) []byte

PrivateKeyToBytes 将私钥序列化为 DER 字节

func PrivateKeyToHex

func PrivateKeyToHex(privateKey *rsa.PrivateKey) string

PrivateKeyToHex 将私钥序列化为十六进制字符串

func PrivateKeyToPEM

func PrivateKeyToPEM(privateKey *rsa.PrivateKey) []byte

PrivateKeyToPEM 将私钥序列化为 PEM 格式

func PublicKeyToBytes

func PublicKeyToBytes(publicKey *rsa.PublicKey) ([]byte, error)

PublicKeyToBytes 将公钥序列化为 DER 字节

func PublicKeyToHex

func PublicKeyToHex(publicKey *rsa.PublicKey) (string, error)

PublicKeyToHex 将公钥序列化为十六进制字符串

func PublicKeyToPEM

func PublicKeyToPEM(publicKey *rsa.PublicKey) ([]byte, error)

PublicKeyToPEM 将公钥序列化为 PEM 格式

func Sign

func Sign(privateKey *rsa.PrivateKey, message []byte) ([]byte, error)

Sign 使用 RSA-PSS 签名(SHA-256)

func SignPKCS1v15

func SignPKCS1v15(privateKey *rsa.PrivateKey, message []byte) ([]byte, error)

SignPKCS1v15 使用 PKCS#1 v1.5 签名(兼容性更好)

func Verify

func Verify(publicKey *rsa.PublicKey, message, signature []byte) bool

Verify 使用 RSA-PSS 验签(SHA-256)

func VerifyPKCS1v15

func VerifyPKCS1v15(publicKey *rsa.PublicKey, message, signature []byte) bool

VerifyPKCS1v15 使用 PKCS#1 v1.5 验签

Types

type RSASigner

type RSASigner struct {
	// contains filtered or unexported fields
}

RSASigner RSA 签名器 (默认 PSS 模式)

func NewRSASigner

func NewRSASigner(privateKey *rsa.PrivateKey) *RSASigner

NewRSASigner 创建 RSA 签名器

func (*RSASigner) Sign

func (s *RSASigner) Sign(msg []byte) ([]byte, error)

type RSAVerifier

type RSAVerifier struct {
	// contains filtered or unexported fields
}

RSAVerifier RSA 验签器 (默认 PSS 模式)

func NewRSAVerifier

func NewRSAVerifier(publicKey *rsa.PublicKey) *RSAVerifier

NewRSAVerifier 创建 RSA 验签器

func (*RSAVerifier) Verify

func (v *RSAVerifier) Verify(msg, signature []byte) (bool, error)

Jump to

Keyboard shortcuts

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