lithcrypt

package module
v0.0.0-...-e90eacd Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2017 License: MIT Imports: 8 Imported by: 0

README

Install

go get github.com/richard-lyman/lithcrypt/

Dependencies

  1. scrypt
  2. crypto/aes
  3. crypto/cipher
  4. crypto/rand

Format

The result of encrypting some byte slice is a header followed by the encrypted content. The header contains the salt, N, r, p, key length, and iv - enough to decrypt the content if the password is provided.

Example

  1. Run the installation command from above
  2. Place the following code in some file (we'll call ours 'main.go')
  3. From the same folder where you created your file ('main.go'), run the command go run main.go (replacing 'main.go' with whatever name you gave your file)
package main

import (
    "encoding/base64"
    "fmt"
    "github.com/richard-lyman/lithcrypt"
    "os"
)

func main() {

    payload := []byte("Something to be encrypted")
    password := []byte("some password")

    encrypted, encrypt_error := lithcrypt.Encrypt(password, payload)
    if encrypt_error != nil {
        fmt.Println("Failed to encrypt:", encrypt_error)
        os.Exit(1)
    }
    fmt.Println("Encrypted payload:", byteSliceToBase64(encrypted))

    original, decrypt_error := lithcrypt.Decrypt(password, encrypted)
    if decrypt_error != nil {
        fmt.Println("Failed to decrypt:", decrypt_error)
        os.Exit(1)
    }
    fmt.Println("Decrypted payload:", string(original))

}

func byteSliceToBase64(b []byte) string {
    result := make([]byte, base64.StdEncoding.EncodedLen(len(b)))
    base64.StdEncoding.Encode(result, b)
    return string(result)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(password []byte, payload []byte) (result []byte, err error)

func Encrypt

func Encrypt(password []byte, payload []byte) ([]byte, error)

func GenKey

func GenKey(password []byte, salt []byte, iter int, keyLen int) ([]byte, error)

func GetRandom

func GetRandom(size int) ([]byte, error)

func ParameterizedEncrypt

func ParameterizedEncrypt(password []byte, payload []byte, iter int, keyLen int) ([]byte, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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