rsa

package
v1.0.3009 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2024 License: Apache-2.0 Imports: 16 Imported by: 1

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

Functions

This section is empty.

Types

type OAEPOptions added in v1.0.2054

type OAEPOptions = rsa.OAEPOptions

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

type Opts added in v1.0.1018

type Opts = pkcs8.Opts

配置

type PBKDF2Opts added in v1.0.1018

type PBKDF2Opts = pkcs8.PBKDF2Opts

PBKDF2 配置

type PKCS1v15DecryptOptions added in v1.0.2054

type PKCS1v15DecryptOptions = rsa.PKCS1v15DecryptOptions

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

type RSA added in v1.0.2048

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

func FromPublicKeyNE(nString string, eString string) 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 GenerateKeyWithSeed added in v1.0.2026

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

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

func GenerateMultiPrimeKey added in v1.0.1051

func GenerateMultiPrimeKey(nprimes int, bits int) RSA

生成密钥

func GenerateMultiPrimeKeyWithSeed added in v1.0.2026

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

生成密钥

func New added in v1.0.1018

func New() RSA

构造函数

func NewRSA added in v1.0.2048

func NewRSA() RSA

构造函数

func (RSA) AppendError added in v1.0.2048

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

添加错误

func (RSA) CheckKeyPair added in v1.0.2048

func (this RSA) CheckKeyPair() bool

检测公钥私钥是否匹配

func (RSA) CreatePKCS1PrivateKey added in v1.0.2048

func (this RSA) CreatePKCS1PrivateKey() RSA

生成 PKCS1 私钥

func (RSA) CreatePKCS1PrivateKeyWithPassword added in v1.0.2048

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

生成 PKCS1 私钥带密码 pem 数据 CreatePKCS1PrivateKeyWithPassword("123", "AES256CBC") PEMCipher: DESCBC | DESEDE3CBC | AES128CBC | AES192CBC | AES256CBC

func (RSA) CreatePKCS1PublicKey added in v1.0.2048

func (this RSA) CreatePKCS1PublicKey() RSA

生成 pcks1 公钥 pem 数据

func (RSA) CreatePKCS8PrivateKey added in v1.0.2048

func (this RSA) CreatePKCS8PrivateKey() RSA

生成 PKCS8 私钥 pem 数据

func (RSA) CreatePKCS8PrivateKeyWithPassword added in v1.0.2048

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

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

func (RSA) CreatePKCS8PublicKey added in v1.0.2048

func (this RSA) CreatePKCS8PublicKey() RSA

生成公钥 pem 数据

func (RSA) CreatePrivateKey added in v1.0.2048

func (this RSA) CreatePrivateKey() RSA

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

func (RSA) CreatePrivateKeyWithPassword added in v1.0.2048

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

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

func (RSA) CreatePublicKey added in v1.0.2048

func (this RSA) CreatePublicKey() RSA

生成公钥 pem 数据

func (RSA) CreateXMLPrivateKey added in v1.0.2048

func (this RSA) CreateXMLPrivateKey() RSA

生成私钥 xml 数据

func (RSA) CreateXMLPublicKey added in v1.0.2048

func (this RSA) CreateXMLPublicKey() RSA

生成公钥 xml 数据

func (RSA) Decrypt added in v1.0.2048

func (this RSA) Decrypt() RSA

私钥解密

func (RSA) DecryptECB added in v1.0.2048

func (this RSA) DecryptECB() RSA

私钥解密, ECB 模式

func (RSA) DecryptECBWithOpts added in v1.0.2054

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

私钥解密, ECB 模式

func (RSA) DecryptOAEP added in v1.0.2048

func (this RSA) DecryptOAEP() RSA

OAEP私钥解密

func (RSA) DecryptOAEPECB added in v1.0.2048

func (this RSA) DecryptOAEPECB() RSA

OAEP私钥解密, ECB 模式

func (RSA) DecryptWithOpts added in v1.0.2053

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

私钥解密带设置

func (RSA) Encrypt added in v1.0.2048

func (this RSA) Encrypt() RSA

公钥加密

func (RSA) EncryptECB added in v1.0.2048

func (this RSA) EncryptECB() RSA

公钥加密, ECB 模式

func (RSA) EncryptOAEP added in v1.0.2048

func (this RSA) EncryptOAEP() RSA

OAEP公钥加密

func (RSA) EncryptOAEPECB added in v1.0.2048

func (this RSA) EncryptOAEPECB() RSA

OAEP公钥加密, ECB 模式

func (RSA) Error added in v1.0.2048

func (this RSA) Error() error

获取错误

func (RSA) FromBase64String added in v1.0.2048

func (this RSA) FromBase64String(data string) RSA

Base64

