ecb

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2024 License: MIT Imports: 3 Imported by: 0

README

ECB encryption and decryption in Go

ECB mode has security vulnerabilities and is not recommended for use, so the Go standard library does not include ECB by default.

  • The padding mode used by this library is PKCS7Padding.

Encryption Example

package main

import (
	"encoding/base64"
	"fmt"
	"github.com/guidoxie/ecb"
)

func main() {
	key := []byte("1234567890123456")
	encrypter, err := ecb.NewEncrypter(key)
	if err != nil {
		panic(err)
	}
	plaintext := []byte("hello")            
	cipherText := encrypter.Encrypt(plaintext) 
	// Output: 67fHA+Z12z2jlwOLTBeCPA==
	fmt.Println(base64.StdEncoding.EncodeToString(cipherText))
}

Decryption Example

package main

import (
	"encoding/base64"
	"fmt"
	"github.com/guidoxie/ecb"
)

func main() {
	key := []byte("1234567890123456")
	decrypter, err := ecb.NewDecrypter(key)
	if err != nil {
		panic(err)
	}
	cipherText, err := base64.StdEncoding.DecodeString("67fHA+Z12z2jlwOLTBeCPA==") 
	if err != nil {
		panic(err)
	}
	plaintext := decrypter.Decrypt(cipherText) 
	// Output: hello
	fmt.Println(string(plaintext))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDecrypter

func NewDecrypter(key []byte) (*decrypter, error)

NewEncrypter Creating a decryptor for ECB mode

func NewEncrypter

func NewEncrypter(key []byte) (*encrypter, error)

NewEncrypter Creating an ECB mode encryptor

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