crypto

package
v0.0.0-...-46a6a0a Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2017 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SaveKey

func SaveKey(key PrivateKey, path string) error

SaveKey will attempt to save the specified private key to the specified file. If path is not specified, then it will use the default .dslink.key. This function will return an error on failure.

Types

type ECDH

type ECDH interface {
	// GenerateKey will create a new Private/Public key pair based on random numbers from io.Reader.
	// Returns error if it was unable to create keys.
	GenerateKey(io.Reader) (PrivateKey, error)
	// Marshal converts a Private/Public key pair into a Base64.RawUrlEncoded string.
	// Returned string separates the pairs with a space, where private key is first.
	// Returns an error if unable to convert values to a string.
	Marshal(PrivateKey) (string, error)
	// Unmarshal will decode a Base64.RawUrlEncoded string into a Private/Public key pair.
	// String may be Private / Public keys separated by a space or alternatively a private
	// key and the public will be generated automatically.
	// Returns an error if string cannot be decoded.
	Unmarshal(string) (PrivateKey, error)
	// UnmarshalPublic will decode a Base64.RawUrlEncoded string into a Public key.
	// Returns an error if string cannot be decoded.
	UnmarshalPublic(string) (PublicKey, error)
	// GenerateSharedSecret Creates a shared secret based on the private of one and
	// public key of the other. Returns a byte slice.
	GenerateSharedSecret(PrivateKey, PublicKey) []byte
	// HashSalt adds the provided string salt to the SharedSecret byte slice sec.
	// It returns a Base64 RawUrl encoded string of the SHA256 Sum of bytes.
	HashSalt(string, []byte) string
	// HashToken generates the token hash for the connection handshake.
	// Returns a base64 encoded SHA256 checksum of the DSId and Token.
	HashToken(dsId string, token string) string
}

ECDH manages creating and providing keys.

func NewECDH

func NewECDH() ECDH

NewECDH returns a new Elliptic ECDH

type PrivateKey

type PrivateKey struct {
	PublicKey
	D []byte
}

func LoadKey

func LoadKey(path string) (PrivateKey, error)

LoadKey will try to load the public and private key configuration from disk. If no filename is specified, it will default to .dslink.key. This function returns a PrivateKey or error.

type PublicKey

type PublicKey struct {
	Curve elliptic.Curve
	X, Y  *big.Int
}

func (PublicKey) Base64

func (p PublicKey) Base64() string

Base64 returns a Base64 Raw Url Encoded (no padding) string of the bytes for the public key.

func (PublicKey) DsId

func (p PublicKey) DsId(prefix string) string

DsId generates the dsId for this Public Key based on the prefix supplied. DsId returned should be the prefix

func (PublicKey) Hash64

func (p PublicKey) Hash64() string

Hash64 returns the SHA256 check sum of the bytes for the public key encoded as Base64 Raw Url encoded (no padding) string.

func (PublicKey) VerifyDsId

func (p PublicKey) VerifyDsId(dsid string) bool

VerifyDsId confirms that the provided dsid matches the expected Hash64 for this public key.

Jump to

Keyboard shortcuts

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