Giter Club home page Giter Club logo

aesgzip's Introduction

注意⚠️:与aes不通用,此代码每1024B × 1024 - 1 进行一次 aes 加密。

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/hunyxv/aesgzip"
)

func init () {
	// 修改 aes 初始化变量(16字节)
	aesgzip.IV  = []byte("[email protected]^765=")
}

func main() {
	aesKey := []byte("123abc456def7890")

	// 文件压缩加密
    plaintext, err := os.Open("input.txt")
	if err != nil {
		log.Fatalln(err)
	}
	defer plaintext.Close()
	dstPath := "output.gz.aes"

	err = aesgzip.GzipEncryption(plaintext, dstPath, aesKey)
	if err != nil {
		log.Fatalln(err)
	}

	// 解密解压缩

	ciphertext, err := os.Open("output.gz.aes")
	if err != nil {
		log.Fatalln(err)
	}
	defer ciphertext.Close()
	dstPath = "output.txt"
	
	err = aesgzip.DecryptUngzip(ciphertext, dstPath, aesKey)
	if err != nil {
		log.Fatalln(err)
	}

	// 一句话加解密
	text := []byte("How are you? I'm fine, thanks!")
	fmt.Println("aes加密前:", text)
	aesText, _ := aesgzip.Encrypt(text, aesKey)
	fmt.Println("aes加密后:", aesText)
	pText, _ := aesgzip.Decrypt(aesText, aesKey)
	fmt.Println("aes解密后:", pText)

	// 一句话加密并压缩 和 解密解压缩
	data := []byte(`{
		"version": "0.1",
		"timestamp": 1586519299,
		"param": {
			"type": 1,
			"list": [
				{"video_id": "v_19rwstgyo4", "update_time": 1586514239, "event": "Update"},
				{"video_id": "v_19rsd3g6o4", "update_time": 1586514249, "event": "Update"},
				{"video_id": "v_19rws3jjr9", "update_time": 1586514259, "event": "Update"}
			]
		}
	}`)

	xx, err := aesgzip.RowGzipEncryption(data, aesKey)
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Println(xx)

	xd, err := aesgzip.RowDecryptUngzip(xx, aesKey)
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Println(xd)
}

aesgzip's People

Contributors

hunyxv avatar

Watchers

 avatar

Forkers

nkchwfree

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.