conncrypt

package module
v0.0.0-...-6e95063 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2015 License: MIT Imports: 7 Imported by: 0

README

ConnCrypt

Symmetrically encrypt your Go (Golang) net.Conns

ConnCrypt does not perform any authentication, only encryption and decryption. This makes it vulnernable to a wide range of attacks (e.g. replay, data-corruption, known-plain texts). You have been warned.

ConnCrypt takes a passphrase and uses PBKDF2 to convert it into an AES256 key. The initialization vector is the hashed AES256 key. The block cipher mode is currently set to CFB, this is not as performant as OFB, though slightly more resistant to attack.

This could be improved by introducing a small handshake into this process to create a secure initialization vector – will accept PRs.

GoDoc

Install
go get -v github.com/jpillora/conncrypt
Usage

See example/main.go

conn, err := net.Dial("tcp", "127.0.0.1:3000")
if err != nil {
	log.Fatal(err)
}

conn.Write([]byte("hello world\n"))

//encrypt and decrypt conn using with AES256
conn = conncrypt.New(conn, &conncrypt.Config{
	Password: "my-super-secret-password",
})

conn.Write([]byte("hello world\n"))
hello world
m�o�׫b�7\�⏎
MIT License

Copyright © 2015 Jaime Pillora <dev@jpillora.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

View Source
const DefaultIterations = 2048

Confg defaults

View Source
const DefaultKeySize = 32 //256bits

Variables

View Source
var DefaultHashFunc = sha256.New
View Source
var DefaultSalt = []byte(`
(;QUHj.BQ?RXzYSO]ifkXp/G!kFmWyXyEV6Nt!d|@bo+N$L9+<d$|g6e26T}
Ao<:>SOd,6acYKY_ec+(x"R";\'4&fTAVu92GVA-wxBptOTM^2,iP5%)wnhW
hwk=]Snsgymt!3gbP2pe=J//}1a?lp9ej=&TB!C_V(cT2?z8wyoL_-13fd[]

`) //salt must be predefined in order to derive the same key

Functions

func New

func New(conn net.Conn, c *Config) net.Conn

New creates an AES encrypted net.Conn by generating a key using PBKDF2 with the provided configuration

func NewFromKey

func NewFromKey(conn net.Conn, key []byte) (net.Conn, error)

NewFromKey creates an AES encrypted net.Conn using the provided key

Types

type Config

type Config struct {
	Password   string
	Salt       []byte
	Iterations int
	KeySize    int
	HashFunc   func() hash.Hash
}

Config stores the PBKDF2 key generation parameters

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL