Giter Site home page Giter Site logo

gosymcryto's Introduction

GoSymCrypto

Go Symmetric Cryptography aims to provide some tools to encrypt/decrypt data using symmetric cryptography in a way that is safe by default. This package contains two packages: a simpler crypto library and a more advanced message one.

Crypto

The crypto package provides simpler utilities to encrypt and decrypt data. It provides utilities to derive a secure key and automatically generates a secure random nonce.

Example

key := crypto.DeriveSecureKey("secret password", nil, 0, 0, 0)
ciphertext, err := crypto.Encrypt(key, []byte("hello world"))
if err != nil {
	panic(err)
}
plaintext, err := crypto.Decrypt(key, ciphertext)
if err != nil {
	panic(err)
}

Message

The message package allows users to create use symmetric cryptography between two peers via a net.Conn interface.

This can be used to enable peer-to-peer communications using a symmetric key while making replay attacks more challenging to perform thanks to a randomized challenge value that gets used during the communications.

Example

// setup some `conn net.Conn`...
conn.SetDeadline(time.Now().Add(time.Second))
connection, err := message.NewConnection(conn, key)
if err != nil {
	connection.Close() // We still want to close the underlying connection
	panic(fmt.Sprintf("handshake failed: %v", err))
}
defer connection.Close()
data := []byte("hello")
if err = connection.WriteMessage([]byte("hello")); err != nil {
	panic(fmt.Sprintf("failed to write 'hello' to server: %v", err))
}
message, err := connection.ReadMessage()
if err != nil {
	panic(fmt.Sprintf("failed to read message from server: %v", err))
}
fmt.Sprintf("Reply: %q", message)

gosymcryto's People

Contributors

stefanovazzocell avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.