func (RSA) FromBytes added in v1.0.2048

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

字节

func (RSA) FromHexString added in v1.0.2048

func (this RSA) FromHexString(data string) RSA

Hex

func (RSA) FromPKCS12Cert added in v1.0.2048

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

Pkcs12 Cert

func (RSA) FromPKCS12CertWithPassword added in v1.0.2048

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

Pkcs12CertWithPassword

func (RSA) FromPKCS1PrivateKey added in v1.0.2048

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

Pkcs1

func (RSA) FromPKCS1PrivateKeyDer added in v1.0.2048

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

Pkcs1 DER

func (RSA) FromPKCS1PrivateKeyWithPassword added in v1.0.2048

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

Pkcs1WithPassword

func (RSA) FromPKCS1PublicKey added in v1.0.2048

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

PKCS1 公钥

func (RSA) FromPKCS1PublicKeyDer added in v1.0.2048

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

PKCS1 DER 公钥

func (RSA) FromPKCS8PrivateKey added in v1.0.2048

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

Pkcs8

func (RSA) FromPKCS8PrivateKeyDer added in v1.0.2048

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

Pkcs8 DER

func (RSA) FromPKCS8PrivateKeyWithPassword added in v1.0.2048

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

Pkcs8WithPassword

func (RSA) FromPKCS8PublicKey added in v1.0.2048

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

PKCS8 公钥

func (RSA) FromPKCS8PublicKeyDer added in v1.0.2048

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

PKCS8 DER 公钥

func (RSA) FromPrivateKey added in v1.0.2048

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

私钥

func (RSA) FromPrivateKeyWithPassword added in v1.0.2048

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

私钥带密码

func (RSA) FromPublicKey added in v1.0.2048

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

公钥

func (RSA) FromPublicKeyNE added in v1.0.2048

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

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

func (RSA) FromString added in v1.0.2048

func (this RSA) FromString(data string) RSA

字符

func (RSA) FromXMLPrivateKey added in v1.0.2048

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

XML 私钥

func (RSA) FromXMLPublicKey added in v1.0.2048

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

XML 公钥

func (RSA) GenerateKey added in v1.0.2048

func (this RSA) GenerateKey(bits int) RSA

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

func (RSA) GenerateKeyWithSeed added in v1.0.2048

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

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

func (RSA) GenerateMultiPrimeKey added in v1.0.2048

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

生成密钥

func (RSA) GenerateMultiPrimeKeyWithSeed added in v1.0.2048

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

生成密钥

func (RSA) GetData added in v1.0.2048

func (this RSA) GetData() []byte

获取 data

func (RSA) GetErrors added in v1.0.2048

func (this RSA) GetErrors() []error

获取错误

func (RSA) GetKeyData added in v1.0.2048

func (this RSA) GetKeyData() []byte

获取 keyData

func (RSA) GetOAEPHash added in v1.0.2053

func (this RSA) GetOAEPHash() hash.Hash

获取 oaepHash 类型

func (RSA) GetOAEPLabel added in v1.0.2053

func (this RSA) GetOAEPLabel() []byte

获取 oaepLabel

func (RSA) GetParsedData added in v1.0.2049

func (this RSA) GetParsedData() []byte

获取 parsedData

func (RSA) GetPrivateKey added in v1.0.2048

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

获取 PrivateKey

func (RSA) GetPublicKey added in v1.0.2048

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

获取 PublicKey

func (RSA) GetPublicKeyEString added in v1.0.2071

func (this RSA) GetPublicKeyEString() string

获取 PublicKeyE

func (RSA) GetPublicKeyNString added in v1.0.2071

func (this RSA) GetPublicKeyNString() string

获取 PublicKeyN

func (RSA) GetSignHash added in v1.0.2048

func (this RSA) GetSignHash() crypto.Hash

获取 hash 类型

func (RSA) GetVerify added in v1.0.2048

func (this RSA) GetVerify() bool

获取验证后情况

func (RSA) LowerSafeDecrypt added in v1.0.2053

func (this RSA) LowerSafeDecrypt() RSA

私钥解密 rsa no padding decrypt

func (RSA) LowerSafeEncrypt added in v1.0.2053

func (this RSA) LowerSafeEncrypt() RSA

公钥加密 rsa no padding encrypt

func (RSA) MakeKeyDer added in v1.0.2048

func (this RSA) MakeKeyDer() RSA

生成密钥 der 数据

func (RSA) MakePublicKey added in v1.0.2048

func (this RSA) MakePublicKey() RSA

生成公钥

func (RSA) OnError added in v1.0.2048

func (this RSA) OnError(fn RsaErrorFunc) RSA

引出错误信息

func (RSA) ParsePKCS12CertFromPEMWithPassword added in v1.0.2048

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

