Code Monkey home page Code Monkey logo

go-crypto's Introduction

说明

主要针对“AES和DES加密算法”的应用:

  • 加密模式:"ECB", "CBC", "CTR", "OFB", "CFB"
  • 填充方式:"PKCS5", "PKCS7", "ZERO"
  • 输出格式:"BASE64", "HEX"

demo

package main

import (
	"fmt"

	cryptoEx "github.com/lylib/go-crypto"
)

func main() {
	AES_Demo()
	DES_Demo()
}

func AES_Demo() {
	fmt.Println("AES Demo")
	content := []byte("Online project hosting using Git. ")

	key := []byte("X7WBOELqgn6dc8CN")    // 16 byte
	vector := []byte("7vcUPpqeblkHO0Qx") // 16 byte

	aes := cryptoEx.NewAESCrypto(&cryptoEx.CryptoData{
		Mode:    &cryptoEx.ECBMode{},
		Padding: &cryptoEx.PKCS5Padding{},
		Format:  &cryptoEx.HexFormat{},
	})
	encryptStr, _ := aes.Encrypt(content, key, vector)
	decryptStr, _ := aes.Decrypt([]byte(encryptStr), key, vector)
	fmt.Println(encryptStr)
	fmt.Println(decryptStr)
}

func DES_Demo() {
	fmt.Println("DES_Demo")
	content := []byte("Online project hosting using Git. ")

	key := []byte("Lyp5NVOq")    // 8 byte
	vector := []byte("oW7nlMbS") // 8 byte

	des := cryptoEx.NewDESCrypto(&cryptoEx.CryptoData{
		Mode:    &cryptoEx.OFBMode{},
		Padding: &cryptoEx.ZeroPadding{},
		Format:  &cryptoEx.Base64Format{},
	})
	encryptStr, _ := des.Encrypt(content, key, vector)
	decryptStr, _ := des.Decrypt([]byte(encryptStr), key, vector)
	fmt.Println(encryptStr)
	fmt.Println(decryptStr)
}

go-crypto's People

Contributors

lybox avatar

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.