rsa

package
v1.0.1017 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2022 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDataToLarge     = errors.New("message too long for RSA public key size")
	ErrDataLen         = errors.New("data length error")
	ErrDataBroken      = errors.New("data broken, first byte is not zero")
	ErrKeyPairDismatch = errors.New("data is not encrypted by the private key")
	ErrDecryption      = errors.New("decryption error")
)
View Source
var (
	ErrKeyMustBePEMEncoded = errors.New("invalid key: Key must be a PEM encoded PKCS1 or PKCS8 key")
	ErrNotRSAPrivateKey    = errors.New("key is not a valid RSA private key")
	ErrNotRSAPublicKey     = errors.New("key is not a valid RSA public key")
)
View Source
var PEMCiphers = map[string]x509.PEMCipher{
	"DESCBC":     x509.PEMCipherDES,
	"DESEDE3CBC": x509.PEMCipher3DES,
	"AES128CBC":  x509.PEMCipherAES128,
	"AES192CBC":  x509.PEMCipherAES192,
	"AES256CBC":  x509.PEMCipherAES256,
}

pem 加密方式

Functions

This section is empty.

Types

type Rsa

type Rsa struct {

	// 错误
	Error error
	// contains filtered or unexported fields
}

*

  • Rsa 加密 *
  • @create 2021-8-28
  • @author deatil

func NewRsa

func NewRsa() Rsa

构造函数

func RsaFromBase64String

func RsaFromBase64String(data string) Rsa

Base64

func RsaFromBytes

func RsaFromBytes(data []byte) Rsa

字节

func RsaFromHexString

func RsaFromHexString(data string) Rsa

Hex

func RsaFromPKCS12Cert

func RsaFromPKCS12Cert(key []byte) Rsa

Pkcs12 Cert

func RsaFromPKCS12CertWithPassword

func RsaFromPKCS12CertWithPassword(key []byte, password string) Rsa

Pkcs12CertWithPassword

func RsaFromPKCS1PrivateKey

func RsaFromPKCS1PrivateKey(key []byte) Rsa

Pkcs1

func RsaFromPKCS1PrivateKeyWithPassword

func RsaFromPKCS1PrivateKeyWithPassword(key []byte, password string) Rsa

Pkcs1WithPassword

func RsaFromPKCS8PrivateKey

func RsaFromPKCS8PrivateKey(key []byte) Rsa

Pkcs8

func RsaFromPKCS8PrivateKeyWithPassword

func RsaFromPKCS8PrivateKeyWithPassword(key []byte, password string) Rsa

Pkcs8WithPassword

func RsaFromPrivateKey

func RsaFromPrivateKey(key []byte) Rsa

私钥

func RsaFromPrivateKeyWithPassword

func RsaFromPrivateKeyWithPassword(key []byte, password string) Rsa

私钥带密码

func RsaFromPublicKey

func RsaFromPublicKey(key []byte) Rsa

公钥

func RsaFromString

func RsaFromString(data string) Rsa

字符

func RsaFromYoumarkPKCS8PrivateKeyWithPassword

func RsaFromYoumarkPKCS8PrivateKeyWithPassword(key []byte, password string) Rsa

设置私钥带密码

func RsaGenerateKey

func RsaGenerateKey(bits int) Rsa

生成密钥 bits = 512 | 1024 | 2048 | 4096

func (Rsa) CreatePKCS1PrivateKey

func (this Rsa) CreatePKCS1PrivateKey() Rsa

PKCS1 私钥

func (Rsa) CreatePKCS1PrivateKeyWithPassword

func (this Rsa) CreatePKCS1PrivateKeyWithPassword(password string, opts ...string) Rsa

PKCS1 私钥带密码 CreatePKCS1PrivateKeyWithPassword("123", "AES256CBC")

func (Rsa) CreatePKCS8PrivateKey

func (this Rsa) CreatePKCS8PrivateKey() Rsa

PKCS8 私钥

func (Rsa) CreatePKCS8PrivateKeyWithPassword

func (this Rsa) CreatePKCS8PrivateKeyWithPassword(password string, opts ...string) Rsa

