Documentation
¶
Index ¶
- Constants
- func BytesToPrivateKey(data []byte) (*rsa.PrivateKey, error)
- func BytesToPublicKey(data []byte) (*rsa.PublicKey, error)
- func Decrypt(privateKey *rsa.PrivateKey, ciphertext []byte) ([]byte, error)
- func DecryptWithLabel(privateKey *rsa.PrivateKey, ciphertext, label []byte) ([]byte, error)
- func Encrypt(publicKey *rsa.PublicKey, plaintext []byte) ([]byte, error)
- func EncryptWithLabel(publicKey *rsa.PublicKey, plaintext, label []byte) ([]byte, error)
- func GenerateKeyPair(bits int) (*rsa.PrivateKey, error)
- func GenerateKeyPair2048() (*rsa.PrivateKey, error)
- func GenerateKeyPair4096() (*rsa.PrivateKey, error)
- func PEMToPrivateKey(pemData []byte) (*rsa.PrivateKey, error)
- func PEMToPublicKey(pemData []byte) (*rsa.PublicKey, error)
- func PrivateKeyToBytes(privateKey *rsa.PrivateKey) []byte
- func PrivateKeyToHex(privateKey *rsa.PrivateKey) string
- func PrivateKeyToPEM(privateKey *rsa.PrivateKey) []byte
- func PublicKeyToBytes(publicKey *rsa.PublicKey) ([]byte, error)
- func PublicKeyToHex(publicKey *rsa.PublicKey) (string, error)
- func PublicKeyToPEM(publicKey *rsa.PublicKey) ([]byte, error)
- func Sign(privateKey *rsa.PrivateKey, message []byte) ([]byte, error)
- func SignPKCS1v15(privateKey *rsa.PrivateKey, message []byte) ([]byte, error)
- func Verify(publicKey *rsa.PublicKey, message, signature []byte) bool
- func VerifyPKCS1v15(publicKey *rsa.PublicKey, message, signature []byte) bool
- type RSASigner
- type RSAVerifier
Constants ¶
const ( KeySize2048 = 2048 KeySize4096 = 4096 )
Variables ¶
This section is empty.
Functions ¶
func BytesToPrivateKey ¶
func BytesToPrivateKey(data []byte) (*rsa.PrivateKey, error)
BytesToPrivateKey 从 DER 字节恢复私钥
func BytesToPublicKey ¶
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 EncryptWithLabel ¶
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 ¶
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 ¶
PublicKeyToBytes 将公钥序列化为 DER 字节
func PublicKeyToHex ¶
PublicKeyToHex 将公钥序列化为十六进制字符串
func PublicKeyToPEM ¶
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 签名(兼容性更好)
Types ¶
type RSASigner ¶
type RSASigner struct {
// contains filtered or unexported fields
}
RSASigner RSA 签名器 (默认 PSS 模式)
func NewRSASigner ¶
func NewRSASigner(privateKey *rsa.PrivateKey) *RSASigner
NewRSASigner 创建 RSA 签名器
type RSAVerifier ¶
type RSAVerifier struct {
// contains filtered or unexported fields
}
RSAVerifier RSA 验签器 (默认 PSS 模式)
func NewRSAVerifier ¶
func NewRSAVerifier(publicKey *rsa.PublicKey) *RSAVerifier
NewRSAVerifier 创建 RSA 验签器