rsa

package
v1.0.2013 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// 获取 Cipher 类型
	GetCipherFromName = cryptobin_pkcs8.GetCipherFromName
	// 获取 hash 类型
	GetHashFromName = cryptobin_pkcs8.GetHashFromName
)
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 Opts added in v1.0.1018

type Opts = cryptobin_pkcs8.Opts

配置

type PBKDF2Opts added in v1.0.1018

type PBKDF2Opts = cryptobin_pkcs8.PBKDF2Opts

PBKDF2 配置

type Rsa

type Rsa struct {

	// 错误
	Errors []error
	// contains filtered or unexported fields
}

*

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

func FromBase64String added in v1.0.1018

func FromBase64String(data string) Rsa

Base64

func FromBytes added in v1.0.1018

func FromBytes(data []byte) Rsa

字节

func FromHexString added in v1.0.1018

func FromHexString(data string) Rsa

Hex

func FromPKCS12Cert added in v1.0.1018

func FromPKCS12Cert(key []byte) Rsa

Pkcs12Cert

func FromPKCS12CertWithPassword added in v1.0.1018

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

Pkcs12Cert 带密码

func FromPKCS1PrivateKey added in v1.0.1018

func FromPKCS1PrivateKey(key []byte) Rsa

PKCS1 私钥

func FromPKCS1PrivateKeyWithPassword added in v1.0.1018

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

PKCS1 私钥带密码

func FromPKCS1PublicKey added in v1.0.1043

func FromPKCS1PublicKey(key []byte) Rsa

PKCS1 公钥

func FromPKCS8PrivateKey added in v1.0.1018

func FromPKCS8PrivateKey(key []byte) Rsa

PKCS8 私钥

func FromPKCS8PrivateKeyWithPassword added in v1.0.1018

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

PKCS8 私钥带密码

func FromPKCS8PublicKey added in v1.0.1043

func FromPKCS8PublicKey(key []byte) Rsa

PKCS8 公钥

func FromPrivateKey added in v1.0.1018

func FromPrivateKey(key []byte) Rsa

私钥

func FromPrivateKeyWithPassword added in v1.0.1018

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

私钥带密码

func FromPublicKey added in v1.0.1018

func FromPublicKey(key []byte) Rsa

公钥

func FromString added in v1.0.1018

func FromString(data string) Rsa

字符

func FromXMLPrivateKey added in v1.0.2013

func FromXMLPrivateKey(key []byte) Rsa

XML 私钥

func FromXMLPublicKey added in v1.0.2013

func FromXMLPublicKey(key []byte) Rsa

XML 公钥

func GenerateKey added in v1.0.1018

func GenerateKey(bits int) Rsa

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

func GenerateMultiPrimeKey added in v1.0.1051

func GenerateMultiPrimeKey(nprimes int, bits int) Rsa

生成密钥

func New added in v1.0.1018

func New() Rsa

构造函数

func NewRsa

func NewRsa() Rsa

构造函数

func (Rsa) AppendError added in v1.0.1026

func (this Rsa) AppendError(err ...error) Rsa

添加错误

func (Rsa) CheckKeyPair added in v1.0.1043

func (this Rsa) CheckKeyPair() bool

检测公钥私钥是否匹配

func (Rsa) CreatePKCS1PrivateKey

func (this Rsa) CreatePKCS1PrivateKey() Rsa

生成 PKCS1 私钥

func (Rsa) CreatePKCS1PrivateKeyWithPassword

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

生成 PKCS1 私钥带密码 pem 数据 CreatePKCS1PrivateKeyWithPassword("123", "AES256CBC")

func (Rsa) CreatePKCS1PublicKey added in v1.0.1043

func (this Rsa) CreatePKCS1PublicKey() Rsa

生成 pcks1 公钥 pem 数据

func (Rsa) CreatePKCS8PrivateKey

func (this Rsa) CreatePKCS8PrivateKey() Rsa

生成 PKCS8 私钥 pem 数据

func (Rsa) CreatePKCS8PrivateKeyWithPassword

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

生成 PKCS8 私钥带密码 pem 数据 CreatePKCS8PrivateKeyWithPassword("123", "AES256CBC", "SHA256")

func (Rsa) CreatePKCS8PublicKey added in v1.0.1043

func (this Rsa) CreatePKCS8PublicKey() Rsa

生成公钥 pem 数据

func (Rsa) CreatePrivateKey

