ecb

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: BSD-3-Clause Imports: 1 Imported by: 38

Documentation

Overview

Package ecb implements block cipher mode of encryption ECB (Electronic Code Book) functions. This is implemented for legacy purposes only and should not be used for any new encryption needs. Use CBC (Cipher Block Chaining) instead.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewECBDecrypter

func NewECBDecrypter(b cipher.Block) cipher.BlockMode

NewECBDecrypter returns a BlockMode which decrypts in electronic codebook (ECB) mode, using the given Block.

Example
key := []byte("SomeBlowfishKey")
ciphertext, err := hex.DecodeString("66E6E737F23E570ACA5710BA3C0E321A")
if err != nil {
	panic(err.Error())
}
block, err := blowfish.NewCipher(key)
if err != nil {
	panic(err.Error())
}
mode := NewECBDecrypter(block)
plaintext := make([]byte, len(ciphertext))
mode.CryptBlocks(plaintext, ciphertext)
fmt.Printf("%s\n", string(plaintext))
Output:

exampleplaintext
Example (Second)
key := []byte("AES256Key-32Characters1234567890")
ciphertext, err := hex.DecodeString("717FADE7B97198A8C2F67766FBAC7B07")
if err != nil {
	panic(err.Error())
}
block, err := aes.NewCipher(key)
if err != nil {
	panic(err.Error())
}
mode := NewECBDecrypter(block)
plaintext := make([]byte, len(ciphertext))
mode.CryptBlocks(plaintext, ciphertext)
fmt.Printf("%s\n", string(plaintext))
Output:

exampleplaintext

func NewECBEncrypter

func NewECBEncrypter(b cipher.Block) cipher.BlockMode

NewECBEncrypter returns a BlockMode which encrypts in elecronic codebook (ECB) mode, using the given Block (Cipher).

Example
key := []byte("SomeBlowfishKey")
plaintext := []byte("exampleplaintext")
block, err := blowfish.NewCipher(key)
if err != nil {
	panic(err.Error())
}
mode := NewECBEncrypter(block)
ciphertext := make([]byte, len(plaintext))
mode.CryptBlocks(ciphertext, plaintext)
fmt.Printf("%X\n", ciphertext)
Output:

66E6E737F23E570ACA5710BA3C0E321A
Example (Second)
key := []byte("AES256Key-32Characters1234567890")
plaintext := []byte("exampleplaintext")
block, err := aes.NewCipher(key)
if err != nil {
	panic(err.Error())
}
mode := NewECBEncrypter(block)
ciphertext := make([]byte, len(plaintext))
mode.CryptBlocks(ciphertext, plaintext)
fmt.Printf("%X\n", ciphertext)
Output:

717FADE7B97198A8C2F67766FBAC7B07

Types

This section is empty.

Jump to

Keyboard shortcuts

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