Skip to content

haowanxing/go-aes-ecb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go-AES-ECB

Build Status

A Simple Go Encryptor/Decryptor For AES-ECB Mode. With PKCS5 & Zeros (Un)Padding.

Usage

package main

import (
	"fmt"
	ecb "github.com/haowanxing/go-aes-ecb"
)

func main() {
	content := "hello"
	key := "0123456789abcdef"

	// 使用PKCS#7对原文进行填充,BlockSize为16字节
	ciphertext := ecb.PKCS7Padding([]byte(content), 16)

	crypted, err := ecb.AesEncrypt(ciphertext, []byte(key)) //ECB加密
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println("crypted: ", crypted, string(crypted))

	origin, err := ecb.AesDecrypt(crypted, []byte(key)) // ECB解密
	if err != nil {
		fmt.Println(err)
		return
	}
	// 使用PKCS#7对解密后的内容去除填充
	origin = ecb.PKCS7UnPadding(origin)
	fmt.Println("decrypted: ", origin, string(origin))
}

Result:

crypted:  [103 76 126 243 142 120 202 189 156 236 156 18 88 35 166 57] gL~?xʽ??X#?9
decrypted:  [104 101 108 108 111] hello

About

A Simple Go Encryptor/Decryptor For AES-ECB Mode

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages