crypter

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

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

Go to latest
Published: Mar 31, 2022 License: MIT Imports: 6 Imported by: 0

README

crypter

AES encryption and hashing of string data.

Install

go get github.com/MichailVestnik/crypter

Create new AES encrypter

const (
	signature = "QAWSEDRFTGYHUJIKOLAZSXDCFVGBHNJM" // must by 32 bytes!
	ivector   = "vector"
	salt      = "SALT:SDR123"
	data      = "String Data"
)

crypt := crypter.New(signature, ivector, salt)

Encrypt and decrypt data


// encrypt data
encr, e := crypt.Encrypt(data)
if e != nil {
    log.Fatal(e)
}
fmt.Printf("encrypted data: %v\n", encr)

// decrypt data
decr, e := crypt.Decrypt(encr)
if e != nil {
    log.Fatal(e)
}
fmt.Printf("decrypted data: %v\n", decr)

Encrypt and decrypt data with hex

encr, e := crypt.Encrypt(data)
if e != nil {
    log.Fatal(e)
}
fmt.Printf("encrypted data: %v\n", encr)

str := hex.EncodeToString(encr)
fmt.Printf("hex string: %v\n", str)

// decrypt data
bytes, e := hex.DecodeString(str)
if e != nil {
    log.Fatal(e)
}

decr, e := crypt.Decrypt(bytes)
if e != nil {
    log.Fatal(e)
}
fmt.Printf("decrypted data: %v\n", decr)

Hash

// hash with sha256
sha := crypt.SHA256(data)
fmt.Println(sha)

// hash with md5
md5 := crypt.MD5(data)
fmt.Println(md5)

Documentation

Overview

AES encryption and data hashing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Crypter

type Crypter struct {
	// contains filtered or unexported fields
}

Структура.

func New

func New(signature, ivector, salt string) *Crypter

New AES crypter.

func (*Crypter) Decrypt

func (c *Crypter) Decrypt(encrypted []byte) (string, error)

Method decrypts the data.

func (*Crypter) Encrypt

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

Method encrypts the data.

func (*Crypter) MD5

func (c *Crypter) MD5(data string) []byte

Method hashes the data using the algorithm md5

func (*Crypter) SHA256

func (c *Crypter) SHA256(data string) []byte

Method hashes the data using the algorithm sha256

Jump to

Keyboard shortcuts

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