PKCS8 私钥带密码 CreatePKCS8PrivateKeyWithPassword("123", "AES256CBC", "SHA256")

func (Rsa) CreatePrivateKey

func (this Rsa) CreatePrivateKey() Rsa

私钥, PKCS1 别名

func (Rsa) CreatePrivateKeyWithPassword

func (this Rsa) CreatePrivateKeyWithPassword(password string, opts ...string) Rsa

私钥带密码, PKCS1 别名

func (Rsa) CreatePublicKey

func (this Rsa) CreatePublicKey() Rsa

公钥

func (Rsa) CreateYoumarkPKCS8PrivateKeyWithPassword

func (this Rsa) CreateYoumarkPKCS8PrivateKeyWithPassword(password string, opt ...tool.YoumarkPKCS8Opts) Rsa

创建私钥带密码

func (Rsa) Decrypt

func (this Rsa) Decrypt() Rsa

私钥解密

func (Rsa) DecryptOAEP

func (this Rsa) DecryptOAEP(typ ...string) Rsa

OAEP私钥解密

func (Rsa) Encrypt

func (this Rsa) Encrypt() Rsa

公钥加密

func (Rsa) EncryptOAEP

func (this Rsa) EncryptOAEP(typ ...string) Rsa

OAEP公钥加密

func (Rsa) FromBase64String

func (this Rsa) FromBase64String(data string) Rsa

Base64

func (Rsa) FromBytes

func (this Rsa) FromBytes(data []byte) Rsa

字节

func (Rsa) FromHexString

func (this Rsa) FromHexString(data string) Rsa

Hex

func (Rsa) FromPKCS12Cert

func (this Rsa) FromPKCS12Cert(key []byte) Rsa

Pkcs12 Cert

func (Rsa) FromPKCS12CertWithPassword

func (this Rsa) FromPKCS12CertWithPassword(key []byte, password string) Rsa

Pkcs12CertWithPassword

func (Rsa) FromPKCS1PrivateKey

func (this Rsa) FromPKCS1PrivateKey(key []byte) Rsa

Pkcs1

func (Rsa) FromPKCS1PrivateKeyWithPassword

func (this Rsa) FromPKCS1PrivateKeyWithPassword(key []byte, password string) Rsa

Pkcs1WithPassword

func (Rsa) FromPKCS8PrivateKey

func (this Rsa) FromPKCS8PrivateKey(key []byte) Rsa

Pkcs8

func (Rsa) FromPKCS8PrivateKeyWithPassword

func (this Rsa) FromPKCS8PrivateKeyWithPassword(key []byte, password string) Rsa

Pkcs8WithPassword

func (Rsa) FromPrivateKey

func (this Rsa) FromPrivateKey(key []byte) Rsa

私钥

func (Rsa) FromPrivateKeyWithPassword

func (this Rsa) FromPrivateKeyWithPassword(key []byte, password string) Rsa

私钥带密码

func (Rsa) FromPublicKey

func (this Rsa) FromPublicKey(key []byte) Rsa

公钥

func (Rsa) FromString

func (this Rsa) FromString(data string) Rsa

字符

func (Rsa) FromYoumarkPKCS8PrivateKeyWithPassword

func (this Rsa) FromYoumarkPKCS8PrivateKeyWithPassword(key []byte, password string) Rsa

设置私钥带密码

func (Rsa) GenerateKey

func (this Rsa) GenerateKey(bits int) Rsa

生成密钥 bits = 512 | 1024 | 2048 | 4096

func (Rsa) GetData

func (this Rsa) GetData() []byte

获取 data

func (Rsa) GetError

func (this Rsa) GetError() error

获取错误

func (Rsa) GetKeyData

func (this Rsa) GetKeyData() []byte

获取 keyData

func (Rsa) GetParedData

func (this Rsa) GetParedData() []byte

获取 paredData

func (Rsa) GetPrivateKey

func (this Rsa) GetPrivateKey() *rsa.PrivateKey

获取 PrivateKey

func (Rsa) GetPublicKey

func (this Rsa) GetPublicKey() *rsa.PublicKey

获取 PublicKey

