plugin

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2021 License: Apache-2.0 Imports: 26 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OidPublicKeyRSA = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 1, 1}
	//oidPublicKeyDSA        = asn1.ObjectIdentifier{1, 2, 840, 10040, 4, 1}
	OidPublicKeyECDSAOrSM2 = asn1.ObjectIdentifier{1, 2, 840, 10045, 2, 1}
)
  • RFC 5480, 2.1.1 Unrestricted Algorithm Identifier and Parameters

RFC 3279, 2.3 Public Key Algorithms

pkcs-1 OBJECT IDENTIFIER ::== { iso(1) member-body(2) us(840)

rsadsi(113549) pkcs(1) 1 }

rsaEncryption OBJECT IDENTIFIER ::== { pkcs1-1 1 }

id-dsa OBJECT IDENTIFIER ::== { iso(1) member-body(2) us(840)

x9-57(10040) x9cm(4) 1 }

RFC 5480, 2.1.1 Unrestricted Algorithm Identifier and Parameters RFC 5480, 2.1.1 Unrestricted Algorithm Identifier and Parameters">¶

id-ecPublicKey OBJECT IDENTIFIER ::= {
      iso(1) member-body(2) us(840) ansi-X9-62(10045) keyType(2) 1 }

OID for algo

Functions

func GetCryptoEngine

func GetCryptoEngine() crypto.Engine

GetCryptoEngine get crypto engine

func GetPublicKeyAlgorithmFromMode

func GetPublicKeyAlgorithmFromMode(mode int) (pkix.AlgorithmIdentifier, error)

GetPublicKeyAlgorithmFromMode get public pkix.AlgorithmIdentifier from mode

func GetSoftwareEngine

func GetSoftwareEngine(keyStoreAbsPath string) crypto.Engine

GetSoftwareEngine get software engine

func MarshalECPrivateKey

func MarshalECPrivateKey(key *asym.ECDSAPrivateKey) ([]byte, error)

MarshalECPrivateKey marshals an EC private Key into ASN.1, DER format.

func MarshalPKCS1PrivateKey

func MarshalPKCS1PrivateKey(key *rsa.PrivateKey) []byte

MarshalPKCS1PrivateKey converts a private Key to ASN.1 DER encoded form.

func MarshalPKCS1PublicKey

func MarshalPKCS1PublicKey(key *rsa.PublicKey) []byte

MarshalPKCS1PublicKey converts an RSA public Key to PKCS#1, ASN.1 DER form.

func MarshalPKCS8PrivateKey

func MarshalPKCS8PrivateKey(key *PrivateKey) ([]byte, error)

MarshalPKCS8PrivateKey converts a private Key to PKCS#8 encoded form. The following Key types are supported: *rsa.PrivateKey, *ecdsa.PrivateKey. Unsupported Key types result in an error.

See RFC 5208. support gm

func MarshalPKIXPublicKey

func MarshalPKIXPublicKey(rawpub []byte, mode int) ([]byte, error)

MarshalPKIXPublicKey serialises a public Key to DER-encoded PKIX format.

func MarshalSMPrivateKey

func MarshalSMPrivateKey(x *gm.SM2PrivateKey, withPKCS8 bool) ([]byte, error)

MarshalSMPrivateKey marshal sm2 private key

func ModeFromCurve

func ModeFromCurve(curve elliptic.Curve) int

ModeFromCurve get mode from curve

func ModeFromRSAMod

func ModeFromRSAMod(rsaMod int) (int, error)

ModeFromRSAMod get mode from RSA mode

func ModeGetCurve

func ModeGetCurve(mode int) (elliptic.Curve, error)

ModeGetCurve get curve form mode

func ModeGetRSAMod

func ModeGetRSAMod(mode int) (int, error)

ModeGetRSAMod get RSA mod from mode

func ModeIsECDSAAlgo

func ModeIsECDSAAlgo(mode int) bool

ModeIsECDSAAlgo is it a ECDSA signature algorithm

func ModeIsEncryptAlgo

