secure

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: MIT Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSupportedKey = errors.New("not an supported key")
View Source
var ErrPubKeyNotFound = errors.New("public key not found")
View Source
var ErrSignNotMatch = errors.New("sign not match")

Functions

func Belongs added in v0.2.0

func Belongs(pub KeyWithFilter, prv []byte, passphrase string) bool

Belongs checks if pub key belongs to prv key.

func DecryptAES

func DecryptAES(key, data []byte) ([]byte, error)

func EncryptAES

func EncryptAES(key, data []byte) ([]byte, error)

func IsAuthErr added in v0.1.0

func IsAuthErr(err error) bool

func PrivateKeyTypePrefix added in v0.2.0

func PrivateKeyTypePrefix(key crypto.PrivateKey) string

func SSHPrvKey added in v0.2.0

func SSHPrvKey(keyData []byte, passphrase string) (crypto.PrivateKey, error)

SSHPrvKey returns a private key from a ssh private key.

func SSHPubKey added in v0.1.0

func SSHPubKey(publicKey []byte) (crypto.PublicKey, error)

func SharedSecret added in v0.2.0

func SharedSecret(prv crypto.PrivateKey, pub crypto.PublicKey) ([]byte, error)

Types

type Cipher added in v0.0.5

type Cipher struct {
	Key *Key
}

func (*Cipher) DecodeAESKey added in v0.2.0

func (c *Cipher) DecodeAESKey(encryptedKeys [][]byte) ([]byte, error)

func (*Cipher) Decoder added in v0.0.5

func (c *Cipher) Decoder(r io.Reader) (io.ReadCloser, error)

func (*Cipher) Encoder added in v0.0.5

func (c *Cipher) Encoder(w io.Writer) (io.WriteCloser, error)

Encoder format is:

[encrypted key count][aes key 1][aes key 2]...[encrypted data].

Each key is for a public key.

type Key

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

func New added in v0.0.5

func New(privateKey []byte, passphrase string, publicKeys ...KeyWithFilter) (*Key, error)

func (*Key) AESKeys added in v0.0.7

func (k *Key) AESKeys() ([]byte, [][]byte, error)

AESKeys returns the AES key and encrypted keys for each public key. If there's only one public key, the AES key will be the ECDH key. If there're multiple public keys, a random base AES key will be generated, then each ECDH key will be used to encrypt the base AES key.

func (*Key) Cipher added in v0.0.5

func (k *Key) Cipher() *Cipher

func (*Key) IsRSA added in v0.2.0

func (k *Key) IsRSA() bool

func (*Key) SigDigest added in v0.2.0

func (k *Key) SigDigest(digest []byte) ([]byte, error)

func (*Key) Sign added in v0.0.5

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

func (*Key) Signer added in v0.0.5

func (k *Key) Signer() *Signer

func (*Key) Verify added in v0.0.5

func (k *Key) Verify(data []byte) ([]byte, bool)

func (*Key) VerifyDigest added in v0.2.0

func (k *Key) VerifyDigest(digest, sign []byte) bool

type KeyWithFilter added in v0.2.0

type KeyWithFilter struct {
	Key    []byte
	Filter string
}

func (KeyWithFilter) GetKey added in v0.2.0

func (key KeyWithFilter) GetKey(typePrefix string) ([]byte, error)

type Signer added in v0.0.5

type Signer struct {
	Key *Key
}

func (*Signer) Decoder added in v0.0.5

func (s *Signer) Decoder(r io.Reader) (io.ReadCloser, error)

func (*Signer) Encoder added in v0.0.5

func (s *Signer) Encoder(w io.Writer) (io.WriteCloser, error)

Jump to

Keyboard shortcuts

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