func (Rsa) GetSignHash

func (this Rsa) GetSignHash() string

获取 hash 类型

func (Rsa) GetVeryed

func (this Rsa) GetVeryed() bool

获取验证后情况

func (Rsa) MakePublicKey

func (this Rsa) MakePublicKey() Rsa

生成公钥

func (Rsa) OnError

func (this Rsa) OnError(fn RsaErrorFunc) Rsa

引出错误信息

func (Rsa) PSSSign

func (this Rsa) PSSSign(opts ...rsa.PSSOptions) Rsa

私钥签名 常用为: PS256[SHA256] | PS384[SHA384] | PS512[SHA512]

func (Rsa) PSSVery

func (this Rsa) PSSVery(data []byte, opts ...rsa.PSSOptions) Rsa

公钥验证 使用原始数据[data]对比签名后数据

func (Rsa) ParseRSAPKCS12CertFromPEMWithPassword

func (this Rsa) ParseRSAPKCS12CertFromPEMWithPassword(pfxData []byte, password string) (*rsa.PrivateKey, error)

解析 pkf 证书

func (Rsa) ParseRSAPKCS8PrivateKeyFromPEMWithPassword

func (this Rsa) ParseRSAPKCS8PrivateKeyFromPEMWithPassword(key []byte, password string) (*rsa.PrivateKey, error)

解析 PKCS8 带密码的私钥

func (Rsa) ParseRSAPrivateKeyFromPEM

func (this Rsa) ParseRSAPrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error)

解析 PKCS1 / PKCS8 私钥

func (Rsa) ParseRSAPrivateKeyFromPEMWithPassword

func (this Rsa) ParseRSAPrivateKeyFromPEMWithPassword(key []byte, password string) (*rsa.PrivateKey, error)

解析 PKCS1 带密码的私钥

func (Rsa) ParseRSAPublicKeyFromPEM

func (this Rsa) ParseRSAPublicKeyFromPEM(key []byte) (*rsa.PublicKey, error)

解析 PKCS1 / PKCS8 公钥

func (Rsa) PriKeyEncrypt

func (this Rsa) PriKeyEncrypt() Rsa

私钥加密

func (Rsa) PubKeyDecrypt

func (this Rsa) PubKeyDecrypt() Rsa

公钥解密

func (Rsa) Sign

func (this Rsa) Sign() Rsa

私钥签名

func (Rsa) ToBase64String

func (this Rsa) ToBase64String() string

输出Base64

func (Rsa) ToBytes

func (this Rsa) ToBytes() []byte

输出字节

func (Rsa) ToHexString

func (this Rsa) ToHexString() string

输出Hex

func (Rsa) ToKeyBytes

func (this Rsa) ToKeyBytes() []byte

私钥/公钥

func (Rsa) ToKeyString

func (this Rsa) ToKeyString() string

私钥/公钥

func (Rsa) ToString

func (this Rsa) ToString() string

输出字符

func (Rsa) ToVeryed

func (this Rsa) ToVeryed() bool

验证结果

func (Rsa) Very

func (this Rsa) Very(data []byte) Rsa

公钥验证 使用原始数据[data]对比签名后数据

func (Rsa) WithData

func (this Rsa) WithData(data []byte) Rsa

设置 data

func (Rsa) WithError

func (this Rsa) WithError(err error) Rsa

设置错误

func (Rsa) WithParedData

func (this Rsa) WithParedData(data []byte) Rsa

设置 paredData

func (Rsa) WithPrivateKey

func (this Rsa) WithPrivateKey(data *rsa.PrivateKey) Rsa

设置 PrivateKey

func (Rsa) WithPublicKey

func (this Rsa) WithPublicKey(data *rsa.PublicKey) Rsa

设置 PublicKey

func (Rsa) WithSignHash

func (this Rsa) WithSignHash(data string) Rsa

设置 hash 类型

func (Rsa) WithVeryed

func (this Rsa) WithVeryed(data bool) Rsa

设置 veryed

type RsaErrorFunc

type RsaErrorFunc = func(error)

错误方法

Jump to

Keyboard shortcuts

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