crypto

package
v10.298.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2021 License: Apache-2.0 Imports: 19 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeHmac256

func ComputeHmac256(tags []byte, key []byte) ([]byte, error)

ComputeHmac256 computes the HMAC256 of the message

func CreateEphemeralKey

func CreateEphemeralKey(curve func() elliptic.Curve, pub *ecdsa.PublicKey) (*ecdsa.PrivateKey, []byte)

CreateEphemeralKey creates an ephmeral private/public key based on the provided public key and the corresponding elliptic curve

func DecodePublicKeyV1

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

DecodePublicKeyV1 decodes the provided public key

func DecodePublicKeyV2

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

DecodePublicKeyV2 decodes the provided public key

func EncodePrivateKey

func EncodePrivateKey(privateKey *ecdsa.PrivateKey) []byte

EncodePrivateKey encodes the private key to a byte slice.

func EncodePublicKeyV1

func EncodePublicKeyV1(publicKey *ecdsa.PublicKey) []byte

EncodePublicKeyV1 encodes the public key to a byte slice

func EncodePublicKeyV2

func EncodePublicKeyV2(publicKey *ecdsa.PublicKey) []byte

EncodePublicKeyV2 encodes the public key to a byte slice

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateRandomString

func GenerateRandomString(s int) (string, error)

GenerateRandomString returns a URL-safe, base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func LoadAndVerifyCertificate

func LoadAndVerifyCertificate(certPEM []byte, roots *x509.CertPool) (*x509.Certificate, error)

LoadAndVerifyCertificate parses, validates, and creates a certificate structure from a PEM buffer It must be provided with the a CertPool

func LoadAndVerifyECSecrets

func LoadAndVerifyECSecrets(keyPEM, certPEM, caCertPEM []byte) (key *ecdsa.PrivateKey, cert *x509.Certificate, rootCertPool *x509.CertPool, err error)

LoadAndVerifyECSecrets loads all the certificates and keys to memory in the right data structures

func LoadCertificate

func LoadCertificate(certPEM []byte) (*x509.Certificate, error)

LoadCertificate loads a certificate from a PEM file without verifying Should only be used for loading a root CA certificate. It will only read the first certificate

func LoadEllipticCurveKey

func LoadEllipticCurveKey(keyPEM []byte) (*ecdsa.PrivateKey, error)

LoadEllipticCurveKey parses and creates an EC key

func LoadRootCertificates

func LoadRootCertificates(rootPEM []byte) *x509.CertPool

LoadRootCertificates loads the certificates in the provide PEM buffer in a CertPool

func VerifyHmac

func VerifyHmac(tags []byte, expectedMAC []byte, key []byte) bool

VerifyHmac verifies if the HMAC of the message matches the one provided

Types

type Nonce16Byte

type Nonce16Byte interface {
	GenerateNonce16Bytes([]byte)
}

Nonce16Byte interface generates 16 byte nonce

func Nonce

func Nonce() Nonce16Byte

Nonce initializes and returns nonce of type Nonce16Byte.

type PublicKey

type PublicKey struct {
	X *big.Int
	Y *big.Int
}

PublicKey is an intermediate structure to create gobs

Jump to

Keyboard shortcuts

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