aes-256-cfb

command
v0.0.0-...-a2a1f02 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2020 License: MIT Imports: 7 Imported by: 0

README

aes-256-cfb example

AES-256 CFB (Cipher FeedBack) mode is almost identical to CBC mode but performed in reverse.

I have the following AES-256 mode examples,

GitHub Webpage

RUN

run aes-cfb.go

You output should be,

Original Text:           This is AES-256 CFB!!

The 32-byte Key:         myverystrongpasswordo32bitlength
The Nonce:               3f267a60bf96b424fa144da8fc4869d4

Encrypted Text:          6a2544cec434601d000afd43d7a1d9edd18f68320a
Decrypted Text:          This is AES-256 CFB!!

HOW IT WORKS

  • Makes a block cipher into a self-synchronizing stream cipher
  • CFB decryption is almost identical to CBC encryption performed in reverse
  • The IV value should be equal to AES block size
  • A different nonce is needed for every message
  • Encryption but not message integrity

For simplicity I did not include the nonce in the cipherText.

Encryption,

// GET CIPHER BLOCK USING KEY
block, err := aes.NewCipher(keyByte)

// GET CFB ENCRYPTER
cfb := cipher.NewCFBEncrypter(block, nonce)

// ENCRYPT DATA
cfb.XORKeyStream(cipherTextByte, plaintextByte)

// RETURN HEX
cipherText := hex.EncodeToString(cipherTextByte)

Decryption,

// GET CIPHER BLOCK USING KEY
block, err := aes.NewCipher(keyByte)

// GET CFB DECRYPTER
cfb := cipher.NewCFBDecrypter(block, nonce)

// DECRYPT DATA
cfb.XORKeyStream(plainTextByte, cipherTextByte)

// RETURN STRING
plainText := string(plainTextByte[:])

This illustration may help,

IMAGE - aes-cfb - IMAGE

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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