chacha20poly1305_scrypt_block

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

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

Go to latest
Published: Mar 7, 2023 License: GPL-3.0 Imports: 6 Imported by: 0

README

logo

Simple wrapper around chacha20poly1305 and scrypt

Simple wrapper around the chacha20poly1305 and scrypt hash to encrypt small chunks of data.
Can be used as a library or as a command line tool located in cmd/cipherCli.

Library usage

package main

import (
	"bytes"
	"log"

	cipher "github.com/8ff/chacha20poly1305_scrypt_block"
)

func main() {
	data := []byte("Hello world")
	key := make([]byte, cipher.ParamDefaults.KeySize)
	// Set key to some long phrase that is of key size
	copy(key, []byte("This is a long phrase that is of key size"))

	// Initialize cipher
	c, err := cipher.Init(cipher.Params{Key: key})
	if err != nil {
		log.Fatalf("Failed to initialize cipher: %v", err)
	}

	// Encrypt data
	encrypted, err := c.Encrypt(data)
	if err != nil {
		log.Fatalf("Failed to encrypt data: %v", err)
	}

	// Decrypt data
	decrypted, err := c.Decrypt(encrypted)
	if err != nil {
		log.Fatalf("Failed to decrypt data: %v", err)
	}

	// Verify that decrypted data is the same as original data
	if !bytes.Equal(data, decrypted) {
		log.Fatalf("Decrypted data is not the same as original data")
	}

	// Print Input and decrypted string
	log.Printf("Input: %s\n", data)
	log.Printf("Decrypted: %s\n", decrypted)
}

Command line usage

foo@bar:~$ cd cmd/cipherCli
foo@bar:~$ cipherCli % echo test | CKEY=test go run cipherCli.go e | CKEY=test go run cipherCli.go d
test

Disclaimer

This is a very simple wrapper around the chacha20poly1305 and scrypt hash. It has not been audited, use at your own risk.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ParamDefaults = Params{
	SaltSize:  32,
	NonceSize: chacha20poly1305.NonceSizeX,
	KeySize:   chacha20poly1305.KeySize,
}

Sane defaults

Functions

This section is empty.

Types

type Params

type Params struct {
	SaltSize  int
	NonceSize int
	KeySize   int
	Key       []byte
}

func Init

func Init(params Params) (*Params, error)

func (*Params) Decrypt

func (c *Params) Decrypt(data []byte) ([]byte, error)

Decrypt function based on chacha20poly1305 and scrypt

func (*Params) Encrypt

func (c *Params) Encrypt(data []byte) ([]byte, error)

Encrypt function based on chacha20poly1305 and scrypt

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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