encryption

package module
v0.0.0-...-14583f9 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2017 License: MIT Imports: 9 Imported by: 0

README

encryption

travis go report card coverage godocs

A very simple wrapper for pbkdf2 encryption that follows NIST recommendations for constructing IVs (see NIST publication section 8.2). See godoc for information and tests for usage.

Example
package main

import (
        "fmt"
        "github.com/schollz/encryption"
)

func main() {
        s := []byte("hello, world")
        p := "secret passphrase"
        encrypted := encryption.Encrypt(s, p)
        fmt.Println(encrypted)
        // prints: agjZrMKjmY2LOnq3.jsOW25nDrq4=.UydSNRCWCwev1Pp53ThDZtUZkJoDuFBt81aZTA==
        
        decrypted, err := encryption.Decrypt(encrypted, p)
        fmt.Println(string(decrypted), err)
        // Hello, world <nil>
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Iter = 500

Iter is the iteration count for pbkdf2. Using a higher iteration count will increase the cost of an exhaustive search but will also make derivation proportionally slower.

Functions

func Decrypt

func Decrypt(encrypted string, passphrase string) (decrypted []byte, err error)

Decrypt string of form `iv.salt.encrypted` to the byte of its original. Throws error if the decryption fails.

func DecryptByte

func DecryptByte(data []byte, passphrase []byte, salt []byte, iv []byte) (plaintext []byte, err error)

DecryptByte using pdbkdf2 decyprtion as specified by NIST to decrypt bytes based on a passphrase, a salt, and an IV.

func Encrypt

func Encrypt(plaintext []byte, passphrase string) string

Encrypt byte using string passphrase into a string `iv.salt.encrypted` which each piece (iv, salt, encrypted) is base64 encoded. Can be decrypted using Decrypt.

func EncryptByte

func EncryptByte(plaintext []byte, passphrase []byte) (encrypted []byte, salt []byte, iv []byte)

EncryptByte using pdbkdf2 encryption as specified by NIST. See Section 8.2 of http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf for more information.

Types

This section is empty.

Jump to

Keyboard shortcuts

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