func (this Rsa) CreatePrivateKey() Rsa

生成私钥 pem 数据, PKCS1 别名 使用: obj := New().GenerateKey(2048) priKey := obj.CreatePrivateKey().ToKeyString()

func (Rsa) CreatePrivateKeyWithPassword

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

生成私钥带密码 pem 数据, PKCS1 别名

func (Rsa) CreateXMLPrivateKey added in v1.0.2002

func (this Rsa) CreateXMLPrivateKey() Rsa

生成私钥 xml 数据

func (Rsa) CreateXMLPublicKey added in v1.0.2002

func (this Rsa) CreateXMLPublicKey() Rsa

生成公钥 xml 数据

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) Error

func (this Rsa) Error() error

获取错误

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) FromPKCS1PublicKey added in v1.0.1043

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

PKCS1 公钥

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) FromPKCS8PublicKey added in v1.0.1043

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

PKCS8 公钥

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) FromPublicKeyNE added in v1.0.1018

func (this Rsa) FromPublicKeyNE(nString string, e int) Rsa

模数、指数生成公钥 指数默认为 10001

func (Rsa) FromString

func (this Rsa) FromString(data string) Rsa

字符

func (Rsa) FromXMLPrivateKey added in v1.0.2002

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

XML 私钥

func (Rsa) FromXMLPublicKey added in v1.0.2002

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

XML 公钥

func (Rsa) GenerateKey

func (this Rsa) GenerateKey(bits int) Rsa

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

func (Rsa) GenerateMultiPrimeKey added in v1.0.1050

func (this Rsa) GenerateMultiPrimeKey(nprimes int, bits int) Rsa

生成密钥

func (Rsa) GetData

func (this Rsa) GetData() []byte

获取 data

func (Rsa) GetErrors added in v1.0.1026

func (this Rsa) GetErrors() []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) GetPublicKeyE added in v1.0.1018

func (this Rsa) GetPublicKeyE() int

获取 PublicKeyE

func (Rsa) GetPublicKeyNHexString added in v1.0.1018

func (this Rsa) GetPublicKeyNHexString() string

获取 PublicKeyN

func (Rsa) GetSignHash

func (this Rsa) GetSignHash() string

获取 hash 类型

func (Rsa) GetVerify added in v1.0.1032

func (this Rsa) GetVerify() bool

获取验证后情况

func (Rsa) MakeKeyDer added in v1.0.1033

func (this Rsa) MakeKeyDer() Rsa

生成密钥 der 数据

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) PSSVerify added in v1.0.1033

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

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

func (Rsa) ParsePKCS12CertFromPEMWithPassword added in v1.0.1043

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

解析 pkf 证书

func (Rsa) ParsePKCS1PublicKeyFromPEM added in v1.0.1043

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

解析 PKCS1 公钥

func (Rsa) ParsePKCS8PrivateKeyFromPEMWithPassword added in v1.0.1043

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

解析 PKCS8 带密码的私钥

func (Rsa) ParsePKCS8PublicKeyFromPEM added in v1.0.1043

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

解析 PKCS8 公钥

func (Rsa) ParsePrivateKeyFromPEM added in v1.0.1043

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

解析 PKCS1 / PKCS8 私钥

func (Rsa) ParsePrivateKeyFromPEMWithPassword added in v1.0.1043

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

解析 PKCS1 带密码的私钥

func (Rsa) ParsePrivateKeyFromXML added in v1.0.2002

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

解析 xml 私钥

func (Rsa) ParsePublicKeyFromXML added in v1.0.2002

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

解析 xml 公钥

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) ToVerify added in v1.0.1032

func (this Rsa) ToVerify() bool

验证结果

func (Rsa) ToVerifyInt added in v1.0.1033

func (this Rsa) ToVerifyInt() int

验证结果,返回 int 类型

func (Rsa) Verify added in v1.0.1033

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

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

func (Rsa) WithData

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

设置 data

func (Rsa) WithError

func (this Rsa) WithError(errs []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) WithVerify added in v1.0.1032

func (this Rsa) WithVerify(data bool) Rsa

设置 verify

type RsaErrorFunc

type RsaErrorFunc = func([]error)

错误方法

type ScryptOpts added in v1.0.1018

type ScryptOpts = cryptobin_pkcs8.ScryptOpts

Scrypt 配置

Jump to

Keyboard shortcuts

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