func ModeIsEncryptAlgo(mode int) bool

ModeIsEncryptAlgo is it a encrypt algorithm

func ModeIsHashAlgo

func ModeIsHashAlgo(mode int) bool

ModeIsHashAlgo is it a hash algorithm

func ModeIsRSAAlgo

func ModeIsRSAAlgo(mode int) bool

ModeIsRSAAlgo is it a RSA signature algorithm

func ModeIsSignatureAlgo

func ModeIsSignatureAlgo(mode int) bool

ModeIsSignatureAlgo is it a signature algorithm

func ParseECPrivateKey

func ParseECPrivateKey(der []byte) (*asym.ECDSAPrivateKey, error)

ParseECPrivateKey parses an ASN.1 Elliptic Curve Private Key Structure.

func ParsePKCS1PrivateKey

func ParsePKCS1PrivateKey(der []byte) (*rsa.PrivateKey, error)

ParsePKCS1PrivateKey returns an RSA private Key from its ASN.1 PKCS#1 DER encoded form.

func ParsePKCS1PublicKey

func ParsePKCS1PublicKey(der []byte) (*rsa.PublicKey, error)

ParsePKCS1PublicKey parses a PKCS#1 public Key in ASN.1 DER form.

func ParsePKCS8PrivateKey

func ParsePKCS8PrivateKey(der []byte) (crypto.PrivateKey, error)

ParsePKCS8PrivateKey parses an unencrypted, PKCS#8 private Key. See RFC 5208.

func ParsePKIXPublicKey

func ParsePKIXPublicKey(derBytes []byte) (rawPub []byte, mode int, err error)

ParsePKIXPublicKey parses a DER encoded public Key. These values are typically found in PEM blocks with "BEGIN PUBLIC KEY".

func ParseSMPrivateKey

func ParseSMPrivateKey(der []byte) (*gm.SM2PrivateKey, error)

ParseSMPrivateKey Parse guomi private Key, support gmssl private Key and cfca private Key return the PrivateKey type. first try to resolve to the private Key of type gmssl. if it fails, try to resolve to the private Key of cfca.

func UseSm2Batch

func UseSm2Batch(reader io.Reader) crypto.FlagReader

UseSm2Batch use Sm2 batch mode

Types

type EncryptEngineMux

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

EncryptEngineMux encryption mux

func (*EncryptEngineMux) CreateDecKey

func (e *EncryptEngineMux) CreateDecKey(persistent bool, mode int) (index []byte, k crypto.DecKey, err error)

CreateDecKey create dec Key

func (*EncryptEngineMux) CreateSignKey

func (e *EncryptEngineMux) CreateSignKey(persistent bool, mode int) (index []byte, k crypto.SignKey, err error)

CreateSignKey sign Key

func (*EncryptEngineMux) GetDecKey

func (e *EncryptEngineMux) GetDecKey(key []byte, mode int) (crypto.DecKey, error)

GetDecKey get dec Key

func (*EncryptEngineMux) GetEncKey

func (e *EncryptEngineMux) GetEncKey(key []byte, mode int) (crypto.EncKey, error)

GetEncKey get enc Key

func (*EncryptEngineMux) GetHash

func (e *EncryptEngineMux) GetHash(mode int) (crypto.Hasher, error)

GetHash get hash function

func (*EncryptEngineMux) GetLevel

func (e *EncryptEngineMux) GetLevel() ([]int, uint8)

GetLevel get level

func (*EncryptEngineMux) GetSecretKey

func (e *EncryptEngineMux) GetSecretKey(mode int, pwd, key []byte) (crypto.SecretKey, error)

GetSecretKey get secret Key

func (*EncryptEngineMux) GetSignKey

func (e *EncryptEngineMux) GetSignKey(key []byte, mode int) (crypto.SignKey, error)

GetSignKey get sign Key

func (*EncryptEngineMux) GetVerifyKey

func (e *EncryptEngineMux) GetVerifyKey(key []byte, mode int) (crypto.VerifyKey, error)