解析 pkf 证书

func (RSA) ParsePKCS1PrivateKeyFromPEM added in v1.0.2048

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

解析 PKCS1 私钥

func (RSA) ParsePKCS1PrivateKeyFromPEMWithPassword added in v1.0.2048

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

解析 PKCS1 带密码的私钥

func (RSA) ParsePKCS1PublicKeyFromPEM added in v1.0.2048

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

解析 PKCS1 公钥

func (RSA) ParsePKCS8PrivateKeyFromPEM added in v1.0.2048

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

解析 PKCS8 私钥

func (RSA) ParsePKCS8PrivateKeyFromPEMWithPassword added in v1.0.2048

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

解析 PKCS8 带密码的私钥

func (RSA) ParsePKCS8PublicKeyFromPEM added in v1.0.2048

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

解析 PKCS8 公钥

func (RSA) ParsePrivateKeyFromXML added in v1.0.2048

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

解析 xml 私钥

func (RSA) ParsePublicKeyFromXML added in v1.0.2048

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

解析 xml 公钥

func (RSA) PrivateKeyEncrypt added in v1.0.2048

func (this RSA) PrivateKeyEncrypt() RSA

私钥加密

func (RSA) PrivateKeyEncryptECB added in v1.0.2048

func (this RSA) PrivateKeyEncryptECB() RSA

私钥加密, ECB 模式

func (RSA) PublicKeyDecrypt added in v1.0.2048

func (this RSA) PublicKeyDecrypt() RSA

公钥解密

func (RSA) PublicKeyDecryptECB added in v1.0.2048

func (this RSA) PublicKeyDecryptECB() RSA

公钥解密, ECB 模式

func (RSA) SetKeyData added in v1.0.2053

func (this RSA) SetKeyData(data string) RSA

设置 keyData

func (RSA) SetOAEPHash added in v1.0.2053

func (this RSA) SetOAEPHash(name string) RSA

设置 oaepHash 类型

func (RSA) SetOAEPLabel added in v1.0.2053

func (this RSA) SetOAEPLabel(data string) RSA

设置 oaepLabel

func (RSA) SetSignHash added in v1.0.2048

func (this RSA) SetSignHash(name string) RSA

设置 hash 类型

func (RSA) Sign added in v1.0.2048

func (this RSA) Sign() RSA

私钥签名

func (RSA) SignPSS added in v1.0.2048

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

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

func (RSA) ToBase64String added in v1.0.2048

func (this RSA) ToBase64String() string

输出Base64

func (RSA) ToBytes added in v1.0.2048

func (this RSA) ToBytes() []byte

输出字节

func (RSA) ToHexString added in v1.0.2048

func (this RSA) ToHexString() string

输出Hex

func (RSA) ToKeyBytes added in v1.0.2048

func (this RSA) ToKeyBytes() []byte

私钥/公钥

func (RSA) ToKeyString added in v1.0.2048

func (this RSA) ToKeyString() string

私钥/公钥

func (RSA) ToString added in v1.0.2048

func (this RSA) ToString() string

输出字符

func (RSA) ToVerify added in v1.0.2048

func (this RSA) ToVerify() bool

验证结果

func (RSA) ToVerifyInt added in v1.0.2048

func (this RSA) ToVerifyInt() int

验证结果,返回 int 类型

func (RSA) Verify added in v1.0.2048

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

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

func (RSA) VerifyPSS added in v1.0.2048

func (this RSA) VerifyPSS(data []byte, opts ...rsa.PSSOptions) RSA

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

func (RSA) WithData added in v1.0.2048

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

设置 data

func (RSA) WithError added in v1.0.2048

func (this RSA) WithError(errs []error) RSA

设置错误

func (RSA) WithKeyData added in v1.0.2053

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

设置 keyData

func (RSA) WithOAEPHash added in v1.0.2053

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

设置 oaepHash

func (RSA) WithOAEPLabel added in v1.0.2053

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

设置 oaepLabel

func (RSA) WithParsedData added in v1.0.2049

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

设置 parsedData

func (RSA) WithPrivateKey added in v1.0.2048

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

设置 PrivateKey

func (RSA) WithPublicKey added in v1.0.2048

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

设置 PublicKey

func (RSA) WithSignHash added in v1.0.2048

func (this RSA) WithSignHash(h crypto.Hash) RSA

设置 hash 类型

func (RSA) WithVerify added in v1.0.2048

func (this RSA) WithVerify(data bool) RSA

设置 verify

type RsaErrorFunc

type RsaErrorFunc = func([]error)

错误方法

type ScryptOpts added in v1.0.1018

type ScryptOpts = pkcs8.ScryptOpts

Scrypt 配置

Jump to

Keyboard shortcuts

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