gocrypt

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

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

Go to latest
Published: Sep 19, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

README

GoCrypt - A Golang Encryption Helper Package

maintained by: hkdb


gocrypt


SUMMARY:

Package 3dfosi/gocrypt provides simplified helper functions for using scrypt (128-bit salt, N=32768, r=8 and p=1) generated hash as a key to encrypt data with AES-256-GCM.

Common use cases include but are not limited to encrypting data at rest for applications and symetric encryption automation prior to transfering files to destination.

USAGE:

Import package:

import "github.com/3dfosi/gocrypt"

Example:

package main

import (
	"encoding/hex"
	"log"

	"github.com/3dfosi/gocrypt"
)

var passphrase = "SOME-CRAZY-LONG-PASSPHRASE"

func main() {

	// Encrypt Data
	encrypted_data, salt, err := gocrypt.Encrypt([]byte("Hello World"), passphrase)
	if err != nil {
		log.Println(err)
		return
	}
	log.Println("Encrypted DATA:", hex.EncodeToString(encrypted_data))
	log.Println("SALT:", hex.EncodeToString(salt))

	// Decrypt Data
	plaintext, err := gocrypt.Decrypt(encrypted_data, salt, passphrase)
	if err != nil {
		log.Println(err)
		return
	}
	log.Println("Plain Text:", string(plaintext))

}
DOCUMENTATION

Check out the documentation for further details on the functions available.

CHANGE
  • 09182022 - Initial commit
SUPPORT US!

If this repo was useful to you, feel free to buy us some coffees! :)

DISCLAIMER

This repo is sponsored by 3DF OSI and is maintained by volunteers. 3DF Limited, 3DF OSI, and its volunteers in no way make any guarantees. Please use at your own risk!

To Learn more, please visit:

https://osi.3df.io

https://3df.io

Documentation

Overview

Package 3dfosi/gocrypt provides simplified helper functions for using scrypt (128-bit salt, N=32768, r=8 and p=1) generated hash as a key to encrypt data with AES-256-GCM.

Common use cases include but are not limited to encrypting data at rest for applications and symetric encryption automation prior to transfering files to destination.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(data []byte, salt []byte, pass string) ([]byte, error)

Function to decrypt data

Variables to pass in:

data []byte - Data to be encrypted
salt []byte - Salt to use to create hash
pass string - Passphrase to use for encryption

Returns:

[]byte - Decrypted Data
error  - Error

func DecryptFile

func DecryptFile(file string, from string, to string, passphrase string) error

Function to decrypt data from a file and output to a new file

Variables to pass in:

file string - Name of the file
from string - Specify path of file
to   string - Specify destination path to output file
              (must end with "/" ie. /opt/app/ instead of /opt/app)
pass string - Passphrase to use for encryption

Returns:

[]byte - Salt used to encrypt
error  - Error

func DecryptFromFile

func DecryptFromFile(file string, salt []byte, passphrase string) ([]byte, error)

Function to decrypt data from a file

Variables to pass in:

file string - Name of the file (full path)
salt []byte - Salt used to create hash
pass string - Passphrase to use for encryption

Returns:

[]byte - Decrypted Data
error  - Error

func Encrypt

func Encrypt(data []byte, pass string) ([]byte, []byte, error)

Function to encrypt data

Variables to pass in:

data []byte - Data to be encrypted
pass string - Passphrase to use for encryption

Returns:

[]byte - Encrypted Data
[]byte - Salt
error  - Error

func EncryptFile

func EncryptFile(file string, from string, to string, passphrase string) error

Function to encrypt an existing file.

Variables to pass in:

file string - Name of the file
from string - Specify path of file
to   string - Specify destination path to output file
              (must end with "/" ie. /opt/app/ instead of /opt/app)
pass string - Passphrase to use for encryption

Returns:

[]byte - Salt used to encrypt
error  - Error

func EncryptToFile

func EncryptToFile(file string, to string, data []byte, passphrase string) ([]byte, error)

Function to encrypt data and output to a file

Variables to pass in:

file string - Name of the file (full path)
to   string - Specify destination path of file
              (must end with "/" ie. /opt/app/ instead of /opt/app)
pass string - Passphrase to use for encryption

Returns:

[]byte - Salt used to encrypt
error  - Error

Types

This section is empty.

Jump to

Keyboard shortcuts

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