ecb

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

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

Go to latest
Published: Aug 15, 2018 License: MIT Imports: 4 Imported by: 1

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AesDecrypt

func AesDecrypt(src, key []byte) ([]byte, error)

Aes/ECB模式的解密方法,PKCS7填充方式

func AesEncrypt

func AesEncrypt(src, key []byte) ([]byte, error)

Aes/ECB模式的加密方法,PKCS7填充方式

func NewECBDecrypter

func NewECBDecrypter(b cipher.Block) cipher.BlockMode

func NewECBEncrypter

func NewECBEncrypter(b cipher.Block) cipher.BlockMode

func PKCS7Padding

func PKCS7Padding(ciphertext []byte, blockSize int) []byte

PKCS7填充

func PKCS7UnPadding

func PKCS7UnPadding(ciphertext []byte) []byte

PKCS7去除

func ZerosPadding

func ZerosPadding(ciphertext []byte, blockSize int) []byte

零点填充

func ZerosUnPadding

func ZerosUnPadding(ciphertext []byte) []byte

零点去除

Types

This section is empty.

Jump to

Keyboard shortcuts

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