GetVerifyKey get verify Key

func (*EncryptEngineMux) ImportDecKey

func (e *EncryptEngineMux) ImportDecKey(key []byte, mode int) (index []byte, err error)

ImportDecKey import dec Key

func (*EncryptEngineMux) ImportSignKey

func (e *EncryptEngineMux) ImportSignKey(key []byte, mode int) (index []byte, err error)

ImportSignKey import sign Key

func (*EncryptEngineMux) Rander

func (e *EncryptEngineMux) Rander() (io.Reader, error)

Rander random reader

func (*EncryptEngineMux) String

func (e *EncryptEngineMux) String() string

String output

type Function

type Function uint32

Function function

const (
	Random Function = iota
	Hash            //always soft
	Crypt           //always soft
	Verify
	SignImport
	SignGet
	CreateSign
	EncKey       //always soft
	DecKeyImport //always soft
	DecKeyGet
	CreateDecKey //always soft
	FunctionMax
)

Function function

func (Function) String

func (f Function) String() string

type MockSecretKey

type MockSecretKey struct {
}

MockSecretKey use in pure encrypt

func (*MockSecretKey) Decrypt

func (s *MockSecretKey) Decrypt(src []byte) []byte

Decrypt decrypt

func (*MockSecretKey) Destroy

func (s *MockSecretKey) Destroy()

Destroy destroy Key

func (*MockSecretKey) Encrypt

func (s *MockSecretKey) Encrypt(src []byte, reader io.Reader) []byte

Encrypt encrypt

type PrivateKey

type PrivateKey struct {
	PublicKey
	//the first is gm, the second is ecdsa, the third is rsa
	PrivKey crypto.Signer
}

PrivateKey private Key

func (*PrivateKey) Decrypt

func (p *PrivateKey) Decrypt(data []byte) ([]byte, error)

Decrypt decrypt

func (*PrivateKey) Destroy

func (p *PrivateKey) Destroy()

Destroy destroy Key

func (*PrivateKey) Sign

func (p *PrivateKey) Sign(msg []byte, hasher hash.Hash, rand io.Reader) ([]byte, error)

Sign generate signature

type PublicKey

type PublicKey struct {
	Mode int
	//gm, ecdsa or rsa
	Key crypto.Verifier
}

PublicKey public Key

func (*PublicKey) Bytes

func (p *PublicKey) Bytes() (ret []byte)

Bytes return der

func (*PublicKey) Encrypt

func (p *PublicKey) Encrypt(data []byte, reader io.Reader) ([]byte, error)

Encrypt encrypt

func (*PublicKey) GetKeyInfo

func (p *PublicKey) GetKeyInfo() int

GetKeyInfo get Key information

func (*PublicKey) Verify

func (p *PublicKey) Verify(msg []byte, hasher hash.Hash, sig []byte) bool

Verify verify signature

type PublicKeyAlgorithm

type PublicKeyAlgorithm int

PublicKeyAlgorithm public Key algorithm

const (
	UnknownPublicKeyAlgorithm PublicKeyAlgorithm = iota
	RSA
	//DSA
	ECDSA
	SM2
)

signature algorithm

func GetPublicKeyAlgorithmFromAlgorithmIdentifier

func GetPublicKeyAlgorithmFromAlgorithmIdentifier(algo pkix.AlgorithmIdentifier) PublicKeyAlgorithm

GetPublicKeyAlgorithmFromAlgorithmIdentifier get PublicKeyAlgorithm

func (PublicKeyAlgorithm) String

func (algo PublicKeyAlgorithm) String() string

type SecretKey

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

SecretKey secret Key

func (*SecretKey) Decrypt

func (s *SecretKey) Decrypt(src []byte) []byte

Decrypt decrypt

func (*SecretKey) Destroy

func (s *SecretKey) Destroy()

Destroy destroy

func (*SecretKey) Encrypt

func (s *SecretKey) Encrypt(src []byte, reader io.Reader) []byte

Encrypt encrypt

Jump to

Keyboard shortcuts

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