Documentation
¶
Overview ¶
ephemeral secret - ECDHE based on Curve25519 meets XChaCha20-Poly1305 AEAD.
This package provides functions to easily generate keys to en-/decrypt data through a derived key of the consensus secret from the used ephemeral keys (private/public). The knowledge of the senders (private) and receivers (public) keys are the basic information to exchange data with encrypted messages.
Structure: Version[2], Sender's Public Key[32], Ciphertext[NonceSizeX[24]+Overhead[16]+Payload[x]], Hash[8]
Index ¶
- Variables
- func New() (Key, *Message, error)
- func Salt() ([]byte, error)
- type Compression
- type Decoding
- type Encoding
- type Key
- type Kind
- type Message
- func (m *Message) Bytes() []byte
- func (m *Message) Compress(c Compression)
- func (m *Message) Decompress(d Compression)
- func (m *Message) Decrypt(private Key, salt []byte) ([]byte, error)
- func (m *Message) Encrypt(private, public Key, data []byte, salt []byte) error
- func (m *Message) Method() byte
- func (m *Message) Payload(payload []byte)
- func (m *Message) Public() Key
- func (m *Message) Purge()
- func (m *Message) String() string
- func (m *Message) Version() byte
- type Version
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( Encoder Encoding = defaultEncoder Decoder Decoding = defaultDecoder )
Functions ¶
Types ¶
type Compression ¶
var ( Compressor Compression = nil Decompressor Compression = nil )
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
func PrivateKey ¶
PrivateKey converts the given key to a Private Key.
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
func (*Message) Compress ¶
func (m *Message) Compress(c Compression)
Compress sets c as Compression method to compress the payload of that Message.
func (*Message) Decompress ¶
func (m *Message) Decompress(d Compression)
Decompress sets d as Compession method to decompress the payload of that Message.
func (*Message) Decrypt ¶
Decrypt Message's data for receivers private Key and return the decrypted data.
Example ¶
package main import ( "fmt" "log" "catinello.eu/es" ) var ( Receiver es.Key M *es.Message Salt []byte ) func main() { // decrypt for Receiver (private key) the Message pt, err := M.Decrypt(Receiver, Salt) if err != nil { log.Fatal(err) } // print first 11 bytes fmt.Println(string(pt[:11])) }
Output: Lorem ipsum
func (*Message) Encrypt ¶
Encrypt the given data for receiver public Key with senders private Key.
Example ¶
package main import ( "fmt" "log" "catinello.eu/es" ) var ( Data []byte = []byte("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.") Sender []byte = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} ReceiverPublic es.Key M *es.Message Salt []byte ) func main() { // use senders private key sender, err := es.PrivateKey(Sender) if err != nil { log.Fatal(err) } // encrypt Data in to Message for Receiver (public key) err = M.Encrypt(sender, ReceiverPublic, Data, Salt) if err != nil { log.Fatal(err) } // ciphertext is 673 bytes long fmt.Println(len(M.Bytes())) }
Output: 673