rsa

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultType    = PKCS1v15
	DefaultKeyType = PKCS1
	DefaultBits    = 2048
	DefaultHash    = crypto.SHA256
)

Variables

This section is empty.

Functions

func CreateKeys

func CreateKeys(opts ...*Options) (types.Bytes, types.Bytes, error)

生成密钥对(公私钥)

func Pkcs1ToPkcs8 added in v0.0.8

func Pkcs1ToPkcs8(key []byte) (types.Bytes, error)

MarshalPKCS8PrivateKey Pkcs1ToPkcs8 将 pkcs1 PrivateKey 转到 pkcs8 PrivateKey 自定义

Types

type KeyType added in v0.0.8

type KeyType uint
const (
	PKCS1 KeyType = 1 + iota //PKCS #1
	PKCS8                    //PKCS #8
	PKIX                     //公钥通用

)

公私钥格式

type Options added in v0.0.8

type Options struct {
	Type       Type
	KeyType    KeyType
	Bits       int
	Hash       crypto.Hash //RSA-OAEP RSA-PSS
	Label      []byte      //RSA-OAEP
	SaltLength int         //RSA-PSS
}

func DefaultOptions added in v0.0.8

func DefaultOptions() *Options

type Type added in v0.0.8

type Type uint
const (
	PKCS1v15 Type = 1 + iota // RSAES-PKCS1-v1_5、RSASSA-PKCS1-v1_5
	OAEP                     // RSAES-OAEP
	PSS                      // RSASSA-PSS

)

加密解密流程、签名验签流程

type XRsa

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

func NewXRsa

func NewXRsa(publicKey []byte, privateKey []byte, opts ...*Options) (*XRsa, error)

解析密钥对(公私钥)

func (*XRsa) Decrypt

func (x *XRsa) Decrypt(ciphertext []byte, opts ...*Options) (types.Bytes, error)

私钥解密 decrypted

func (*XRsa) Encrypt

func (x *XRsa) Encrypt(plaintext []byte, opts ...*Options) (types.Bytes, error)

公钥加密 encrypted

func (*XRsa) Sign

func (x *XRsa) Sign(data []byte, opts ...*Options) (types.Bytes, error)

私钥签名 signature

func (*XRsa) Verify

func (x *XRsa) Verify(data []byte, sign []byte, opts ...*Options) error

公钥验签 verifies

Jump to

Keyboard shortcuts

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