rsa

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// 获取 Cipher 类型
	GetCipherFromName = pkcs8.GetCipherFromName
	// 获取 hash 类型
	GetHashFromName = pkcs8.GetHashFromName
)
View Source
var (
	ErrKeyMustBePEMEncoded = errors.New("go-cryptobin/rsa: invalid key: Key must be a PEM encoded PKCS1 or PKCS8 key")
	ErrNotRSAPrivateKey    = errors.New("go-cryptobin/rsa: key is not a valid RSA private key")
	ErrNotRSAPublicKey     = errors.New("go-cryptobin/rsa: key is not a valid RSA public key")
)

Functions

This section is empty.

Types

type OAEPOptions

type OAEPOptions = rsa.OAEPOptions

OAEPOptions is an interface for passing options to OAEP decryption using the crypto.Decrypter interface.

type Opts

type Opts = pkcs8.Opts

配置

type PBKDF2Opts

type PBKDF2Opts = pkcs8.PBKDF2Opts

PBKDF2 配置

type PKCS1v15DecryptOptions

type PKCS1v15DecryptOptions = rsa.PKCS1v15DecryptOptions

PKCS1v15DecryptOptions is for passing options to PKCS #1 v1.5 decryption using the crypto.Decrypter interface.

type RSA

type RSA struct {

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

*

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

func FromBase64String

func FromBase64String(data string) RSA

Base64

func FromBytes

func FromBytes(data []byte) RSA

字节

func FromHexString

func FromHexString(data string) RSA

Hex

func FromPKCS1PrivateKey

func FromPKCS1PrivateKey(key []byte) RSA

PKCS1 私钥

func FromPKCS1PrivateKeyWithPassword

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

PKCS1 私钥带密码

func FromPKCS1PublicKey

func FromPKCS1PublicKey(key []byte) RSA

PKCS1 公钥

func FromPKCS8PrivateKey

func FromPKCS8PrivateKey(key []byte) RSA

PKCS8 私钥

func FromPKCS8PrivateKeyWithPassword

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

PKCS8 私钥带密码

func FromPKCS8PublicKey

func FromPKCS8PublicKey(key []byte) RSA

PKCS8 公钥

func FromPKCS12Cert

func FromPKCS12Cert(key []byte) RSA

Pkcs12Cert

func FromPKCS12CertWithPassword

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

Pkcs12Cert 带密码

func FromPrivateKey

func FromPrivateKey(key []byte) RSA

私钥

func FromPrivateKeyWithPassword

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

私钥带密码

func FromPublicKey

func FromPublicKey(key []byte) RSA

公钥

func FromPublicKeyNE

func FromPublicKeyNE(nString string, eString string) RSA

公钥

func FromString

func FromString(data string) RSA

字符

func FromXMLPrivateKey

func FromXMLPrivateKey(key []byte) RSA

XML 私钥

func FromXMLPublicKey

func FromXMLPublicKey(key []byte) RSA

XML 公钥

func GenerateKey

func GenerateKey(bits int) RSA

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

func GenerateKeyWithSeed

func GenerateKeyWithSeed(reader io.Reader, bits int) RSA

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

func GenerateMultiPrimeKey

func GenerateMultiPrimeKey(nprimes int, bits int) RSA

生成密钥

func GenerateMultiPrimeKeyWithSeed

func GenerateMultiPrimeKeyWithSeed(reader io.Reader, nprimes int, bits int) RSA

生成密钥

func New

func New() RSA

构造函数

func NewRSA

func NewRSA() RSA

构造函数

func (RSA) AppendError

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

添加错误

func (RSA) CheckKeyPair

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") PEMCipher: DESCBC | DESEDE3CBC | AES128CBC | AES192CBC | AES256CBC

func (RSA) CreatePKCS1PublicKey

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

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

func (this RSA) CreatePublicKey() RSA

生成公钥 pem 数据

func (RSA) CreateXMLPrivateKey

func (this RSA) CreateXMLPrivateKey() RSA

生成私钥 xml 数据

func (RSA) CreateXMLPublicKey

func (this RSA) CreateXMLPublicKey() RSA

生成公钥 xml 数据

func (RSA) Decrypt

func (this RSA) Decrypt() RSA

私钥解密

func (RSA) DecryptECB

func (this RSA) DecryptECB() RSA

私钥解密, ECB 模式

func (RSA) DecryptECBWithOpts

func (this RSA) DecryptECBWithOpts(opts crypto.DecrypterOpts) RSA

私钥解密, ECB 模式

func (RSA) DecryptOAEP

func (this RSA) DecryptOAEP() RSA

OAEP私钥解密

func (RSA) DecryptOAEPECB

func (this RSA) DecryptOAEPECB() RSA

OAEP私钥解密, ECB 模式

func (RSA) DecryptWithOpts

func (this RSA) DecryptWithOpts(opts crypto.DecrypterOpts) RSA

私钥解密带设置

func (RSA) Encrypt

func (this RSA) Encrypt() RSA

公钥加密

func (RSA) EncryptECB

func (this RSA) EncryptECB() RSA

公钥加密, ECB 模式

func (RSA) EncryptOAEP

func (this RSA) EncryptOAEP() RSA

OAEP公钥加密

func (RSA) EncryptOAEPECB

func (this RSA) EncryptOAEPECB() RSA

OAEP公钥加密, ECB 模式

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

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

Pkcs1

func (RSA) FromPKCS1PrivateKeyDer

func (this RSA) FromPKCS1PrivateKeyDer(der []byte) RSA

Pkcs1 DER

func (RSA) FromPKCS1PrivateKeyWithPassword

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

Pkcs1WithPassword

func (RSA) FromPKCS1PublicKey

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

PKCS1 公钥

func (RSA) FromPKCS1PublicKeyDer

func (this RSA) FromPKCS1PublicKeyDer(der []byte) RSA

PKCS1 DER 公钥

func (RSA) FromPKCS8PrivateKey

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

Pkcs8

func (RSA) FromPKCS8PrivateKeyDer

func (this RSA) FromPKCS8PrivateKeyDer(der []byte) RSA

Pkcs8 DER

func (RSA) FromPKCS8PrivateKeyWithPassword

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

Pkcs8WithPassword

func (RSA) FromPKCS8PublicKey

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

PKCS8 公钥

func (RSA) FromPKCS8PublicKeyDer

func (this RSA) FromPKCS8PublicKeyDer(der []byte) RSA

PKCS8 DER 公钥

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

func (this RSA) FromPublicKeyNE(nString string, eString string) RSA

模数、指数生成公钥 指数默认为 0x10001(65537)

func (RSA) FromString

func (this RSA) FromString(data string) RSA

字符

func (RSA) FromXMLPrivateKey

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

XML 私钥

func (RSA) FromXMLPublicKey

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

func (this RSA) GenerateKeyWithSeed(reader io.Reader, bits int) RSA

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

func (RSA) GenerateMultiPrimeKey

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

生成密钥

func (RSA) GenerateMultiPrimeKeyWithSeed

func (this RSA) GenerateMultiPrimeKeyWithSeed(reader io.Reader, nprimes int, bits int) RSA

生成密钥

func (RSA) GetData

func (this RSA) GetData() []byte

获取 data

func (RSA) GetErrors

func (this RSA) GetErrors() []error

获取错误

func (RSA) GetKeyData

func (this RSA) GetKeyData() []byte

获取 keyData

func (RSA) GetOAEPHash

func (this RSA) GetOAEPHash() hash.Hash

获取 oaepHash 类型

func (RSA) GetOAEPLabel

func (this RSA) GetOAEPLabel() []byte

获取 oaepLabel

func (RSA) GetParsedData

func (this RSA) GetParsedData() []byte

获取 parsedData

func (RSA) GetPrivateKey

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

获取 PrivateKey

func (RSA) GetPublicKey

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

获取 PublicKey

func (RSA) GetPublicKeyEString

func (this RSA) GetPublicKeyEString() string

获取 PublicKeyE

func (RSA) GetPublicKeyNString

func (this RSA) GetPublicKeyNString() string

获取 PublicKeyN

func (RSA) GetSignHash

func (this RSA) GetSignHash() crypto.Hash

获取 hash 类型

func (RSA) GetVerify

func (this RSA) GetVerify() bool

获取验证后情况

func (RSA) LowerSafeDecrypt

func (this RSA) LowerSafeDecrypt() RSA

私钥解密 rsa no padding decrypt

func (RSA) LowerSafeEncrypt

func (this RSA) LowerSafeEncrypt() RSA

公钥加密 rsa no padding encrypt

func (RSA) MakeKeyDer

func (this RSA) MakeKeyDer() RSA

生成密钥 der 数据

func (RSA) MakePublicKey

func (this RSA) MakePublicKey() RSA

生成公钥

func (RSA) OnError

func (this RSA) OnError(fn func([]error)) RSA

引出错误信息

func (RSA) ParsePKCS1PrivateKeyFromPEM

func (this RSA) ParsePKCS1PrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error)

