cryptobin

package
v1.0.1015 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2022 License: Apache-2.0 Imports: 54 Imported by: 0

Documentation

Index

Constants

View Source
const PBKDF2Iterations = 10000

PBKDF2Iterations is the default number of iterations for PBKDF2, 100k iterations. Nist recommends at least 10k, 1Passsword uses 100k.

View Source
const PBKDF2SaltSize = 16

PBKDF2SaltSize is the default size of the salt for PBKDF2, 128-bit salt.

Variables

View Source
var (
	ErrNotDSAPrivateKey = errors.New("key is not a valid DSA private key")
	ErrNotDSAPublicKey  = errors.New("key is not a valid DSA public key")
)
View Source
var (
	ErrNotECPublicKey  = errors.New("key is not a valid ECDSA public key")
	ErrNotECPrivateKey = errors.New("key is not a valid ECDSA private key")
)
View Source
var (
	ErrNotEdPrivateKey = errors.New("key is not a valid Ed25519 private key")
	ErrNotEdPublicKey  = errors.New("key is not a valid Ed25519 public key")
)
View Source
var (
	// 创建私钥默认可用选项
	// HMACHash 目前支持 SHA256 和 SHA1
	Youmark_PKCS8_AES128CBC_SHA256 = youmarkPKCS8.Opts{
		Cipher: youmarkPKCS8.AES128CBC,
		KDFOpts: youmarkPKCS8.PBKDF2Opts{
			SaltSize:       8,
			IterationCount: 2048,
			HMACHash:       crypto.SHA256,
		},
	}

	Youmark_PKCS8_AES192CBC_SHA256 = youmarkPKCS8.Opts{
		Cipher: youmarkPKCS8.AES192CBC,
		KDFOpts: youmarkPKCS8.PBKDF2Opts{
			SaltSize:       8,
			IterationCount: 1000,
			HMACHash:       crypto.SHA256,
		},
	}

	Youmark_PKCS8_AES256CBC_SHA256 = youmarkPKCS8.Opts{
		Cipher: youmarkPKCS8.AES256CBC,
		KDFOpts: youmarkPKCS8.PBKDF2Opts{
			SaltSize:       16,
			IterationCount: 2000,
			HMACHash:       crypto.SHA256,
		},
	}

	Youmark_PKCS8_AES128GCM_SHA256 = youmarkPKCS8.Opts{
		Cipher: youmarkPKCS8.AES128GCM,
		KDFOpts: youmarkPKCS8.PBKDF2Opts{
			SaltSize:       8,
			IterationCount: 2048,
			HMACHash:       crypto.SHA256,
		},
	}

	Youmark_PKCS8_AES192GCM_SHA256 = youmarkPKCS8.Opts{
		Cipher: youmarkPKCS8.AES192GCM,
		KDFOpts: youmarkPKCS8.PBKDF2Opts{
			SaltSize:       8,
			IterationCount: 10000,
			HMACHash:       crypto.SHA256,
		},
	}

	Youmark_PKCS8_AES256GCM_SHA256 = youmarkPKCS8.Opts{
		Cipher: youmarkPKCS8.AES256GCM,
		KDFOpts: youmarkPKCS8.PBKDF2Opts{
			SaltSize:       16,
			IterationCount: 16,
			HMACHash:       crypto.SHA256,
		},
	}

	Youmark_PKCS8_TripleDESCBC_SHA1 = youmarkPKCS8.Opts{
		Cipher: youmarkPKCS8.TripleDESCBC,
		KDFOpts: youmarkPKCS8.PBKDF2Opts{
			SaltSize:       16,
			IterationCount: 16,
			HMACHash:       crypto.SHA1,
		},
	}

	Youmark_PKCS8_AES256CBC_Scrypt = youmarkPKCS8.Opts{
		Cipher: youmarkPKCS8.AES256CBC,
		KDFOpts: youmarkPKCS8.ScryptOpts{
			CostParameter:            1 << 2,
			BlockSize:                8,
			ParallelizationParameter: 1,
			SaltSize:                 16,
		},
	}
)
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 DefaultOpts = &Opts{
	SaltSize:       PBKDF2SaltSize,
	IterationCount: PBKDF2Iterations,
	HMACHash:       "SHA256",
}

默认配置

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

func AddOidAsn1

func AddOidAsn1(name string, identifier asn1.ObjectIdentifier)

添加 oidAsn1

func AddOidHash

func AddOidHash(name string, value func() hash.Hash)

添加 oidHash

func AddRfc1423Algo

func AddRfc1423Algo(value rfc1423Algo)

添加 rfc1423Algo

func AppendOID added in v1.0.1010

func AppendOID(b asn1.ObjectIdentifier, v ...int) asn1.ObjectIdentifier

最加数据为新的 Identifier

func DecryptPEMBlock

func DecryptPEMBlock(block *pem.Block, password []byte) ([]byte, error)

解出 PEM 块

func DecryptPKCS8PrivateKey

func DecryptPKCS8PrivateKey(data, password []byte) ([]byte, error)

解出 PKCS8 密钥 加密方式: AES-128-CBC | AES-192-CBC | AES-256-CBC | DES | 3DES

func EncryptPKCS8PrivateKey

func EncryptPKCS8PrivateKey(
	rand io.Reader,
	blockType string,
	data []byte,
	password []byte,
	alg x509.PEMCipher,
	opts ...any,
) (*pem.Block, error)

加密 PKCS8

func YoumarkPKCS8MarshalPrivateKey added in v1.0.1012

func YoumarkPKCS8MarshalPrivateKey(priv any, password []byte, opts *youmarkPKCS8.Opts) ([]byte, error)

创建私钥带密码

func YoumarkPKCS8ParsePrivateKey added in v1.0.1012

func YoumarkPKCS8ParsePrivateKey(der []byte, password []byte) (any, youmarkPKCS8.KDFParameters, error)

设置私钥带密码

Types

type CA added in v1.0.1010

