cipher

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: MIT Imports: 8 Imported by: 0

README

Cipher

Cipher algorithms in Golang

PkgGoDev Go Report Card GitHub tag (latest by date) GitHub


Getting Started

Prerequisite

Create .env file in your root directory and add below variables

  • CIPHER_PASSWORD
  • CIPHER_SALT

Note: Rotate password/salt pair regularly

When encryption runs more than 2^32 times, Nonce is at the risk of a repeat

Installing

go get it (pun intended 😸)

go get github.com/junekimdev/cipher

Usage

package main

import (
  "log"

  "github.com/junekimdev/cipher"
)


func main() {
  // text to encrypt
  encrypted, err := cipher.Encrypt(text)

  // encrypted text to decrypt
  decrypted, err := cipher.Decrypt(string(encrypted))
  ////---- decrypted == text

  // a file to encrypt
  cipher.EncryptFile(plainTextFile1, encryptedFile)

  // encrypted text to decrypt
  cipher.DecryptFile(encryptedFile, plainTextFile2)
  ////---- plainTextFile1 == plainTextFile2
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEnvNotLoaded = errors.New("Environment variables are not loaded")
)

Error

Functions

func Decrypt

func Decrypt(encrypted string) ([]byte, error)

Decrypt encrypted text with GCM cipher

func DecryptFile

func DecryptFile(inFilepath, outFilepath string) error

DecryptFile decrypts an encrypted file with CTR cipher

func Encrypt

func Encrypt(text string) ([]byte, error)

Encrypt plaintext with GCM cipher

func EncryptFile

func EncryptFile(inFilepath, outFilepath string) error

EncryptFile encrypts a file with CTR cipher

Types

This section is empty.

Jump to

Keyboard shortcuts

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