crypto

package
v0.0.0-...-8b94866 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: Unlicense Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotPublicKey    = errors.New("key is not a valid ECDSA public key")
	ErrNotECPrivateKey = errors.New("key is not a valid ECDSA private key")
)
View Source
var (
	ErrInvalidKey      = errors.New("key is invalid")
	ErrInvalidKeyType  = errors.New("key is of invalid type")
	ErrHashUnavailable = errors.New("the requested hash function is unavailable")
)
View Source
var (
	ErrKeyMustBePEMEncoded = errors.New("invalid key: must be a PEM encode 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 (
	// Sadly this is missing from crypto/ecdsa compared to crypto/rsa
	ErrECDSAVerification = errors.New("crypto/ecdsa: verification error")
)

Functions

func ParseECPrivateKeyFromPEM

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

ParseECPrivateKeyFromPEM parse PEM encoded Elliptic Curve Key Structure

func ParseECPublicKeyFromPEM

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

func ParseRSAPrivateKeyFromPEM

func ParseRSAPrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error)

ParseRSAPrivateKeyFromPEM parse PEM encoded PKCS1 or PKCS8 private key

func ParseRSAPrivateKeyFromPEMWithPassword

func ParseRSAPrivateKeyFromPEMWithPassword(key []byte, password string) (*rsa.PrivateKey, error)

ParseRSAPrivateKeyFromPEMWithPassword Parse PEM encoded PKCS1 or PKCS8 private key protected with password

func ParseRSAPublicKeyFromPEM

func ParseRSAPublicKeyFromPEM(key []byte) (*rsa.PublicKey, error)

ParseRSAPublicKeyFromPEM Parse PEM encoded PKCS1 or PKCS8 public key

func RegisterSigningMethod

func RegisterSigningMethod(alg string, f func() SigningMethod)

Types

type Certificate

type Certificate struct {
	*x509.Certificate
	// contains filtered or unexported fields
}

func ParseCertificate

func ParseCertificate(certificate string) (*Certificate, error)

ParseCertificate parse raw data into x509.Certificate format

func (*Certificate) Algorithm

func (c *Certificate) Algorithm() x509.PublicKeyAlgorithm

func (*Certificate) PEM

func (c *Certificate) PEM() []byte

type SigningMethod

type SigningMethod interface {
	Verify(signingString, signature string, key any) error
	Sign(signingString string, key any) (string, error)
	Alg() string
}

Implement SigningMethod to add new methods for signing or verifying signed string

func GetSigningMethod

func GetSigningMethod(alg string) (method SigningMethod)

type SigningMethodECDSA

type SigningMethodECDSA struct {
	Name      string
	Hash      crypto.Hash
	KeySize   int
	CurveBits int
}

Implement the ECDSA family of signing methods SigningMethod Expects *ecdsa.PrivateKey for signing and *ecdsa.PublicKey for verification

var (
	SigningMethodES256 *SigningMethodECDSA
	SigningMethodES384 *SigningMethodECDSA
	SigningmethodES512 *SigningMethodECDSA
)

Specific instances for ES256 and company

func (*SigningMethodECDSA) Alg

func (m *SigningMethodECDSA) Alg() string

func (*SigningMethodECDSA) Sign

func (m *SigningMethodECDSA) Sign(text string, key any) (string, error)

Sign Implements the verify method from SigningMethod For this Sign method, key must be an *ecdsa.PrivateKey

func (*SigningMethodECDSA) Verify

func (m *SigningMethodECDSA) Verify(signingString string, signature string, key any) error

Verify Implements the sign method from SigningMethod For this Verify method, key must be an *ecdsa.PublicKey struct

type SigningMethodRSA

type SigningMethodRSA struct {
	Name string
	Hash crypto.Hash
}
var (
	SigningMethodRS256 *SigningMethodRSA
	SigningMethodRS384 *SigningMethodRSA
	SigningMethodRS512 *SigningMethodRSA
)

Specific instances for RSA256 and company

func (*SigningMethodRSA) Alg

func (m *SigningMethodRSA) Alg() string

func (*SigningMethodRSA) Sign

func (m *SigningMethodRSA) Sign(text string, key any) (string, error)

Sign Implements the sign method from SigningMethod For this signing method, must be an *rsa.PrivateKey structure

func (*SigningMethodRSA) Verify

func (m *SigningMethodRSA) Verify(signingString, signature string, key any) error

Verify Implement the Verify method from SigningMethod For this signing method, must be *rsa.PublicKey structure

type SigningMethodRSAPSS

type SigningMethodRSAPSS struct {
	*SigningMethodRSA

	Options *rsa.PSSOptions
	// VerifyOptions is optional, If set overrides Options for rsa.VerifyPPS.
	// Used to accept tokens signed with rsa.PSSSaltLengthAuto, what doesn't follow
	// https://tools.ietf.org/html/rfc7518#section-3.5 but was used previously.
	// See https://github.com/dgrijalva/jwt-go/issues/285#issuecomment-437451244 for details.
	VerifyOptions *rsa.PSSOptions
}
var (
	SigningMethodPS256 *SigningMethodRSAPSS
	SigningMethodPS384 *SigningMethodRSAPSS
	SigningMethodPS512 *SigningMethodRSAPSS
)

Specific instances for RS/PS and company.

func (*SigningMethodRSAPSS) Alg

func (m *SigningMethodRSAPSS) Alg() string

func (*SigningMethodRSAPSS) Sign

func (m *SigningMethodRSAPSS) Sign(text string, key any) (string, error)

Implements the Sign method from SigningMethod For this signing method, key must be an rsa.PrivateKey struct

func (*SigningMethodRSAPSS) Verify

func (m *SigningMethodRSAPSS) Verify(signingString string, signature string, key any) error

Implements the Verify method from SigningMethod For this verify method, key must be an rsa.PublicKey struct

Jump to

Keyboard shortcuts

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