type CA struct {

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

*

  • CA *
  • @create 2022-7-22
  • @author deatil

func NewCA added in v1.0.1010

func NewCA() CA

构造函数

func (CA) CreateCA added in v1.0.1010

func (this CA) CreateCA() CA

CA 证书

func (CA) CreateCSR added in v1.0.1010

func (this CA) CreateCSR() CA

证书请求

func (CA) CreateCert added in v1.0.1010

func (this CA) CreateCert(ca any) CA

自签名证书

func (CA) CreatePKCS12Cert added in v1.0.1012

func (this CA) CreatePKCS12Cert(caCerts []*x509.Certificate, pwd string) CA

pkcs12 密钥 caCerts 通常保留为空 支持 [rsa | ecdsa | sm2]

func (CA) CreatePKCS12CertTrustStore added in v1.0.1012

func (this CA) CreatePKCS12CertTrustStore(certs []*x509.Certificate, password string) CA

pkcs12 密钥

func (CA) CreatePrivateKey added in v1.0.1010

func (this CA) CreatePrivateKey() CA

私钥

func (CA) DecodePKCS12CertChain added in v1.0.1012

func (this CA) DecodePKCS12CertChain(pfxData []byte, password string) (privateKey interface{}, certificate *x509.Certificate, caCerts []*x509.Certificate, err error)

解析 pkcs12 cert

func (CA) DecodePKCS12CertTrustStore added in v1.0.1012

func (this CA) DecodePKCS12CertTrustStore(pfxData []byte, password string) (certs []*x509.Certificate, err error)

解析 pkcs12 cert

func (CA) FromCert added in v1.0.1010

func (this CA) FromCert(cert *x509.Certificate) CA

证书

func (CA) FromCertRequest added in v1.0.1010

func (this CA) FromCertRequest(cert *x509.CertificateRequest) CA

证书请求

func (CA) FromCertificateDer added in v1.0.1010

func (this CA) FromCertificateDer(der []byte) CA

解析证书导入

func (CA) FromCertificateRequestDer added in v1.0.1010

func (this CA) FromCertificateRequestDer(asn1Data []byte) CA

解析证书导入

func (CA) FromPKCS12Cert added in v1.0.1012

func (this CA) FromPKCS12Cert(pfxData []byte, password string) CA

pkcs12

func (CA) FromPrivateKey added in v1.0.1010

func (this CA) FromPrivateKey(key any) CA

私钥 可用 [*rsa.PrivateKey | *ecdsa.PrivateKey | ed25519.PrivateKey]

func (CA) FromPublicKey added in v1.0.1010

func (this CA) FromPublicKey(key any) CA

公钥 可用 [*rsa.PublicKey | *ecdsa.PublicKey | ed25519.PublicKey]

func (CA) FromSM2PKCS12Cert added in v1.0.1012

func (this CA) FromSM2PKCS12Cert(pfxData []byte, password string) CA

pkcs12

func (CA) FromSM2PKCS12OneCert added in v1.0.1011

func (this CA) FromSM2PKCS12OneCert(pfxData []byte, password string) CA

pkcs12

func (CA) GenerateEcdsaKey added in v1.0.1010

func (this CA) GenerateEcdsaKey(curve string) CA

生成密钥 Ecdsa 可选 [P521 | P384 | P256 | P224]

func (CA) GenerateEdDSAKey added in v1.0.1010

func (this CA) GenerateEdDSAKey() CA

生成密钥 EdDSA

func (CA) GenerateRsaKey added in v1.0.1010

func (this CA) GenerateRsaKey(bits int) CA

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

func (CA) GenerateSM2Key added in v1.0.1010

func (this CA) GenerateSM2Key() CA

生成密钥 SM2

func (CA) GetCert added in v1.0.1010

func (this CA) GetCert() any

获取 cert

func (CA) GetCertRequest added in v1.0.1010

func (this CA) GetCertRequest() any

获取 certRequest

func (CA) GetError added in v1.0.1010

func (this CA) GetError() error

获取错误

func (CA) GetKeyData added in v1.0.1010

func (this CA) GetKeyData() []byte

获取 keyData

func (CA) GetPrivateKey added in v1.0.1010

func (this CA) GetPrivateKey() any

获取 PrivateKey

func (CA) GetPublicKey added in v1.0.1010

func (this CA) GetPublicKey() any

获取 publicKey

func (CA) GetSM2SignatureAlgorithm added in v1.0.1010

func (this CA) GetSM2SignatureAlgorithm(name string) sm2X509.SignatureAlgorithm

获取 SM2 签名 alg

func (CA) GetSignatureAlgorithm added in v1.0.1010

func (this CA) GetSignatureAlgorithm(name string) x509.SignatureAlgorithm

获取签名 alg

func (CA) MakeCA added in v1.0.1010

func (this CA) MakeCA(
	subject *pkix.Name,
	expire int,
	signAlgName string,
) CA

生成 CA 证书

func (CA) MakeCSR added in v1.0.1010

func (this CA) MakeCSR(
	country []string,
	organization []string,
	organizationalUnit []string,
	locality []string,
	province []string,
	streetAddress []string,
	postalCode []string,
	commonName string,
) CA

生成证书请求

func (CA) MakeCert added in v1.0.1010

func (this CA) MakeCert(
	subject *pkix.Name,
	expire int,
	dns []string,
	ip []net.IP,
	signAlgName string,
) CA

生成自签名证书

func (CA) MakeSM2CA added in v1.0.1010

func (this CA) MakeSM2CA(
	subject *pkix.Name,
	expire int,
	signAlgName string,
) CA

生成 CA 证书

func (CA) MakeSM2CSR added in v1.0.1010

func (this CA) MakeSM2CSR(
	country []string,
	organization []string,
	organizationalUnit []string,
	locality []string,
	province []string,
	streetAddress []string,
	postalCode []string,
	commonName string,
) CA

生成证书请求

func (CA) MakeSM2Cert added in v1.0.1010

func (this CA) MakeSM2Cert(
	subject *pkix.Name,
	expire int,
	dns []string,
	ip []net.IP,
	signAlgName string,
) CA

生成自签名证书

func (CA) OnError added in v1.0.1010

func (this CA) OnError(fn CAErrorFunc) CA

引出错误信息

func (CA) SM2Verify added in v1.0.1011

func (this CA) SM2Verify(rootPEM string, certPEM string, opts sm2X509.VerifyOptions) (bool, error)

SM2 验证

func (CA) ToKeyBytes added in v1.0.1010

func (this CA) ToKeyBytes() []byte

私钥/公钥/cert

func (CA) ToKeyString added in v1.0.1010

func (this CA) ToKeyString() string

私钥/公钥

func (CA) UpdateCert added in v1.0.1010

func (this CA) UpdateCert(fn func(*x509.Certificate) *x509.Certificate) CA

更新 Cert 数据

func (CA) UpdateCertRequest added in v1.0.1010

func (this CA) UpdateCertRequest(fn func(*x509.CertificateRequest) *x509.CertificateRequest) CA

更新证书请求数据

func (CA) UpdateSM2Cert added in v1.0.1010

func (this CA) UpdateSM2Cert(fn func(*x509.Certificate) *x509.Certificate) CA

更新 Cert 数据

func (CA) UpdateSM2CertRequest added in v1.0.1010

func (this CA) UpdateSM2CertRequest(fn func(*x509.CertificateRequest) *x509.CertificateRequest) CA

更新证书请求数据

func (CA) Verify added in v1.0.1011

func (this CA) Verify(rootPEM string, certPEM string, opts x509.VerifyOptions) (bool, error)

验证

func (CA) WithCert added in v1.0.1011

func (this CA) WithCert(data any) CA

设置 cert 可用 [*x509.Certificate | *sm2X509.Certificate]

func (CA) WithCertRequest added in v1.0.1010

func (this CA) WithCertRequest(data any) CA

设置 certRequest 可用 [*x509.CertificateRequest | *sm2X509.CertificateRequest]

func (CA) WithError added in v1.0.1010

func (this CA) WithError(err error) CA

设置错误

func (CA) WithKeyData added in v1.0.1010

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

设置 keyData

func (CA) WithPrivateKey added in v1.0.1010

func (this CA) WithPrivateKey(data any) CA

设置 PrivateKey

func (CA) WithPublicKey added in v1.0.1010

func (this CA) WithPublicKey(data any) CA

设置 publicKey

type CACertificate added in v1.0.1010

type CACertificate = x509.Certificate

证书

type CACertificateRequest added in v1.0.1010

type CACertificateRequest = x509.CertificateRequest

证书请求

type CAErrorFunc added in v1.0.1010

type CAErrorFunc = func(error)

错误方法

type CAExtKeyUsage added in v1.0.1011

type CAExtKeyUsage = x509.ExtKeyUsage

ExtKeyUsage

type CAKeyUsage added in v1.0.1011

type CAKeyUsage = x509.KeyUsage

KeyUsage

type CAPkixAlgorithmIdentifier added in v1.0.1011

type CAPkixAlgorithmIdentifier = pkix.AlgorithmIdentifier

AlgorithmIdentifier

type CAPkixAttributeTypeAndValue added in v1.0.1011

type CAPkixAttributeTypeAndValue = pkix.AttributeTypeAndValue

AttributeTypeAndValue 数据

type CAPkixAttributeTypeAndValueSET added in v1.0.1011

type CAPkixAttributeTypeAndValueSET = pkix.AttributeTypeAndValueSET

AttributeTypeAndValueSET

type CAPkixCertificateList added in v1.0.1011

type CAPkixCertificateList = pkix.CertificateList

CertificateList

type CAPkixExtension added in v1.0.1011

type CAPkixExtension = pkix.Extension

Extension

type CAPkixName added in v1.0.1010

type CAPkixName = pkix.Name

Subject 数据

type CAPkixRDNSequence added in v1.0.1011

type CAPkixRDNSequence = pkix.RDNSequence

RDNSequence

type CAPkixRevokedCertificate added in v1.0.1011

type CAPkixRevokedCertificate = pkix.RevokedCertificate

RevokedCertificate

type CAPkixTBSCertificateList added in v1.0.1011

type CAPkixTBSCertificateList = pkix.TBSCertificateList

TBSCertificateList

type CAPublicKeyAlgorithm added in v1.0.1011

type CAPublicKeyAlgorithm = x509.PublicKeyAlgorithm

PublicKeyAlgorithm

type CASM2Certificate added in v1.0.1010

type CASM2Certificate = sm2X509.Certificate

SM2 证书

type CASM2CertificateRequest added in v1.0.1010

type CASM2CertificateRequest = sm2X509.CertificateRequest

SM2 证书请求

type CASM2ExtKeyUsage added in v1.0.1011

type CASM2ExtKeyUsage = sm2X509.ExtKeyUsage

ExtKeyUsage

type CASM2KeyUsage added in v1.0.1011

type CASM2KeyUsage = sm2X509.KeyUsage

KeyUsage

type CASM2PublicKeyAlgorithm added in v1.0.1011

type CASM2PublicKeyAlgorithm = sm2X509.PublicKeyAlgorithm

PublicKeyAlgorithm

type CASM2SignatureAlgorithm added in v1.0.1011

type CASM2SignatureAlgorithm = sm2X509.SignatureAlgorithm

SignatureAlgorithm

type CASM2VerifyOptions added in v1.0.1011

type CASM2VerifyOptions = sm2X509.VerifyOptions

配置别名

type CASignatureAlgorithm added in v1.0.1011

type CASignatureAlgorithm = x509.SignatureAlgorithm

SignatureAlgorithm

type CAVerifyOptions added in v1.0.1011

type CAVerifyOptions = x509.VerifyOptions

配置别名

type Cipher added in v1.0.1012

type Cipher struct {
	// contains filtered or unexported fields
}

*

  • 加密方式 *
  • @create 2022-7-26
  • @author deatil

func NewCipher added in v1.0.1012

func NewCipher() Cipher

构造函数

func (Cipher) AddFunc added in v1.0.1012

func (this Cipher) AddFunc(name string, block CipherFunc) Cipher

添加

func (Cipher) GetFunc added in v1.0.1012

func (this Cipher) GetFunc(name string) CipherFunc

类型

func (Cipher) WithFunc added in v1.0.1012

func (this Cipher) WithFunc(funcs CipherFuncMap) Cipher

覆盖

type CipherFunc added in v1.0.1012

type CipherFunc = func([]byte) (cipher.Block, error)

CipherFunc

type CipherFuncMap added in v1.0.1012

type CipherFuncMap = map[string]CipherFunc

CipherFunc map 列表

type CryptoHashMap added in v1.0.1006

type CryptoHashMap = map[string]crypto.Hash

hash

type Cryptobin

type Cryptobin struct {

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

*

  • 对称加密 *
  • @create 2022-3-19
  • @author deatil

func FromBase64String

func FromBase64String(data string) Cryptobin

Base64

func FromBytes

func FromBytes(data []byte) Cryptobin

字节

func FromHexString

func FromHexString(data string) Cryptobin

Hex

func FromString

func FromString(data string) Cryptobin

字符

func New

func New() Cryptobin

构造函数

func (Cryptobin) Aes

func (this Cryptobin) Aes() Cryptobin

Aes

func (Cryptobin) AesCFBDecrypt

func (this Cryptobin) AesCFBDecrypt() Cryptobin

解密

func (Cryptobin) AesCFBEncrypt

func (this Cryptobin) AesCFBEncrypt() Cryptobin

加密

func (Cryptobin) AesECBDecrypt

func (this Cryptobin) AesECBDecrypt() Cryptobin

func (Cryptobin) AesECBEncrypt

func (this Cryptobin) AesECBEncrypt() Cryptobin

func (Cryptobin) AesECBGenerateKey

func (this Cryptobin) AesECBGenerateKey(key []byte) (genKey []byte)

func (Cryptobin) Blowfish added in v1.0.2

func (this Cryptobin) Blowfish(salt ...string) Cryptobin

Blowfish

func (Cryptobin) CBC

func (this Cryptobin) CBC() Cryptobin

CBC

func (Cryptobin) CFB

func (this Cryptobin) CFB() Cryptobin

CFB

func (Cryptobin) CTR

func (this Cryptobin) CTR() Cryptobin

CTR

func (Cryptobin) Cast5 added in v1.0.2

func (this Cryptobin) Cast5() Cryptobin

Cast5

func (Cryptobin) Chacha20 added in v1.0.2

func (this Cryptobin) Chacha20(nonce string, counter ...uint32) Cryptobin

Chacha20

func (Cryptobin) Chacha20poly1305 added in v1.0.2

func (this Cryptobin) Chacha20poly1305(nonce string, additional string) Cryptobin

Chacha20poly1305 nonce is 12 bytes

func (Cryptobin) CheckGuessMultiple added in v1.0.1012

func (this Cryptobin) CheckGuessMultiple() bool

检测 guess 方式

func (Cryptobin) CipherBlock

func (this Cryptobin) CipherBlock(key []byte) (cipher.Block, error)

Cipher

func (Cryptobin) CipherDecrypt added in v1.0.2

func (this Cryptobin) CipherDecrypt() Cryptobin

解密

func (Cryptobin) CipherEncrypt added in v1.0.2

func (this Cryptobin) CipherEncrypt() Cryptobin

加密

func (Cryptobin) Decrypt

func (this Cryptobin) Decrypt() Cryptobin

解密

func (Cryptobin) Des

func (this Cryptobin) Des() Cryptobin

Des

func (Cryptobin) ECB

func (this Cryptobin) ECB() Cryptobin

ECB

func (Cryptobin) Encrypt

func (this Cryptobin) Encrypt() Cryptobin

加密

func (Cryptobin) FromBase64String

func (this Cryptobin) FromBase64String(data string) Cryptobin

Base64

func (Cryptobin) FromBytes

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

字节

func (Cryptobin) FromHexString

func (this Cryptobin) FromHexString(data string) Cryptobin

Hex

func (Cryptobin) FromString

func (this Cryptobin) FromString(data string) Cryptobin

字符

func (Cryptobin) FuncDecrypt added in v1.0.1006

func (this Cryptobin) FuncDecrypt(f func(Cryptobin) Cryptobin) Cryptobin

方法解密

func (Cryptobin) FuncEncrypt added in v1.0.1006

func (this Cryptobin) FuncEncrypt(f func(Cryptobin) Cryptobin) Cryptobin

方法加密

func (Cryptobin) GCM

func (this Cryptobin) GCM(nonce string, additional ...string) Cryptobin

GCM

func (Cryptobin) GetConfig

func (this Cryptobin) GetConfig() map[string]any

获取全部配置

func (Cryptobin) GetData

func (this Cryptobin) GetData() []byte

数据

func (Cryptobin) GetError

func (this Cryptobin) GetError() error

错误信息

func (Cryptobin) GetIv

func (this Cryptobin) GetIv() []byte

向量

func (Cryptobin) GetKey

func (this Cryptobin) GetKey() []byte

密码

func (Cryptobin) GetMode

func (this Cryptobin) GetMode() string

加密方式

func (Cryptobin) GetMultiple added in v1.0.1006

func (this Cryptobin) GetMultiple() string

加密类型

func (Cryptobin) GetOneConfig added in v1.0.3

func (this Cryptobin) GetOneConfig(key string) any

获取一个配置

func (Cryptobin) GetPadding

func (this Cryptobin) GetPadding() string

补码算法

func (Cryptobin) GetParsedData

func (this Cryptobin) GetParsedData() []byte

解析后的数据

func (Cryptobin) GuessDecrypt added in v1.0.3

func (this Cryptobin) GuessDecrypt() Cryptobin

解密

func (Cryptobin) GuessEncrypt added in v1.0.3

func (this Cryptobin) GuessEncrypt() Cryptobin

加密

func (Cryptobin) ISO10126Padding added in v1.0.3

func (this Cryptobin) ISO10126Padding() Cryptobin

ISO10126 补码

func (Cryptobin) ISO7816_4Padding added in v1.0.3

func (this Cryptobin) ISO7816_4Padding() Cryptobin

ISO7816_4 补码

func (Cryptobin) NoPadding

func (this Cryptobin) NoPadding() Cryptobin

不补码

func (Cryptobin) NoParse added in v1.0.3

func (this Cryptobin) NoParse() Cryptobin

不做处理

func (Cryptobin) OFB

func (this Cryptobin) OFB() Cryptobin

OFB

func (Cryptobin) OnError added in v1.0.1008

func (this Cryptobin) OnError(fn ErrorFunc) Cryptobin

引出错误信息

func (Cryptobin) PKCS1Padding added in v1.0.3

func (this Cryptobin) PKCS1Padding(bt ...string) Cryptobin

PKCS1 补码

func (Cryptobin) PKCS5Padding

func (this Cryptobin) PKCS5Padding() Cryptobin

PKCS5 补码

func (Cryptobin) PKCS7Padding

func (this Cryptobin) PKCS7Padding() Cryptobin

PKCS7 补码

func (Cryptobin) Padding

func (this Cryptobin) Padding(plainText []byte, blockSize int) []byte

Padding 补码模式

func (Cryptobin) RC4 added in v1.0.2

func (this Cryptobin) RC4() Cryptobin

RC4

func (Cryptobin) RsaDecrypt

func (this Cryptobin) RsaDecrypt(password ...string) Cryptobin

RSA 私钥解密 pkcs8 带密码不支持其他工具生成的密钥

func (Cryptobin) RsaEncrypt

func (this Cryptobin) RsaEncrypt() Cryptobin

RSA 公钥加密

func (Cryptobin) RsaOAEPDecrypt added in v1.0.1006

func (this Cryptobin) RsaOAEPDecrypt(typ string, password ...string) Cryptobin

RSA OAEP 私钥解密 pkcs8 带密码不支持其他工具生成的密钥 typ 为 hash.defaultHashes 对应数据

func (Cryptobin) RsaOAEPEncrypt added in v1.0.1006

func (this Cryptobin) RsaOAEPEncrypt(typ string) Cryptobin

RSA OAEP 公钥加密 typ 为 hash.defaultHashes 对应数据

func (Cryptobin) RsaPrikeyEncrypt

func (this Cryptobin) RsaPrikeyEncrypt(password ...string) Cryptobin

RSA 私钥加密 pkcs8 带密码不支持其他工具生成的密钥

func (Cryptobin) RsaPubkeyDecrypt

func (this Cryptobin) RsaPubkeyDecrypt() Cryptobin

RSA 公钥解密

func (Cryptobin) SM2Decrypt added in v1.0.3

func (this Cryptobin) SM2Decrypt(password ...string) Cryptobin

SM2 私钥解密

func (Cryptobin) SM2Encrypt added in v1.0.3

func (this Cryptobin) SM2Encrypt() Cryptobin

SM2 公钥加密

func (Cryptobin) SM4 added in v1.0.3

func (this Cryptobin) SM4() Cryptobin

SM4

func (Cryptobin) SetIv

func (this Cryptobin) SetIv(data string) Cryptobin

向量

func (Cryptobin) SetKey

func (this Cryptobin) SetKey(data string) Cryptobin

密码

func (Cryptobin) String

func (this Cryptobin) String() string

输出原始字符

func (Cryptobin) TBCPadding added in v1.0.3

func (this Cryptobin) TBCPadding() Cryptobin

TBC 补码

func (Cryptobin) Tea added in v1.0.2

func (this Cryptobin) Tea(rounds ...int) Cryptobin

Tea

func (Cryptobin) ToBase64String

func (this Cryptobin) ToBase64String() string

输出Base64

func (Cryptobin) ToBytes

func (this Cryptobin) ToBytes() []byte

输出字节

func (Cryptobin) ToHexString

func (this Cryptobin) ToHexString() string

输出Hex

func (Cryptobin) ToString

func (this Cryptobin) ToString() string

输出字符

func (Cryptobin) TriDes

func (this Cryptobin) TriDes() Cryptobin

TriDes

func (Cryptobin) Twofish added in v1.0.2

func (this Cryptobin) Twofish() Cryptobin

Twofish

func (Cryptobin) UnPadding

func (this Cryptobin) UnPadding(cipherText []byte) []byte

UnPadding 补码模式

func (Cryptobin) WithConfig

func (this Cryptobin) WithConfig(config map[string]any) Cryptobin

配置

func (Cryptobin) WithData

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

设置数据

func (Cryptobin) WithError added in v1.0.3

func (this Cryptobin) WithError(err error) Cryptobin

设置错误

func (Cryptobin) WithIv

func (this Cryptobin) WithIv(iv []byte) Cryptobin

设置向量

func (Cryptobin) WithKey

func (this Cryptobin) WithKey(key []byte) Cryptobin

设置密钥

func (Cryptobin) WithMode

func (this Cryptobin) WithMode(mode string) Cryptobin

加密方式

func (Cryptobin) WithMultiple added in v1.0.1006

func (this Cryptobin) WithMultiple(multiple string) Cryptobin

加密类型

func (Cryptobin) WithOneConfig added in v1.0.3

func (this Cryptobin) WithOneConfig(key string, value any) Cryptobin

设置一个配置

func (Cryptobin) WithPadding

func (this Cryptobin) WithPadding(padding string) Cryptobin

补码算法

func (Cryptobin) WithParsedData added in v1.0.1011

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

补码算法

func (Cryptobin) X923Padding added in v1.0.3

func (this Cryptobin) X923Padding() Cryptobin

X923 补码

func (Cryptobin) Xtea added in v1.0.2

func (this Cryptobin) Xtea() Cryptobin

Xtea

func (Cryptobin) Xts added in v1.0.1012

func (this Cryptobin) Xts(cipher string, sectorNum uint64) Cryptobin

Xts cipher 可用 [ Aes | Des | TriDes | Tea | Xtea | Twofish | Blowfish | Cast5 | SM4]

func (Cryptobin) ZeroPadding

func (this Cryptobin) ZeroPadding() Cryptobin

Zero 补码

type DSA added in v1.0.1011

type DSA struct {

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

*

  • DSA *
  • @create 2022-7-25
  • @author deatil

func DSAFromBase64String added in v1.0.1011

func DSAFromBase64String(data string) DSA

Base64

func DSAFromBytes added in v1.0.1011

func DSAFromBytes(data []byte) DSA

字节

func DSAFromHexString added in v1.0.1011

func DSAFromHexString(data string) DSA

Hex

func DSAFromPKCS8PrivateKey added in v1.0.1013

func DSAFromPKCS8PrivateKey(key []byte) DSA

PKCS8 私钥

func DSAFromPKCS8PrivateKeyWithPassword added in v1.0.1013

func DSAFromPKCS8PrivateKeyWithPassword(key []byte, password string) DSA

PKCS8 私钥带密码

func DSAFromPKCS8PublicKey added in v1.0.1013

func DSAFromPKCS8PublicKey(key []byte) DSA

PKCS8 公钥

func DSAFromPrivateKey added in v1.0.1011

func DSAFromPrivateKey(key []byte) DSA

私钥

func DSAFromPrivateKeyWithPassword added in v1.0.1012

func DSAFromPrivateKeyWithPassword(key []byte, password string) DSA

私钥带密码

func DSAFromPublicKey added in v1.0.1011

func DSAFromPublicKey(key []byte) DSA

公钥

func DSAFromString added in v1.0.1011

func DSAFromString(data string) DSA

字符

func DSAGenerateKey added in v1.0.1011

func DSAGenerateKey(ln string) DSA

生成密钥 可用参数 [L1024N160 | L2048N224 | L2048N256 | L3072N256]

func NewDSA added in v1.0.1011

func NewDSA() DSA

构造函数

func (DSA) CreatePKCS8PrivateKey added in v1.0.1013

func (this DSA) CreatePKCS8PrivateKey() DSA

私钥

func (DSA) CreatePKCS8PrivateKeyWithPassword added in v1.0.1013

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

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

func (DSA) CreatePKCS8PublicKey added in v1.0.1013

func (this DSA) CreatePKCS8PublicKey() DSA

公钥

func (DSA) CreatePrivateKey added in v1.0.1011

func (this DSA) CreatePrivateKey() DSA

私钥

func (DSA) CreatePrivateKeyWithPassword added in v1.0.1012

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

私钥带密码 CreatePrivateKeyWithPassword("123", "AES256CBC")

func (DSA) CreatePublicKey added in v1.0.1011

func (this DSA) CreatePublicKey() DSA

公钥

func (DSA) DataHash added in v1.0.1011

func (this DSA) DataHash(signHash string, data []byte) []byte

签名后数据

func (DSA) FromBase64String added in v1.0.1011

func (this DSA) FromBase64String(data string) DSA

Base64

func (DSA) FromBytes added in v1.0.1011

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

字节

func (DSA) FromHexString added in v1.0.1011

func (this DSA) FromHexString(data string) DSA

Hex

func (DSA) FromPKCS8PrivateKey added in v1.0.1013

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

PKCS8 私钥

func (DSA) FromPKCS8PrivateKeyWithPassword added in v1.0.1013

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

PKCS8 私钥带密码

func (DSA) FromPKCS8PublicKey added in v1.0.1013

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

PKCS8 公钥

func (DSA) FromPrivateKey added in v1.0.1011

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

私钥

func (DSA) FromPrivateKeyWithPassword added in v1.0.1012

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

私钥带密码

func (DSA) FromPublicKey added in v1.0.1011

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

公钥

func (DSA) FromString added in v1.0.1011

func (this DSA) FromString(data string) DSA

字符

func (DSA) GenerateKey added in v1.0.1011

func (this DSA) GenerateKey(ln string) DSA

生成密钥 可用参数 [L1024N160 | L2048N224 | L2048N256 | L3072N256]

func (DSA) GetData added in v1.0.1011

func (this DSA) GetData() []byte

获取 data

func (DSA) GetError added in v1.0.1011

func (this DSA) GetError() error

获取错误

func (DSA) GetKeyData added in v1.0.1011

func (this DSA) GetKeyData() []byte

获取 keyData

func (DSA) GetParedData added in v1.0.1011

func (this DSA) GetParedData() []byte

获取 paredData

func (DSA) GetPrivateKey added in v1.0.1011

func (this DSA) GetPrivateKey() *dsa.PrivateKey

获取 PrivateKey

func (DSA) GetPublicKey added in v1.0.1011

func (this DSA) GetPublicKey() *dsa.PublicKey

获取 PublicKey

func (DSA) GetSignHash added in v1.0.1011

func (this DSA) GetSignHash() string

获取 hash 类型

func (DSA) GetVeryed added in v1.0.1011

func (this DSA) GetVeryed() bool

获取验证后情况

func (DSA) MakePublicKey added in v1.0.1011

func (this DSA) MakePublicKey() DSA

生成公钥

func (DSA) OnError added in v1.0.1011

func (this DSA) OnError(fn DSAErrorFunc) DSA

引出错误信息

func (DSA) ParsePKCS8PrivateKeyFromPEM added in v1.0.1013

func (this DSA) ParsePKCS8PrivateKeyFromPEM(key []byte) (*dsa.PrivateKey, error)

解析私钥 PKCS8

func (DSA) ParsePKCS8PrivateKeyFromPEMWithPassword added in v1.0.1013

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

解析 PKCS8 带密码的私钥

func (DSA) ParsePKCS8PublicKeyFromPEM added in v1.0.1013

func (this DSA) ParsePKCS8PublicKeyFromPEM(key []byte) (*dsa.PublicKey, error)

解析公钥 PKCS8

func (DSA) ParsePrivateKeyFromPEM added in v1.0.1011

func (this DSA) ParsePrivateKeyFromPEM(key []byte) (*dsa.PrivateKey, error)

解析私钥

func (DSA) ParsePrivateKeyFromPEMWithPassword added in v1.0.1012

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

解析私钥带密码

func (DSA) ParsePublicKeyFromPEM added in v1.0.1011

func (this DSA) ParsePublicKeyFromPEM(key []byte) (*dsa.PublicKey, error)

解析公钥

func (DSA) Sign added in v1.0.1011

func (this DSA) Sign(separator ...string) DSA

私钥签名

func (DSA) SignAsn1 added in v1.0.1011

func (this DSA) SignAsn1() DSA

私钥签名

func (DSA) SignBytes added in v1.0.1012

func (this DSA) SignBytes() DSA

私钥签名

func (DSA) SignHex added in v1.0.1011

func (this DSA) SignHex() DSA

私钥签名

func (DSA) ToBase64String added in v1.0.1011

func (this DSA) ToBase64String() string

输出Base64

func (DSA) ToBytes added in v1.0.1011

func (this DSA) ToBytes() []byte

输出字节

func (DSA) ToHexString added in v1.0.1011

func (this DSA) ToHexString() string

输出Hex

func (DSA) ToKeyBytes added in v1.0.1011

func (this DSA) ToKeyBytes() []byte

私钥/公钥

func (DSA) ToKeyString added in v1.0.1011

func (this DSA) ToKeyString() string

私钥/公钥

func (DSA) ToString added in v1.0.1011

func (this DSA) ToString() string

输出字符

func (DSA) ToVeryed added in v1.0.1011

func (this DSA) ToVeryed() bool

验证结果

func (DSA) VerifyAsn1 added in v1.0.1011

func (this DSA) VerifyAsn1(data []byte) DSA

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

func (DSA) VerifyBytes added in v1.0.1012

func (this DSA) VerifyBytes(data []byte) DSA

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

func (DSA) VerifyHex added in v1.0.1011

func (this DSA) VerifyHex(data []byte) DSA

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

func (DSA) Very added in v1.0.1011

func (this DSA) Very(data []byte, separator ...string) DSA

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

func (DSA) WithData added in v1.0.1011

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

设置 data

func (DSA) WithError added in v1.0.1011

func (this DSA) WithError(err error) DSA

设置错误

func (DSA) WithParedData added in v1.0.1011

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

设置 paredData

func (DSA) WithPrivateKey added in v1.0.1011

func (this DSA) WithPrivateKey(data *dsa.PrivateKey) DSA

设置 PrivateKey

func (DSA) WithPublicKey added in v1.0.1011

func (this DSA) WithPublicKey(data *dsa.PublicKey) DSA

设置 PublicKey

func (DSA) WithSignHash added in v1.0.1011

func (this DSA) WithSignHash(data string) DSA

设置 hash 类型 可用参数可查看 Hash 结构体数据

func (DSA) WithVeryed added in v1.0.1011

func (this DSA) WithVeryed(data bool) DSA

设置 veryed

type DSAErrorFunc added in v1.0.1011

type DSAErrorFunc = func(error)

错误方法

type DSASignature added in v1.0.1011

type DSASignature struct {
	R, S *big.Int
}

type DsaPkcs1Key added in v1.0.1015

type DsaPkcs1Key struct{}

dsa pkcs1 密钥

func NewDsaPkcs1Key added in v1.0.1015

func NewDsaPkcs1Key() DsaPkcs1Key

构造函数

func (DsaPkcs1Key) MarshalPrivateKey added in v1.0.1015

func (this DsaPkcs1Key) MarshalPrivateKey(key *dsa.PrivateKey) ([]byte, error)

包装私钥

func (DsaPkcs1Key) MarshalPublicKey added in v1.0.1015

func (this DsaPkcs1Key) MarshalPublicKey(key *dsa.PublicKey) ([]byte, error)

包装公钥

func (DsaPkcs1Key) ParsePrivateKey added in v1.0.1015

func (this DsaPkcs1Key) ParsePrivateKey(derBytes []byte) (*dsa.PrivateKey, error)

解析私钥

func (DsaPkcs1Key) ParsePublicKey added in v1.0.1015

func (this DsaPkcs1Key) ParsePublicKey(derBytes []byte) (*dsa.PublicKey, error)

解析公钥

type DsaPkcs8Key added in v1.0.1015

type DsaPkcs8Key struct{}

dsa pkcs8 密钥

func NewDsaPkcs8Key added in v1.0.1015

func NewDsaPkcs8Key() DsaPkcs8Key

构造函数

func (DsaPkcs8Key) MarshalPKCS8PrivateKey added in v1.0.1015

func (this DsaPkcs8Key) MarshalPKCS8PrivateKey(key *dsa.PrivateKey) ([]byte, error)

PKCS8 包装私钥

func (DsaPkcs8Key) MarshalPKCS8PublicKey added in v1.0.1015

func (this DsaPkcs8Key) MarshalPKCS8PublicKey(pub *dsa.PublicKey) ([]byte, error)

PKCS8 包装公钥

func (DsaPkcs8Key) ParsePKCS8PrivateKey added in v1.0.1015

func (this DsaPkcs8Key) ParsePKCS8PrivateKey(derBytes []byte) (key *dsa.PrivateKey, err error)

PKCS8 解析私钥

func (DsaPkcs8Key) ParsePKCS8PublicKey added in v1.0.1015

func (this DsaPkcs8Key) ParsePKCS8PublicKey(derBytes []byte) (*dsa.PublicKey, error)

PKCS8 解析公钥

type Ecdsa

type Ecdsa struct {

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

*

  • Ecdsa *
  • @create 2022-4-3
  • @author deatil

func EcdsaFromBase64String

func EcdsaFromBase64String(data string) Ecdsa

Base64

func EcdsaFromBytes

func EcdsaFromBytes(data []byte) Ecdsa

字节

func EcdsaFromHexString

func EcdsaFromHexString(data string) Ecdsa

Hex

func EcdsaFromPKCS8PrivateKey added in v1.0.1012

func EcdsaFromPKCS8PrivateKey(key []byte) Ecdsa

PKCS8 私钥

func EcdsaFromPKCS8PrivateKeyWithPassword added in v1.0.1012

func EcdsaFromPKCS8PrivateKeyWithPassword(key []byte, password string) Ecdsa

PKCS8 私钥带密码

func EcdsaFromPrivateKey

func EcdsaFromPrivateKey(key []byte) Ecdsa

私钥

func EcdsaFromPrivateKeyWithPassword added in v1.0.1012

func EcdsaFromPrivateKeyWithPassword(key []byte, password string) Ecdsa

私钥

func EcdsaFromPublicKey

func EcdsaFromPublicKey(key []byte) Ecdsa

公钥

func EcdsaFromString

func EcdsaFromString(data string) Ecdsa

字符

func EcdsaFromYoumarkPKCS8PrivateKeyWithPassword added in v1.0.1012

func EcdsaFromYoumarkPKCS8PrivateKeyWithPassword(key []byte, password string) Ecdsa

设置私钥带密码

func EcdsaGenerateKey

func EcdsaGenerateKey(hash string) Ecdsa

生成密钥 可选 [P521 | P384 | P256 | P224]

func NewEcdsa

func NewEcdsa() Ecdsa

构造函数

func (Ecdsa) CreatePKCS8PrivateKey added in v1.0.1012

func (this Ecdsa) CreatePKCS8PrivateKey() Ecdsa

PKCS8 私钥

func (Ecdsa) CreatePKCS8PrivateKeyWithPassword added in v1.0.1012

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

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

func (Ecdsa) CreatePrivateKey

func (this Ecdsa) CreatePrivateKey() Ecdsa

私钥

func (Ecdsa) CreatePrivateKeyWithPassword added in v1.0.1012

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

私钥带密码 CreatePrivateKeyWithPassword("123", "AES256CBC")

func (Ecdsa) CreatePublicKey

func (this Ecdsa) CreatePublicKey() Ecdsa

公钥

func (Ecdsa) CreateYoumarkPKCS8PrivateKeyWithPassword added in v1.0.1012

func (this Ecdsa) CreateYoumarkPKCS8PrivateKeyWithPassword(password string, opt ...YoumarkPKCS8Opts) Ecdsa

创建私钥带密码

func (Ecdsa) DataHash

func (this Ecdsa) DataHash(signHash string, data []byte) []byte

签名后数据

func (Ecdsa) FromBase64String

func (this Ecdsa) FromBase64String(data string) Ecdsa

Base64

func (Ecdsa) FromBytes

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

字节

func (Ecdsa) FromHexString

func (this Ecdsa) FromHexString(data string) Ecdsa

Hex

func (Ecdsa) FromPKCS8PrivateKey added in v1.0.1012

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

PKCS8 私钥

func (Ecdsa) FromPKCS8PrivateKeyWithPassword added in v1.0.1012

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

Pkcs8WithPassword

func (Ecdsa) FromPrivateKey

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

私钥

func (Ecdsa) FromPrivateKeyBytes added in v1.0.1005

func (this Ecdsa) FromPrivateKeyBytes(priByte []byte) Ecdsa

明文私钥生成私钥结构体

func (Ecdsa) FromPrivateKeyDBytes added in v1.0.1006

func (this Ecdsa) FromPrivateKeyDBytes(DBytes []byte) Ecdsa

私钥字符,必须先添加公钥

func (Ecdsa) FromPrivateKeyString added in v1.0.1005

func (this Ecdsa) FromPrivateKeyString(keyString string) Ecdsa

私钥字符,必须先添加公钥 (hexStringD)

func (Ecdsa) FromPrivateKeyWithPassword added in v1.0.1012

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

私钥带密码

func (Ecdsa) FromPublicKey

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

公钥

func (Ecdsa) FromPublicKeyString added in v1.0.1005

func (this Ecdsa) FromPublicKeyString(keyString string) Ecdsa

公钥字符 (hexStringX + hexStringY)

func (Ecdsa) FromPublicKeyXYBytes added in v1.0.1005

func (this Ecdsa) FromPublicKeyXYBytes(XBytes, YBytes []byte) Ecdsa

公钥字符对

func (Ecdsa) FromString

func (this Ecdsa) FromString(data string) Ecdsa

字符

func (Ecdsa) FromYoumarkPKCS8PrivateKeyWithPassword added in v1.0.1012

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

设置私钥带密码

func (Ecdsa) GenerateKey

func (this Ecdsa) GenerateKey() Ecdsa

生成密钥

func (Ecdsa) GetData

func (this Ecdsa) GetData() []byte

获取 data

func (Ecdsa) GetError

func (this Ecdsa) GetError() error

获取错误

func (Ecdsa) GetKeyData

func (this Ecdsa) GetKeyData() []byte

获取 keyData

func (Ecdsa) GetParedData

func (this Ecdsa) GetParedData() []byte

获取 paredData

func (Ecdsa) GetPrivateKey

func (this Ecdsa) GetPrivateKey() *ecdsa.PrivateKey

获取 PrivateKey

func (Ecdsa) GetPrivateKeyCurve added in v1.0.1005

func (this Ecdsa) GetPrivateKeyCurve() elliptic.Curve

获取 PrivateKeyCurve

func (Ecdsa) GetPrivateKeyD added in v1.0.1005

func (this Ecdsa) GetPrivateKeyD() *big.Int

获取 PrivateKeyD privateKeyDHex := NewEncoding().HexEncode(GetPrivateKeyD().Bytes())

func (Ecdsa) GetPrivateKeyX added in v1.0.1005

func (this Ecdsa) GetPrivateKeyX() *big.Int

获取 PrivateKeyX privateKeyXHex := NewEncoding().HexEncode(GetPrivateKeyX().Bytes())

func (Ecdsa) GetPrivateKeyY added in v1.0.1005

func (this Ecdsa) GetPrivateKeyY() *big.Int

获取 PrivateKeyY privateKeyYHex := NewEncoding().HexEncode(GetPrivateKeyY().Bytes())

func (Ecdsa) GetPublicKey

func (this Ecdsa) GetPublicKey() *ecdsa.PublicKey

获取 PublicKey

func (Ecdsa) GetPublicKeyCurve added in v1.0.1005

func (this Ecdsa) GetPublicKeyCurve() elliptic.Curve

获取 PublicKeyCurve

func (Ecdsa) GetPublicKeyX added in v1.0.1005

func (this Ecdsa) GetPublicKeyX() *big.Int

获取 PublicKeyX publicKeyXHex := NewEncoding().HexEncode(GetPublicKeyX().Bytes())

func (Ecdsa) GetPublicKeyY added in v1.0.1005

func (this Ecdsa) GetPublicKeyY() *big.Int

获取 PublicKeyY publicKeyYHex := NewEncoding().HexEncode(GetPublicKeyY().Bytes())

func (Ecdsa) GetSignHash

func (this Ecdsa) GetSignHash() string

获取 hash 类型

func (Ecdsa) GetVeryed

func (this Ecdsa) GetVeryed() bool

获取验证后情况

func (Ecdsa) MakePublicKey added in v1.0.1010

func (this Ecdsa) MakePublicKey() Ecdsa

生成公钥

func (Ecdsa) OnError added in v1.0.1008

func (this Ecdsa) OnError(fn EcdsaErrorFunc) Ecdsa

引出错误信息

func (Ecdsa) ParseECPKCS8PrivateKeyFromPEMWithPassword added in v1.0.1012

func (this Ecdsa) ParseECPKCS8PrivateKeyFromPEMWithPassword(key []byte, password string) (*ecdsa.PrivateKey, error)

解析 PKCS8 带密码的私钥

func (Ecdsa) ParseECPrivateKeyFromPEM

func (this Ecdsa) ParseECPrivateKeyFromPEM(key []byte) (*ecdsa.PrivateKey, error)

解析私钥

func (Ecdsa) ParseECPrivateKeyFromPEMWithPassword added in v1.0.1012

func (this Ecdsa) ParseECPrivateKeyFromPEMWithPassword(key []byte, password string) (*ecdsa.PrivateKey, error)

解析私钥带密码

func (Ecdsa) ParseECPublicKeyFromPEM

func (this Ecdsa) ParseECPublicKeyFromPEM(key []byte) (*ecdsa.PublicKey, error)

解析公钥

func (Ecdsa) Sign

func (this Ecdsa) Sign(separator ...string) Ecdsa

私钥签名

func (Ecdsa) SignAsn1 added in v1.0.1007

func (this Ecdsa) SignAsn1() Ecdsa

私钥签名

func (Ecdsa) SignHex added in v1.0.1007

func (this Ecdsa) SignHex() Ecdsa

私钥签名

func (Ecdsa) ToBase64String

func (this Ecdsa) ToBase64String() string

输出Base64

func (Ecdsa) ToBytes

func (this Ecdsa) ToBytes() []byte

输出字节

func (Ecdsa) ToHexString

func (this Ecdsa) ToHexString() string

输出Hex

func (Ecdsa) ToKeyBytes

func (this Ecdsa) ToKeyBytes() []byte

私钥/公钥

func (Ecdsa) ToKeyString

func (this Ecdsa) ToKeyString() string

私钥/公钥

func (Ecdsa) ToString

func (this Ecdsa) ToString() string

输出字符

func (Ecdsa) ToVeryed

func (this Ecdsa) ToVeryed() bool

验证结果

func (Ecdsa) VerifyAsn1 added in v1.0.1007

func (this Ecdsa) VerifyAsn1(data []byte) Ecdsa

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

func (Ecdsa) VerifyHex added in v1.0.1007

func (this Ecdsa) VerifyHex(data []byte) Ecdsa

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

func (Ecdsa) Very

func (this Ecdsa) Very(data []byte, separator ...string) Ecdsa

公钥验证

func (Ecdsa) WithCurve

func (this Ecdsa) WithCurve(curve string) Ecdsa

设置 data 可选 [P521 | P384 | P256 | P224]

func (Ecdsa) WithData

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

设置 data

func (Ecdsa) WithError

func (this Ecdsa) WithError(err error) Ecdsa

设置错误

func (Ecdsa) WithParedData

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

设置 paredData

func (Ecdsa) WithPrivateKey

func (this Ecdsa) WithPrivateKey(data *ecdsa.PrivateKey) Ecdsa

设置 PrivateKey

func (Ecdsa) WithPublicKey

func (this Ecdsa) WithPublicKey(data *ecdsa.PublicKey) Ecdsa

设置 PublicKey

func (Ecdsa) WithSignHash

func (this Ecdsa) WithSignHash(hash string) Ecdsa

设置 hash 类型

func (Ecdsa) WithVeryed added in v1.0.1011

func (this Ecdsa) WithVeryed(data bool) Ecdsa

设置 veryed

type EcdsaErrorFunc added in v1.0.1008

type EcdsaErrorFunc = func(error)

错误方法

type EdDSA added in v1.0.2

type EdDSA struct {

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

*

  • EdDSA *
  • @create 2022-4-3
  • @author deatil

func EdDSAFromBase64String added in v1.0.2

func EdDSAFromBase64String(data string) EdDSA

Base64

func EdDSAFromBytes added in v1.0.2

func EdDSAFromBytes(data []byte) EdDSA

字节

func EdDSAFromHexString added in v1.0.2

func EdDSAFromHexString(data string) EdDSA

Hex

func EdDSAFromPrivateKey added in v1.0.2

func EdDSAFromPrivateKey(key []byte) EdDSA

私钥

func EdDSAFromPrivateKeyWithPassword added in v1.0.1012

func EdDSAFromPrivateKeyWithPassword(key []byte, password string) EdDSA

私钥

func EdDSAFromPublicKey added in v1.0.2

func EdDSAFromPublicKey(key []byte) EdDSA

公钥

func EdDSAFromString added in v1.0.2

func EdDSAFromString(data string) EdDSA

字符

func EdDSAFromYoumarkPKCS8PrivateKeyWithPassword added in v1.0.1013

func EdDSAFromYoumarkPKCS8PrivateKeyWithPassword(key []byte, password string) EdDSA

设置私钥带密码

func EdDSAGenerateKey added in v1.0.2

func EdDSAGenerateKey() EdDSA

生成密钥

func NewEdDSA added in v1.0.2

func NewEdDSA() EdDSA

构造函数

func (EdDSA) CreatePrivateKey added in v1.0.2

func (this EdDSA) CreatePrivateKey() EdDSA

私钥

func (EdDSA) CreatePrivateKeyWithPassword added in v1.0.1012

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

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

func (EdDSA) CreatePublicKey added in v1.0.2

func (this EdDSA) CreatePublicKey() EdDSA

公钥

func (EdDSA) CreateYoumarkPKCS8PrivateKeyWithPassword added in v1.0.1013

func (this EdDSA) CreateYoumarkPKCS8PrivateKeyWithPassword(password string, opt ...YoumarkPKCS8Opts) EdDSA

创建私钥带密码

func (EdDSA) FromBase64String added in v1.0.2

func (this EdDSA) FromBase64String(data string) EdDSA

Base64

func (EdDSA) FromBytes added in v1.0.2

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

字节

func (EdDSA) FromHexString added in v1.0.2

func (this EdDSA) FromHexString(data string) EdDSA

Hex

func (EdDSA) FromPrivateKey added in v1.0.2

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

私钥

func (EdDSA) FromPrivateKeyWithPassword added in v1.0.1012

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

私钥带密码

func (EdDSA) FromPublicKey added in v1.0.2

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

公钥

func (EdDSA) FromString added in v1.0.2

func (this EdDSA) FromString(data string) EdDSA

字符

func (EdDSA) FromYoumarkPKCS8PrivateKeyWithPassword added in v1.0.1013

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

设置私钥带密码

func (EdDSA) GenerateKey added in v1.0.2

func (this EdDSA) GenerateKey() EdDSA

生成密钥

func (EdDSA) GetData added in v1.0.2

func (this EdDSA) GetData() []byte

获取 data

func (EdDSA) GetError added in v1.0.2

func (this EdDSA) GetError() error

获取错误

func (EdDSA) GetKeyData added in v1.0.2

func (this EdDSA) GetKeyData() []byte

获取 keyData

func (EdDSA) GetParedData added in v1.0.2

func (this EdDSA) GetParedData() []byte

获取 paredData

func (EdDSA) GetPrivateKey added in v1.0.2

func (this EdDSA) GetPrivateKey() ed25519.PrivateKey

获取 PrivateKey

func (EdDSA) GetPublicKey added in v1.0.2

func (this EdDSA) GetPublicKey() ed25519.PublicKey

获取 PublicKey

func (EdDSA) GetVeryed added in v1.0.2

func (this EdDSA) GetVeryed() bool

获取验证后情况

func (EdDSA) MakePublicKey added in v1.0.1010

func (this EdDSA) MakePublicKey() EdDSA

生成公钥

func (EdDSA) OnError added in v1.0.1008

func (this EdDSA) OnError(fn EdDSAErrorFunc) EdDSA

引出错误信息

func (EdDSA) ParseEdPrivateKeyFromPEM added in v1.0.2

func (this EdDSA) ParseEdPrivateKeyFromPEM(key []byte) (crypto.PrivateKey, error)

解析私钥

func (EdDSA) ParseEdPrivateKeyFromPEMWithPassword added in v1.0.1012

func (this EdDSA) ParseEdPrivateKeyFromPEMWithPassword(key []byte, password string) (crypto.PrivateKey, error)

解析私钥带密码

func (EdDSA) ParseEdPublicKeyFromPEM added in v1.0.2

func (this EdDSA) ParseEdPublicKeyFromPEM(key []byte) (crypto.PublicKey, error)

解析公钥

func (EdDSA) Sign added in v1.0.2

func (this EdDSA) Sign() EdDSA

私钥签名

func (EdDSA) ToBase64String added in v1.0.2

func (this EdDSA) ToBase64String() string

输出Base64

func (EdDSA) ToBytes added in v1.0.2

func (this EdDSA) ToBytes() []byte

输出字节

func (EdDSA) ToHexString added in v1.0.2

func (this EdDSA) ToHexString() string

输出Hex

func (EdDSA) ToKeyBytes added in v1.0.2

func (this EdDSA) ToKeyBytes() []byte

私钥/公钥

func (EdDSA) ToKeyString added in v1.0.2

func (this EdDSA) ToKeyString() string

私钥/公钥

func (EdDSA) ToString added in v1.0.2

func (this EdDSA) ToString() string

输出字符

func (EdDSA) ToVeryed added in v1.0.2

func (this EdDSA) ToVeryed() bool

验证结果

func (EdDSA) Very added in v1.0.2

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

公钥验证

func (EdDSA) WithData added in v1.0.2

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

设置 data

func (EdDSA) WithError added in v1.0.2

func (this EdDSA) WithError(err error) EdDSA

设置错误

func (EdDSA) WithParedData added in v1.0.2

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

设置 paredData

func (EdDSA) WithPrivateKey added in v1.0.2

func (this EdDSA) WithPrivateKey(data ed25519.PrivateKey) EdDSA

设置 PrivateKey

func (EdDSA) WithPublicKey added in v1.0.2

func (this EdDSA) WithPublicKey(data ed25519.PublicKey) EdDSA

设置 PublicKey

func (EdDSA) WithVeryed added in v1.0.1011

func (this EdDSA) WithVeryed(data bool) EdDSA

设置 veryed

type EdDSAErrorFunc added in v1.0.1008

type EdDSAErrorFunc = func(error)

错误方法

type Encoding added in v1.0.1005

type Encoding struct{}

*

  • 编码 *
  • @create 2022-4-17
  • @author deatil

func NewEncoding added in v1.0.1005

func NewEncoding() Encoding

构造函数

func (Encoding) Base64Decode added in v1.0.1005

func (this Encoding) Base64Decode(s string) ([]byte, error)

Base64 解码

func (Encoding) Base64Encode added in v1.0.1005

func (this Encoding) Base64Encode(src []byte) string

Base64 编码

func (Encoding) HexDecode added in v1.0.1005

func (this Encoding) HexDecode(s string) ([]byte, error)

Hex 解码

func (Encoding) HexEncode added in v1.0.1005

func (this Encoding) HexEncode(src []byte) string

Hex 编码

func (Encoding) HexPadding added in v1.0.1007

func (this Encoding) HexPadding(text string, size int) string

补码

type ErrorFunc added in v1.0.1008

type ErrorFunc = func(error)

错误方法

type Hash added in v1.0.1006

type Hash struct {
	// contains filtered or unexported fields
}

*

  • 摘要 *
  • @create 2022-4-16
  • @author deatil

func NewHash added in v1.0.1006

func NewHash() Hash

构造函数

func (Hash) AddCryptoHash added in v1.0.1006

func (this Hash) AddCryptoHash(name string, sha crypto.Hash) Hash

添加

func (Hash) AddHash added in v1.0.1006

func (this Hash) AddHash(name string, sha hashFunc) Hash

添加

func (Hash) DataCryptoHash added in v1.0.1006

func (this Hash) DataCryptoHash(typ string, slices ...[]byte) []byte

签名后数据

func (Hash) DataHash added in v1.0.1006

func (this Hash) DataHash(typ string, slices ...[]byte) []byte

签名后数据

func (Hash) GetCryptoHash added in v1.0.1006

func (this Hash) GetCryptoHash(typ string) crypto.Hash

类型

func (Hash) GetHash added in v1.0.1006

func (this Hash) GetHash(typ string) hashFunc

类型

func (Hash) WithCryptoHashs added in v1.0.1006

func (this Hash) WithCryptoHashs(hashes CryptoHashMap) Hash

覆盖 cryptoHashes

func (Hash) WithHashs added in v1.0.1006

func (this Hash) WithHashs(hashes HashMap) Hash

覆盖 hashes

type HashMap added in v1.0.1006

type HashMap = map[string]hashFunc

hash

type Opts

type Opts struct {
	SaltSize       int
	IterationCount int
	HMACHash       string
}

配置

type Padding added in v1.0.3

type Padding struct{}

*

  • 补码 *
  • @create 2022-4-17
  • @author deatil

func NewPadding added in v1.0.3

func NewPadding() Padding

构造函数

func (Padding) ISO10126Padding added in v1.0.3

func (this Padding) ISO10126Padding(text []byte, blockSize int) []byte

ISO10126Padding 填充至符合块大小的整数倍,填充值最后一个字节为填充的数量数,其他字节填充随机字节。

func (Padding) ISO10126UnPadding added in v1.0.3

func (this Padding) ISO10126UnPadding(src []byte) []byte

func (Padding) ISO7816_4Padding added in v1.0.3

func (this Padding) ISO7816_4Padding(text []byte, blockSize int) []byte

ISO7816_4Padding 填充至符合块大小的整数倍,填充值第一个字节为0x80,其他字节填0x00。

func (Padding) ISO7816_4UnPadding added in v1.0.3

func (this Padding) ISO7816_4UnPadding(src []byte) []byte

func (Padding) PKCS1Padding added in v1.0.3

func (this Padding) PKCS1Padding(text []byte, blockSize int, bt string) []byte

填充格式如下: Padding = 00 + BT + PS + 00 + D 00为固定字节 BT为处理模式 PS为填充字节,填充数量为k - 3 - D,k表示密钥长度, D表示原文长度。 PS的最小长度为8个字节。填充的值根据BT值来定: BT = 00时,填充全00 BT = 01时,填充全FF BT = 02时,随机填充,但不能为00。

func (Padding) PKCS1UnPadding added in v1.0.3

func (this Padding) PKCS1UnPadding(src []byte) []byte

func (Padding) PKCS5Padding added in v1.0.3

func (this Padding) PKCS5Padding(text []byte) []byte

PKCS7Padding的子集,块大小固定为8字节

func (Padding) PKCS5UnPadding added in v1.0.3

func (this Padding) PKCS5UnPadding(src []byte) []byte

func (Padding) PKCS7Padding added in v1.0.3

func (this Padding) PKCS7Padding(text []byte, blockSize int) []byte

明文补码算法 填充至符合块大小的整数倍,填充值为填充数量数

func (Padding) PKCS7UnPadding added in v1.0.3

func (this Padding) PKCS7UnPadding(src []byte) []byte

明文减码算法

func (Padding) RandomBytes added in v1.0.3

func (this Padding) RandomBytes(length uint) []byte

随机字节

func (Padding) TBCPadding added in v1.0.3

func (this Padding) TBCPadding(text []byte, blockSize int) []byte

TBCPadding(Trailling-Bit-Compliment) 填充至符合块大小的整数倍,原文最后一位为1时填充0x00,最后一位为0时填充0xFF。

func (Padding) TBCUnPadding added in v1.0.3

func (this Padding) TBCUnPadding(src []byte) []byte

func (Padding) X923Padding added in v1.0.3

func (this Padding) X923Padding(text []byte, blockSize int) []byte

X923Padding 填充至符合块大小的整数倍,填充值最后一个字节为填充的数量数,其他字节填0

func (Padding) X923UnPadding added in v1.0.3

func (this Padding) X923UnPadding(src []byte) []byte

func (Padding) ZeroPadding added in v1.0.3

func (this Padding) ZeroPadding(text []byte, blockSize int) []byte

数据长度不对齐时使用0填充,否则不填充

func (Padding) ZeroUnPadding added in v1.0.3

func (this Padding) ZeroUnPadding(src []byte) []byte

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

func RsaFromPKCS12Cert(key []byte) Rsa

Pkcs12 Cert

func RsaFromPKCS12CertWithPassword added in v1.0.1012

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

Pkcs12CertWithPassword

func RsaFromPKCS1PrivateKey added in v1.0.1012

func RsaFromPKCS1PrivateKey(key []byte) Rsa

Pkcs1

func RsaFromPKCS1PrivateKeyWithPassword added in v1.0.1012

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

Pkcs1WithPassword

func RsaFromPKCS8PrivateKey added in v1.0.1012

func RsaFromPKCS8PrivateKey(key []byte) Rsa

Pkcs8

func RsaFromPKCS8PrivateKeyWithPassword added in v1.0.1012

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

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

设置私钥带密码

func RsaGenerateKey

func RsaGenerateKey(bits int) Rsa

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

func (Rsa) CreatePKCS1PrivateKey added in v1.0.1012

func (this Rsa) CreatePKCS1PrivateKey() Rsa

PKCS1 私钥

func (Rsa) CreatePKCS1PrivateKeyWithPassword added in v1.0.1012

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

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

func (Rsa) CreatePKCS8PrivateKey added in v1.0.1012

func (this Rsa) CreatePKCS8PrivateKey() Rsa

PKCS8 私钥

func (Rsa) CreatePKCS8PrivateKeyWithPassword added in v1.0.1012

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

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

func (Rsa) CreatePrivateKey added in v1.0.1012

func (this Rsa) CreatePrivateKey() Rsa

私钥, PKCS1 别名

func (Rsa) CreatePrivateKeyWithPassword added in v1.0.1012

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

私钥带密码, PKCS1 别名

func (Rsa) CreatePublicKey

func (this Rsa) CreatePublicKey() Rsa

公钥

func (Rsa) CreateYoumarkPKCS8PrivateKeyWithPassword added in v1.0.1012

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

创建私钥带密码

func (Rsa) Decrypt

func (this Rsa) Decrypt() Rsa

私钥解密

func (Rsa) DecryptOAEP added in v1.0.1006

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

OAEP私钥解密

func (Rsa) Encrypt

func (this Rsa) Encrypt() Rsa

公钥加密

func (Rsa) EncryptOAEP added in v1.0.1006

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

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

Pkcs12 Cert

func (Rsa) FromPKCS12CertWithPassword added in v1.0.1012

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

Pkcs12CertWithPassword

func (Rsa) FromPKCS1PrivateKey added in v1.0.1012

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

Pkcs1

func (Rsa) FromPKCS1PrivateKeyWithPassword added in v1.0.1012

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

Pkcs1WithPassword

func (Rsa) FromPKCS8PrivateKey added in v1.0.1012

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

Pkcs8

func (Rsa) FromPKCS8PrivateKeyWithPassword added in v1.0.1012

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

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

func (this Rsa) MakePublicKey() Rsa

生成公钥

func (Rsa) OnError added in v1.0.1008

func (this Rsa) OnError(fn RsaErrorFunc) Rsa

引出错误信息

func (Rsa) PSSSign added in v1.0.2

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

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

func (Rsa) PSSVery added in v1.0.2

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

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

func (Rsa) ParseRSAPKCS12CertFromPEMWithPassword added in v1.0.1012

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

func (this Rsa) WithVeryed(data bool) Rsa

设置 veryed

type RsaErrorFunc added in v1.0.1008

type RsaErrorFunc = func(error)

错误方法

type SM2 added in v1.0.3

type SM2 struct {

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

*

  • 国密 SM2 加密 *
  • @create 2022-4-16
  • @author deatil

func NewSM2 added in v1.0.3

func NewSM2() SM2

构造函数

func SM2FromBase64String added in v1.0.3

func SM2FromBase64String(data string) SM2

Base64

func SM2FromBytes added in v1.0.3

func SM2FromBytes(data []byte) SM2

字节

func SM2FromHexString added in v1.0.3

func SM2FromHexString(data string) SM2

Hex

func SM2FromPrivateKey added in v1.0.3

func SM2FromPrivateKey(key []byte) SM2

私钥

func SM2FromPrivateKeyWithPassword added in v1.0.3

func SM2FromPrivateKeyWithPassword(key []byte, password string) SM2

私钥带密码

func SM2FromPublicKey added in v1.0.3

func SM2FromPublicKey(key []byte) SM2

公钥

func SM2FromString added in v1.0.3

func SM2FromString(data string) SM2

字符

func SM2GenerateKey added in v1.0.3

func SM2GenerateKey() SM2

生成密钥

func (SM2) CreatePrivateKey added in v1.0.3

func (this SM2) CreatePrivateKey() SM2

国密私钥

func (SM2) CreatePrivateKeyWithPassword added in v1.0.3

func (this SM2) CreatePrivateKeyWithPassword(password string) SM2

国密私钥带密码

func (SM2) CreatePublicKey added in v1.0.3

func (this SM2) CreatePublicKey() SM2

国密公钥

func (SM2) Decrypt added in v1.0.3

func (this SM2) Decrypt() SM2

私钥解密

func (SM2) Encrypt added in v1.0.3

func (this SM2) Encrypt() SM2

公钥加密

func (SM2) FromBase64String added in v1.0.3

func (this SM2) FromBase64String(data string) SM2

Base64

func (SM2) FromBytes added in v1.0.3

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

字节

func (SM2) FromHexString added in v1.0.3

func (this SM2) FromHexString(data string) SM2

Hex

func (SM2) FromPrivateKey added in v1.0.3

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

私钥

func (SM2) FromPrivateKeyBytes added in v1.0.1005

func (this SM2) FromPrivateKeyBytes(priByte []byte) SM2

明文私钥生成私钥结构体

func (SM2) FromPrivateKeyDBytes added in v1.0.1006

func (this SM2) FromPrivateKeyDBytes(DBytes []byte) SM2

私钥字符,必须先添加公钥

func (SM2) FromPrivateKeyString added in v1.0.1005

func (this SM2) FromPrivateKeyString(keyString string) SM2

私钥字符,必须先添加公钥 (hexStringD) private-key: 07e4********;

func (SM2) FromPrivateKeyWithPassword added in v1.0.3

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

私钥带密码

func (SM2) FromPublicKey added in v1.0.3

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

公钥

func (SM2) FromPublicKeyString added in v1.0.1005

func (this SM2) FromPublicKeyString(keyString string) SM2

公钥字符 (hexStringX + hexStringY) public-key: 047c********.

func (SM2) FromPublicKeyXYBytes added in v1.0.1005

func (this SM2) FromPublicKeyXYBytes(XBytes, YBytes []byte) SM2

公钥字符对

func (SM2) FromString added in v1.0.3

func (this SM2) FromString(data string) SM2

字符

func (SM2) GenerateKey added in v1.0.3

func (this SM2) GenerateKey() SM2

生成密钥

func (SM2) GetData added in v1.0.3

func (this SM2) GetData() []byte

获取 data

func (SM2) GetError added in v1.0.3

func (this SM2) GetError() error

获取错误

func (SM2) GetKeyData added in v1.0.3

func (this SM2) GetKeyData() []byte

获取 keyData

func (SM2) GetParedData added in v1.0.3

func (this SM2) GetParedData() []byte

获取 paredData

func (SM2) GetPrivateKey added in v1.0.3

func (this SM2) GetPrivateKey() *sm2.PrivateKey

获取 PrivateKey

func (SM2) GetPrivateKeyCurve added in v1.0.1005

func (this SM2) GetPrivateKeyCurve() elliptic.Curve

获取 PrivateKeyCurve

func (SM2) GetPrivateKeyD added in v1.0.1005

func (this SM2) GetPrivateKeyD() *big.Int

获取 PrivateKeyD privateKeyDHex := NewEncoding().HexEncode(GetPrivateKeyD().Bytes())

func (SM2) GetPrivateKeyX added in v1.0.1005

func (this SM2) GetPrivateKeyX() *big.Int

获取 PrivateKeyX privateKeyXHex := NewEncoding().HexEncode(GetPrivateKeyX().Bytes())

func (SM2) GetPrivateKeyY added in v1.0.1005

func (this SM2) GetPrivateKeyY() *big.Int

获取 PrivateKeyY privateKeyYHex := NewEncoding().HexEncode(GetPrivateKeyY().Bytes())

func (SM2) GetPublicKey added in v1.0.3

func (this SM2) GetPublicKey() *sm2.PublicKey

获取 PublicKey

func (SM2) GetPublicKeyCurve added in v1.0.1005

func (this SM2) GetPublicKeyCurve() elliptic.Curve

获取 PublicKeyCurve

func (SM2) GetPublicKeyX added in v1.0.1005

func (this SM2) GetPublicKeyX() *big.Int

获取 PublicKeyX publicKeyXHex := NewEncoding().HexEncode(GetPublicKeyX().Bytes())

func (SM2) GetPublicKeyY added in v1.0.1005

func (this SM2) GetPublicKeyY() *big.Int

获取 PublicKeyY publicKeyYHex := NewEncoding().HexEncode(GetPublicKeyY().Bytes())

func (SM2) GetVeryed added in v1.0.3

func (this SM2) GetVeryed() bool

获取验证后情况

func (SM2) MakePublicKey added in v1.0.1010

func (this SM2) MakePublicKey() SM2

生成公钥

func (SM2) OnError added in v1.0.1008

func (this SM2) OnError(fn SM2ErrorFunc) SM2

引出错误信息

func (SM2) ParsePrivateKeyFromPEM added in v1.0.3

func (this SM2) ParsePrivateKeyFromPEM(key []byte) (*sm2.PrivateKey, error)

解析 SM2 PKCS8 私钥

func (SM2) ParsePrivateKeyFromPEMWithPassword added in v1.0.3

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

解析 SM2 PKCS8 私钥带密码

func (SM2) ParsePublicKeyFromPEM added in v1.0.3

func (this SM2) ParsePublicKeyFromPEM(key []byte) (*sm2.PublicKey, error)

解析 SM2 PKCS8 公钥

func (SM2) Sign added in v1.0.3

func (this SM2) Sign() SM2

私钥签名

func (SM2) SignAsn1 added in v1.0.1007

func (this SM2) SignAsn1(uid []byte) SM2

私钥签名

func (SM2) SignHex added in v1.0.1007

func (this SM2) SignHex(uid []byte) SM2

私钥签名 兼容[招行]

func (SM2) ToBase64String added in v1.0.3

func (this SM2) ToBase64String() string

输出Base64

func (SM2) ToBytes added in v1.0.3

func (this SM2) ToBytes() []byte

输出字节

func (SM2) ToHexString added in v1.0.3

func (this SM2) ToHexString() string

输出Hex

func (SM2) ToKeyBytes added in v1.0.3

func (this SM2) ToKeyBytes() []byte

私钥/公钥

func (SM2) ToKeyString added in v1.0.3

func (this SM2) ToKeyString() string

私钥/公钥

func (SM2) ToString added in v1.0.3

func (this SM2) ToString() string

输出字符

func (SM2) ToVeryed added in v1.0.3

func (this SM2) ToVeryed() bool

验证结果

func (SM2) VerifyAsn1 added in v1.0.1007

func (this SM2) VerifyAsn1(data []byte, uid []byte) SM2

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

func (SM2) VerifyHex added in v1.0.1007

func (this SM2) VerifyHex(data []byte, uid []byte) SM2

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

func (SM2) Very added in v1.0.3

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

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

func (SM2) WithData added in v1.0.3

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

设置 data

func (SM2) WithError added in v1.0.3

func (this SM2) WithError(err error) SM2

设置错误

func (SM2) WithParedData added in v1.0.3

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

设置 paredData

func (SM2) WithPrivateKey added in v1.0.3

func (this SM2) WithPrivateKey(data *sm2.PrivateKey) SM2

设置 PrivateKey

func (SM2) WithPublicKey added in v1.0.3

func (this SM2) WithPublicKey(data *sm2.PublicKey) SM2

设置 PublicKey

func (SM2) WithVeryed added in v1.0.1011

func (this SM2) WithVeryed(data bool) SM2

设置 veryed

type SM2ErrorFunc added in v1.0.1008

type SM2ErrorFunc = func(error)

错误方法

type YoumarkPKCS8Opts added in v1.0.1012

type YoumarkPKCS8Opts = youmarkPKCS8.Opts

设置选项

Jump to

Keyboard shortcuts

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