Documentation ¶
Overview ¶
Package eitherbox provides a cryptographically secure composition of NaCL secretbox that can be opened by either of two key holders.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Box ¶
type Box []byte
Box is a cryptographically secure box that can be opened with one of two keys.
func Encrypt ¶
Encrypt encrypts `b` into a package that can be decrypted by either public key. Public/private keypairs should be generated with box.GenerateKey(..).
Example ¶
// Create keys for Alice alicePublic, alicePrivate, _ := box.GenerateKey(rand.Reader) // Create keys for Bob bobPublic, bobPrivate, _ := box.GenerateKey(rand.Reader) // Create keys for Eve evePublic, evePrivate, _ := box.GenerateKey(rand.Reader) secret := []byte("hello world") twokeyBox := Encrypt(secret, alicePublic, bobPublic) // Alice can decrypt aliceMsg, _ := twokeyBox.Decrypt(alicePublic, alicePrivate) // Bob can decrypt bobMsg, _ := twokeyBox.Decrypt(bobPublic, bobPrivate) // Eve can't decrypt eveMsg, _ := twokeyBox.Decrypt(evePublic, evePrivate) fmt.Println("Alice got:", string(aliceMsg)) fmt.Println("Bob got:", string(bobMsg)) fmt.Println("Eve got:", string(eveMsg))
Output: Alice got: hello world Bob got: hello world Eve got:
Click to show internal directories.
Click to hide internal directories.