解析 PKCS1 私钥

func (RSA) ParsePKCS1PrivateKeyFromPEMWithPassword

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

解析 PKCS1 带密码的私钥

func (RSA) ParsePKCS1PublicKeyFromPEM

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

解析 PKCS1 公钥

func (RSA) ParsePKCS8PrivateKeyFromPEM

func (this RSA) ParsePKCS8PrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error)

解析 PKCS8 私钥

func (RSA) ParsePKCS8PrivateKeyFromPEMWithPassword

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

解析 PKCS8 带密码的私钥

func (RSA) ParsePKCS8PublicKeyFromPEM

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

解析 PKCS8 公钥

func (RSA) ParsePKCS12CertFromPEMWithPassword

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

解析 pkf 证书

func (RSA) ParsePrivateKeyFromXML

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

解析 xml 私钥

func (RSA) ParsePublicKeyFromXML

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

解析 xml 公钥

func (RSA) PrivateKeyEncrypt

func (this RSA) PrivateKeyEncrypt() RSA

私钥加密

func (RSA) PrivateKeyEncryptECB

func (this RSA) PrivateKeyEncryptECB() RSA

私钥加密, ECB 模式

func (RSA) PublicKeyDecrypt

func (this RSA) PublicKeyDecrypt() RSA

公钥解密

