keys: Index | Examples | Files

package saltpack

import ""



Package Files

boxkey.go encrypt.go errors.go log.go saltpack.go sign.go signcrypt.go signkey.go

func SetLogger Uses

func SetLogger(l Logger)

SetLogger sets logger for the package.

func StripBefore Uses

func StripBefore(message string) string

StripBefore removes text before BEGIN.

type ContextLogger Uses

type ContextLogger interface {
    Debugf(ctx context.Context, format string, args ...interface{})
    Infof(ctx context.Context, format string, args ...interface{})
    Warningf(ctx context.Context, format string, args ...interface{})
    Errorf(ctx context.Context, format string, args ...interface{})

ContextLogger interface used in this package with request context.

func NewContextLogger Uses

func NewContextLogger(lev LogLevel) ContextLogger

NewContextLogger ...

type Keystore Uses

type Keystore interface {
    // X25519Keys return all X25519 box keys in the Keystore to try to decrypt.
    X25519Keys() ([]*keys.X25519Key, error)

Keystore ...

type LogLevel Uses

type LogLevel int

LogLevel ...

const (
    // DebugLevel ...
    DebugLevel LogLevel = 3
    // InfoLevel ...
    InfoLevel LogLevel = 2
    // WarnLevel ...
    WarnLevel LogLevel = 1
    // ErrLevel ...
    ErrLevel LogLevel = 0

type Logger Uses

type Logger interface {
    Debugf(format string, args ...interface{})
    Infof(format string, args ...interface{})
    Warningf(format string, args ...interface{})
    Errorf(format string, args ...interface{})

Logger interface used in this package.

func NewLogger Uses

func NewLogger(lev LogLevel) Logger

NewLogger ...

type Saltpack Uses

type Saltpack struct {
    // contains filtered or unexported fields

Saltpack provider.

func NewSaltpack Uses

func NewSaltpack(keys Keystore) *Saltpack

NewSaltpack creates a Saltpack provider. Uses signcryption, see .

func (*Saltpack) CreateEphemeralKey Uses

func (s *Saltpack) CreateEphemeralKey() (ksaltpack.BoxSecretKey, error)

CreateEphemeralKey creates a random ephemeral key.

func (*Saltpack) Decrypt Uses

func (s *Saltpack) Decrypt(b []byte) ([]byte, *keys.X25519PublicKey, error)

Decrypt bytes. If there was a sender, will return a X25519 key ID.

func (*Saltpack) DecryptArmored Uses

func (s *Saltpack) DecryptArmored(str string) ([]byte, *keys.X25519PublicKey, error)

DecryptArmored text. If there was a sender, will return a X25519 key ID.

func (*Saltpack) Encrypt Uses

func (s *Saltpack) Encrypt(b []byte, sender *keys.X25519Key, recipients ...keys.ID) ([]byte, error)

Encrypt to recipients. Sender can be nil, if you want it to be anonymous.

func (*Saltpack) EncryptArmored Uses

func (s *Saltpack) EncryptArmored(b []byte, sender *keys.X25519Key, recipients ...keys.ID) (string, error)

EncryptArmored to recipients. Sender can be nil, if you want it to be anonymous.

func (*Saltpack) GetAllBoxSecretKeys Uses

func (s *Saltpack) GetAllBoxSecretKeys() []ksaltpack.BoxSecretKey

GetAllBoxSecretKeys returns all keys, needed if we want to support "hidden" receivers via trial and error.

func (*Saltpack) ImportBoxEphemeralKey Uses

func (s *Saltpack) ImportBoxEphemeralKey(kid []byte) ksaltpack.BoxPublicKey

ImportBoxEphemeralKey imports the ephemeral key into BoxPublicKey format. This key has never been seen before, so will be ephemeral.

func (*Saltpack) LookupBoxPublicKey Uses

func (s *Saltpack) LookupBoxPublicKey(kid []byte) ksaltpack.BoxPublicKey

LookupBoxPublicKey returns a public key given the specified key ID. For most cases, the key ID will be the key itself.

func (*Saltpack) LookupBoxSecretKey Uses

func (s *Saltpack) LookupBoxSecretKey(kids [][]byte) (int, ksaltpack.BoxSecretKey)

LookupBoxSecretKey looks in the Keyring for the secret key corresponding to one of the given Key IDs. Returns the index and the key on success, or -1 and nil on failure.

func (*Saltpack) LookupSigningPublicKey Uses

func (s *Saltpack) LookupSigningPublicKey(b []byte) ksaltpack.SigningPublicKey

LookupSigningPublicKey (for ksaltpack.SigKeyring)

func (*Saltpack) NewDecryptArmoredStream Uses

func (s *Saltpack) NewDecryptArmoredStream(r io.Reader) (io.Reader, *keys.X25519PublicKey, error)

NewDecryptArmoredStream creates decryption stream. If there was a sender, will return a X25519 key ID.

func (*Saltpack) NewDecryptStream Uses

func (s *Saltpack) NewDecryptStream(r io.Reader) (io.Reader, *keys.X25519PublicKey, error)

NewDecryptStream create decryption stream. If there was a sender, will return a X25519 key ID.

func (*Saltpack) NewEncryptArmoredStream Uses

func (s *Saltpack) NewEncryptArmoredStream(w io.Writer, sender *keys.X25519Key, recipients ...keys.ID) (io.WriteCloser, error)

NewEncryptArmoredStream creates an encrypted armored io.WriteCloser. Sender can be nil, if you want it to be anonymous.

func (*Saltpack) NewEncryptStream Uses

func (s *Saltpack) NewEncryptStream(w io.Writer, sender *keys.X25519Key, recipients ...keys.ID) (io.WriteCloser, error)

NewEncryptStream creates an encrypted io.WriteCloser. Sender can be nil, if you want it to be anonymous.

func (*Saltpack) NewSignArmoredDetachedStream Uses

func (s *Saltpack) NewSignArmoredDetachedStream(w io.Writer, key *keys.EdX25519Key, detached bool) (io.WriteCloser, error)

NewSignArmoredDetachedStream ...

func (*Saltpack) NewSignArmoredStream Uses

func (s *Saltpack) NewSignArmoredStream(w io.Writer, key *keys.EdX25519Key, detached bool) (io.WriteCloser, error)

NewSignArmoredStream ...

func (*Saltpack) NewSignDetachedStream Uses

func (s *Saltpack) NewSignDetachedStream(w io.Writer, key *keys.EdX25519Key, detached bool) (io.WriteCloser, error)

NewSignDetachedStream ...

func (*Saltpack) NewSignStream Uses

func (s *Saltpack) NewSignStream(w io.Writer, key *keys.EdX25519Key, detached bool) (io.WriteCloser, error)

NewSignStream ...

func (*Saltpack) NewSigncryptArmoredOpenStream Uses

func (s *Saltpack) NewSigncryptArmoredOpenStream(r io.Reader) (io.Reader, *keys.EdX25519PublicKey, error)

NewSigncryptArmoredOpenStream ...

func (*Saltpack) NewSigncryptArmoredStream Uses

func (s *Saltpack) NewSigncryptArmoredStream(w io.Writer, sender *keys.EdX25519Key, recipients ...keys.ID) (io.WriteCloser, error)

NewSigncryptArmoredStream creates a signcrypt stream.

func (*Saltpack) NewSigncryptOpenStream Uses

func (s *Saltpack) NewSigncryptOpenStream(r io.Reader) (io.Reader, *keys.EdX25519PublicKey, error)

NewSigncryptOpenStream creates a signcrypt open stream.

func (*Saltpack) NewSigncryptStream Uses

func (s *Saltpack) NewSigncryptStream(w io.Writer, sender *keys.EdX25519Key, recipients ...keys.ID) (io.WriteCloser, error)

NewSigncryptStream creates a signcrypt stream.

func (*Saltpack) NewVerifyArmoredStream Uses

func (s *Saltpack) NewVerifyArmoredStream(r io.Reader) (io.Reader, keys.ID, error)

NewVerifyArmoredStream ...

func (*Saltpack) NewVerifyStream Uses

func (s *Saltpack) NewVerifyStream(r io.Reader) (io.Reader, keys.ID, error)

NewVerifyStream ...

func (*Saltpack) Sign Uses

func (s *Saltpack) Sign(b []byte, key *keys.EdX25519Key) ([]byte, error)

Sign ...


sp := saltpack.NewSaltpack(nil)

alice := keys.GenerateEdX25519Key()

message := []byte("hi from alice")

sig, err := sp.SignArmored(message, alice)
if err != nil {
fmt.Printf("%s\n", alice.ID())
fmt.Printf("%s\n", sig)

func (*Saltpack) SignArmored Uses

func (s *Saltpack) SignArmored(b []byte, key *keys.EdX25519Key) (string, error)

SignArmored ...

func (*Saltpack) SignArmoredDetached Uses

func (s *Saltpack) SignArmoredDetached(b []byte, key *keys.EdX25519Key) (string, error)

SignArmoredDetached ...

func (*Saltpack) SignDetached Uses

func (s *Saltpack) SignDetached(b []byte, key *keys.EdX25519Key) ([]byte, error)

SignDetached ...


sp := saltpack.NewSaltpack(nil)

alice := keys.GenerateEdX25519Key()

message := []byte("hi from alice")

sig, err := sp.SignArmoredDetached(message, alice)
if err != nil {
fmt.Printf("%s", sig)

func (*Saltpack) Signcrypt Uses

func (s *Saltpack) Signcrypt(b []byte, sender *keys.EdX25519Key, recipients ...keys.ID) ([]byte, error)

Signcrypt to recipients.

func (*Saltpack) SigncryptArmored Uses

func (s *Saltpack) SigncryptArmored(b []byte, sender *keys.EdX25519Key, recipients ...keys.ID) (string, error)

SigncryptArmored to recipients.

func (*Saltpack) SigncryptArmoredOpen Uses

func (s *Saltpack) SigncryptArmoredOpen(str string) ([]byte, *keys.EdX25519PublicKey, error)

SigncryptArmoredOpen ...

func (*Saltpack) SigncryptOpen Uses

func (s *Saltpack) SigncryptOpen(b []byte) ([]byte, *keys.EdX25519PublicKey, error)

SigncryptOpen ...

func (*Saltpack) Verify Uses

func (s *Saltpack) Verify(b []byte) ([]byte, keys.ID, error)

Verify ...


sp := saltpack.NewSaltpack(nil)

aliceID := keys.ID("kex1w2jep8dkr2s0g9kx5g6xe3387jslnlj08yactvn8xdtrx4cnypjq9rpnux")
	kXR7VktZdyH7rvq v5wcIkHbs7mPCSd NhKLR9E0K47y29T QkuYinHym6EfZwL 
	1TwgxI3RQ52fHg5 1FzmLOMghcYLcV7 i0l0ovabGhxGrEl z7WuI4O3xMU5saq 
	U28RqUnKNroATPO 5rn2YyQcut2SeMn lXJBlDqRv9WyxjG M0PcKvsAsvmid1m 
	cqA4TCjz5V9VpuO zuIQ55lRQLeP5kU aWFxq5Nl8WsPqlR RdX86OuTbaKUvKI 
	wdNd6ISacrT0I82 qZ71sc7sTxiMxoI P43uCGaAZZ3Ab62 vR8N6WQPE8. 

out, signer, err := sp.VerifyArmored(sig)
if err != nil {
if signer == aliceID {
    fmt.Printf("signer is alice\n")
fmt.Printf("%s\n", string(out))


signer is alice
hi from alice

func (*Saltpack) VerifyArmored Uses

func (s *Saltpack) VerifyArmored(msg string) ([]byte, keys.ID, error)

VerifyArmored ...

func (*Saltpack) VerifyArmoredDetached Uses

func (s *Saltpack) VerifyArmoredDetached(sig string, b []byte) (keys.ID, error)

VerifyArmoredDetached ...

func (*Saltpack) VerifyDetached Uses

func (s *Saltpack) VerifyDetached(sig []byte, b []byte) (keys.ID, error)

VerifyDetached ...

Package saltpack imports 13 packages (graph) and is imported by 2 packages. Updated 2020-04-09. Refresh now. Tools for package owners.