Categorygithub.com/geeks-accelerator/cryptoengine
modulepackage
0.0.0-20200203072530-3f426d88937b
Repository: https://github.com/geeks-accelerator/cryptoengine.git
Documentation: pkg.go.dev

# README

Build status

Build Status GoDoc

CryptoEngine package

This simplifies even further the usage of the NaCl crypto primitives, by taking care of the nonce part. It uses a KDF, specifically HKDF to compute the nonces.

Big Picture

The encryption and decryption phases are the following:


Message -> Encrypt -> EncryptedMessage -> ToBytes() -> < = NETWORK = >  <- FromBytes() -> EncryptedMessage -> Decrypt -> Message

Usage

1- Import the library

import github.com/sec51/cryptoengine

2- Instanciate the CryptoEngine object via:

	engine, err := cryptoengine.InitCryptoEngine("Sec51")
	if err != nil {
		return err
	}

See the godoc for more info about the InitCryptoEngine parameter

3- Encrypt a message using symmetric encryption

    message := "the quick brown fox jumps over the lazy dog"
	engine.NewMessage(message)
	if err != nil {
		return err
	}

4- Serialize the message to a byte slice, so that it can be safely sent to the network

	messageBytes, err := tcp.ToBytes()
	if err != nil {
		t.Fatal(err)
	}	

5- Parse the byte slice back to a message

	message, err := MessageFromBytes(messageBytes)
	if err != nil {
		t.Fatal(err)
	}

License

Copyright (c) 2015 Sec51.com [email protected]

Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

# Packages

No description provided by the author

# Functions

This function initialize all the necessary information to carry out a secure communication either via public key cryptography or secret key cryptography.
Create a new message with a clear text and the message type messageType: is an identifier to distinguish the messages on the receiver and parse them for example if zero is a JSON message and 1 is XML, then the received can parse different formats with different methods.
NewStorageAws implements the interface Storage to support persisting private keys to AWS Secrets Manager.
NewStorageMemory implements the interface Storage to store a single key in memory.
This function instantiate the verification engine by leveraging the context Basically if a public key of a peer is available locally then it's locaded here.
This function instantiate the verification engine by passing it the key (at the moment only the public key) go nacl crypto does not support Ed25519 signatures yet.

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

This is the basic object which needs to be instanciated for encrypting messages either via public key cryptography or private key cryptography The object has the methods necessary to execute all the needed functions to encrypt and decrypt a message, both with symmetric and asymmetric crypto.
This struct represent the encrypted message which can be sent over the networl safely |lenght| => 8 bytes (uint64 total message length) |nonce| => 24 bytes ([]byte size) |message| => N bytes ([]byte message).
StorageAws is a storage engine that uses AWS Secrets Manager to persist private keys.
StorageMemory...
The verification engine links two peers basically.

# Interfaces

Storage provides the ability to persist keys to custom locations.