crypto

package
v1.6.4 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2024 License: Apache-2.0 Imports: 24 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ECIES_AES128_SHA256 = ECIESParams{
		Hash: sha256.New,

		Cipher:    aes.NewCipher,
		BlockSize: aes.BlockSize,
		KeyLen:    16,
		// contains filtered or unexported fields
	}

	ECIES_AES256_SHA256 = ECIESParams{
		Hash: sha256.New,

		Cipher:    aes.NewCipher,
		BlockSize: aes.BlockSize,
		KeyLen:    32,
		// contains filtered or unexported fields
	}

	ECIES_AES256_SHA384 = ECIESParams{
		Hash: sha512.New384,

		Cipher:    aes.NewCipher,
		BlockSize: aes.BlockSize,
		KeyLen:    32,
		// contains filtered or unexported fields
	}

	ECIES_AES256_SHA512 = ECIESParams{
		Hash: sha512.New,

		Cipher:    aes.NewCipher,
		BlockSize: aes.BlockSize,
		KeyLen:    32,
		// contains filtered or unexported fields
	}
)
View Source
var AttributeTypeNames = map[string]string{
	"2.5.4.6":  "C",
	"2.5.4.10": "O",
	"2.5.4.11": "OU",
	"2.5.4.3":  "CN",
	"2.5.4.5":  "SERIALNUMBER",
	"2.5.4.7":  "L",
	"2.5.4.8":  "ST",
	"2.5.4.9":  "STREET",
	"2.5.4.17": "POSTALCODE",
}

Functions

func CheckHMAC

func CheckHMAC(h func() hash.Hash, message, messageMAC, key []byte) bool

func GetDN

func GetDN(name pkix.Name) string

GetDN Get the DN (distinguished name) associated with a pkix.Name. NOTE: This code is almost a direct copy of the String() function in https://go-review.googlesource.com/c/go/+/67270/1/src/crypto/x509/pkix/pkix.go#26 which returns a DN as defined by RFC 2253.

func HashSha256

func HashSha256(data []byte) []byte

func HashSha512

func HashSha512(data []byte) []byte

func NewHMAC

func NewHMAC(h func() hash.Hash, message, key []byte) []byte

func ParseCertPem

func ParseCertPem(pemBytes []byte) (cert *x509.Certificate, err error)

ParseCertPem used in server app

func ParseCertPemOrPanic added in v1.5.3

func ParseCertPemOrPanic(pemBytes []byte) *x509.Certificate

func ToCertPem added in v1.5.7

func ToCertPem(cert *x509.Certificate) []byte

Types

type ECDSASignature

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

func (ECDSASignature) MarshalOrPanic added in v1.5.10

func (t ECDSASignature) MarshalOrPanic() []byte

func (ECDSASignature) UnmarshalOrPanic added in v1.5.10

func (ECDSASignature) UnmarshalOrPanic(signature []byte) (ecdsaSignature ECDSASignature)

type ECIESParams

type ECIESParams struct {
	Hash func() hash.Hash // hash function

	Cipher    func([]byte) (cipher.Block, error) // symmetric cipher
	BlockSize int                                // block size of symmetric cipher
	KeyLen    int                                // length of symmetric key
	// contains filtered or unexported fields
}

ECIESParams ECDH , inspired by go-ethereum

func ParamsFromCurve

func ParamsFromCurve(curve elliptic.Curve) (params ECIESParams)

ParamsFromCurve selects parameters optimal for the selected elliptic curve. Only the curves P256, P384, and P512 are supported.

func (ECIESParams) SymDecrypt

func (params ECIESParams) SymDecrypt(key, cipherText []byte) (m []byte)

SymDecrypt carries out CTR decryption using the block cipher specified in the parameters

func (ECIESParams) SymEncrypt

func (params ECIESParams) SymEncrypt(rand io.Reader, key, m []byte) (cipherText []byte)

SymEncrypt carries out CTR encryption using the block cipher specified in the parameters.

type ECPriv

type ECPriv struct {
	*ecdsa.PrivateKey
}

ECPriv Used for both ECDSA and ECDH

func NewECPriv added in v1.5.10

func NewECPriv(curve elliptic.Curve) ECPriv

NewECPriv generate an EC private key (default to use P256 curve)

func (ECPriv) Decrypt

func (prv ECPriv) Decrypt(c []byte) []byte

Decrypt decrypts an ECIES ciphertext.

func (ECPriv) GenerateShared

func (prv ECPriv) GenerateShared(pub ECPub, skLen, macLen int) (sk []byte)

ECDH key agreement method used to establish secret keys for encryption.

func (ECPriv) LoadPem

func (ECPriv) LoadPem(pemBytes []byte) ECPriv

func (ECPriv) Sign

func (t ECPriv) Sign(digest []byte) []byte

func (ECPriv) ToPem

func (t ECPriv) ToPem() []byte

type ECPub

type ECPub struct {
	*ecdsa.PublicKey
}

ECPub is a representation of an elliptic curve public key.

func (ECPub) Encrypt

func (pub ECPub) Encrypt(rand io.Reader, m []byte) (ct []byte)

func (*ECPub) LoadCert

func (t *ECPub) LoadCert(pemBytes []byte)

func (ECPub) Verify

func (t ECPub) Verify(digest []byte, signature []byte) bool

type PKCS8

type PKCS8 struct {
	pem.Block
	Key interface{}
	reflect.Type
}

PKCS8 default in nodejs sdk

func (PKCS8) FormatECDSA

func (t PKCS8) FormatECDSA() *ecdsa.PrivateKey

func (PKCS8) LoadPem

func (PKCS8) LoadPem(pemBytes []byte) PKCS8

func (PKCS8) ToPem

func (t PKCS8) ToPem() []byte

Jump to

Keyboard shortcuts

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