func (RSA) PublicKeyDecryptECB

func (this RSA) PublicKeyDecryptECB() RSA

公钥解密, ECB 模式

func (RSA) SetKeyData

func (this RSA) SetKeyData(data string) RSA

设置 keyData

func (RSA) SetOAEPHash

func (this RSA) SetOAEPHash(name string) RSA

设置 OAEP Hash 类型

func (RSA) SetOAEPLabel

func (this RSA) SetOAEPLabel(data string) RSA

设置 OAEP Label

func (RSA) SetSignHash

func (this RSA) SetSignHash(name string) RSA

设置 hash 类型

func (RSA) Sign

func (this RSA) Sign() RSA

私钥签名

func (RSA) SignPSS

func (this RSA) SignPSS(opts ...rsa.PSSOptions) RSA

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

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

func (this RSA) ToVerify() bool

验证结果

func (RSA) ToVerifyInt

func (this RSA) ToVerifyInt() int

验证结果,返回 int 类型

func (RSA) Verify

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

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

func (RSA) VerifyPSS

func (this RSA) VerifyPSS(data []byte, opts ...rsa.PSSOptions) 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) WithKeyData

func (this RSA) WithKeyData(data []byte) RSA

设置 keyData

func (RSA) WithOAEPHash

func (this RSA) WithOAEPHash(h hash.Hash) RSA

设置 OAEP Hash

func (RSA) WithOAEPLabel

func (this RSA) WithOAEPLabel(data []byte) RSA

设置 OAEP Label

func (RSA) WithParsedData

func (this RSA) WithParsedData(data []byte) RSA

设置 parsedData

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(h crypto.Hash) RSA

设置 hash 类型

func (RSA) WithVerify

func (this RSA) WithVerify(data bool) RSA

设置 verify

type ScryptOpts

type ScryptOpts = pkcs8.ScryptOpts

Scrypt 配置

Jump to

Keyboard shortcuts

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