Skip to content
/ tools Public

Some encrypt and decrypt tools, use algorithm like des, 3des, aes. Some abstract algorithm also contained in this package.

Notifications You must be signed in to change notification settings

Tom-Kail/tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

tools

Up to now, this package contains some encrypt, decrypt and abstract algorithms. 
In the future, I will add more useful tools.

Supported encrypt and decrypt algorithms

aes, des, 3des, base64

Supported abstract algorithms

md5_16, md5_32, sha1

Demo

Encrypt and decrypt file

package main

import (
	"log"
	"time"

	"github.com/Tom-Kail/tools"
)

func main() {
	log.Println("start")
	EB := time.Now().UnixNano()
	//  `myfile.txt` is a file waiting to be encrypted, `cipher.txt` is encrypt output, 10240 byte is buffer size
	err := tools.EncryptFile("myfile.txt", "cipher.txt", "aes", []byte("your_key"), 10240)
	if err != nil {
		log.Fatal(err)
	}
	EF := time.Now().UnixNano()
	DB := time.Now().UnixNano()
	err = tools.DecryptFile("cipher.txt", "clear.txt", "aes", []byte("your_key"), 10240)
	if err != nil {
		log.Fatal(err)
	}
	DF := time.Now().UnixNano()
	log.Println("finish")
	EC := float64(EF-EB) / 1000000000
	DC := float64(DF-DB) / 1000000000
	log.Println("\t\nEncrypt cost: ", EC, "\t\nDecrypt cost: ", DC)

}

Encrypt and decrypt byte array

func Encrypt(data []byte, typ string, key []byte) ([]byte, error) {
	....
}

func Decrypt(data []byte, typ string, key []byte) ([]byte, error) {
	....
}

About

Some encrypt and decrypt tools, use algorithm like des, 3des, aes. Some abstract algorithm also contained in this package.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages