rsa

package
v1.0.1028 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

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

Pkcs12 Cert

func FromPKCS12CertWithPassword added in v1.0.1018

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

Pkcs12CertWithPassword

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

Pkcs1WithPassword

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

Pkcs8WithPassword

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

func GenerateKey(bits int) Rsa

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

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) 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) CreatePKCS8KdfPrivateKeyWithPassword added in v1.0.1022

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

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

func (Rsa) CreatePKCS8PbePrivateKeyWithPassword added in v1.0.1022

func (this Rsa) CreatePKCS8PbePrivateKeyWithPassword(password string, alg string) Rsa

生成 PKCS8 私钥带密码 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) 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) CreatePublicKey

func (this Rsa) CreatePublicKey() Rsa

生成公钥 pem 数据

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() cryptobin_tool.Errors

获取错误

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

func (this Rsa) GenerateKey(bits int) Rsa

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

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) 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(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) WithVeryed

func (this Rsa) WithVeryed(data bool) Rsa

设置 veryed

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