scrypt

package module
v0.0.0-...-5587a9b Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2023 License: MIT Imports: 10 Imported by: 0

README

go-scrypt

Encrypt data with password

go get -u golang.org/x/crypto
go get -u https://github.com/null-none/go-scrypt
package main

import (
	Scrypt "github.com/null-none/go-scrypt"
	"bufio"
	"crypto/aes"
	"crypto/cipher"
	"crypto/rand"
	"encoding/hex"
	"fmt"
	"golang.org/x/crypto/scrypt"
	"log"
	"os"
	"strings"
)


func main() {
	reader := bufio.NewReader(os.Stdin)
	fmt.Println("Enter password and text for encryption")
	fmt.Println("---------------------")
	fmt.Print("Password -> ")
	inputPassword, _ := reader.ReadString('\n')
	inputPassword = strings.Replace(inputPassword, "\n", "", -1)
	fmt.Print("Data -> ")
	inputData, _ := reader.ReadString('\n')
	inputData = strings.Replace(inputData, "\n", "", -1)

	var (
		password = []byte(inputPassword)
		data     = []byte(inputData)
	)
	ciphertext, err := Scrypt.Encrypt(password, data)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("ciphertext: %s\n", hex.EncodeToString(ciphertext))
	plaintext, err := Scrypt.Decrypt(password, ciphertext)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("plaintext: %s\n", plaintext)
  
}
Enter password and text for encryption
---------------------
Password -> test
Data -> test
ciphertext: bc73454392d981a41fc3e36e8c9d547028ed02524bcfb7f112c683a8ac649786f56ffa591e0527a74d679b841d3e625f96541dc170a245c5df4818233e3f3d22
plaintext: test

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(key, data []byte) ([]byte, error)

func DeriveKey

func DeriveKey(password, salt []byte) ([]byte, []byte, error)

func Encrypt

func Encrypt(key, data []byte) ([]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