crypto

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2021 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(data *EncryptedData, key []byte) ([]byte, error)

func DeriveKey

func DeriveKey(publicKey *ecdsa.PublicKey, privateKey *ecdsa.PrivateKey) []byte

Derives a key from a public and private ECDSA key pair. The derived key is compatible to the one generated by the subtle crypto API

func GenerateKey

func GenerateKey() (*ecdsa.PrivateKey, error)

func Hash

func Hash(data []byte) []byte

func LoadPrivateKey

func LoadPrivateKey(privateKey []byte) (*ecdsa.PrivateKey, error)

func LoadPublicKey

func LoadPublicKey(publicKey []byte) (*ecdsa.PublicKey, error)

func RandomBytes

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

func Verify

func Verify(message []byte, signatureBytes []byte, publicKey *ecdsa.PublicKey) (bool, error)

func VerifyWithBytes

func VerifyWithBytes(message, signature, publicKeyData []byte) (bool, error)

Types

type Actor

type Actor struct {
	Name          string
	SigningKey    *Key
	EncryptionKey *Key
}

func MakeActor

func MakeActor(name string) (*Actor, error)

type ECDHEncryptedData

type ECDHEncryptedData struct {
	IV        []byte `json:"iv"`
	Data      []byte `json:"data"`
	PublicKey []byte `json:"publicKey"`
}

type ECDSASignature

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

func Sign

func Sign(message []byte, privateKey *ecdsa.PrivateKey) (*ECDSASignature, error)

func (*ECDSASignature) Serialize

func (e *ECDSASignature) Serialize() []byte

type EncryptedData

type EncryptedData struct {
	IV   []byte `json:"iv"`
	Data []byte `json:"data"`
}

func Encrypt

func Encrypt(data, key []byte) (*EncryptedData, error)

type JWKPrivateKey

type JWKPrivateKey struct {
	Curve       string   `json:"crv"`
	D           string   `json:"d"`
	Extractable bool     `json:"ext"`
	KeyOps      []string `json:"key_ops"`
	KeyType     string   `json:"kty"`
	X           string   `json:"x"`
	Y           string   `json:"y"`
}

type Key

type Key struct {
	Name      string                 `json:"name"`
	Type      string                 `json:"type"`
	Format    string                 `json:"format"`
	Params    map[string]interface{} `json:"params"`
	PublicKey []byte                 `json:"public_key"`
	Purposes  []string               `json:"purposes"`
	// only defined for local signing operations
	PrivateKey []byte `json:"private_key,omitempty"`
}

func AsSettingsKey

func AsSettingsKey(key *ecdsa.PrivateKey, name, keyType string) (*Key, error)

func GenerateWebKey

func GenerateWebKey(name, keyType string) (*Key, error)

func (*Key) Encrypt

func (k *Key) Encrypt(data []byte, recipient *Key) (*ECDHEncryptedData, error)

func (*Key) Sign

func (k *Key) Sign(data []byte) (*SignedData, error)

func (*Key) SignString

func (k *Key) SignString(data string) (*SignedStringData, error)

func (*Key) Verify

func (k *Key) Verify(data *SignedData) (bool, error)

func (*Key) VerifyString

func (k *Key) VerifyString(data *SignedStringData) (bool, error)

type KeyPair

type KeyPair struct {
	PrivateKeyBytes []byte            `json:"privateKeyBytes"`
	PublicKeyBytes  []byte            `json:"publicKeyBytes"`
	PrivateKey      *ecdsa.PrivateKey `json:"-"`
	PublicKey       *ecdsa.PublicKey  `json:"-"`
}

func KeyPairFromStrings

func KeyPairFromStrings(keyPair *StringKeyPair) (*KeyPair, error)

type SignedData

type SignedData struct {
	Data      []byte `json:"data"`
	Signature []byte `json:"signature"`
	PublicKey []byte `json:"publicKey"`
}

func (*SignedData) AsMap

func (s *SignedData) AsMap() map[string]interface{}

func (*SignedData) Verify

func (s *SignedData) Verify(publicKey *ecdsa.PublicKey) (bool, error)

type SignedStringData

type SignedStringData struct {
	Data      string `json:"data"`
	Signature []byte `json:"signature"`
	PublicKey []byte `json:"publicKey"`
}

func (*SignedStringData) AsMap

func (s *SignedStringData) AsMap() map[string]interface{}

type StringKeyPair

type StringKeyPair struct {
	PublicKey  string `json:"publicKey"`
	PrivateKey string `json:"privateKey"`
}

type WebKey

type WebKey struct {
	// PKIX ASN.1 DER format
	PublicKey string `json:"publicKey"`
	// JWK format (as Firefox can't parse PKCS8...)
	PrivateKey *JWKPrivateKey `json:"privateKey"`
}

func AsWebKey

func AsWebKey(key *ecdsa.PrivateKey, keyType string) (*WebKey, error)

Jump to

Keyboard shortcuts

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