A 56: AES Encryption in Go (50 pts)

What You Need

A Linux machine with Go installed, which you prepared in a previous project.

Purpose

Encrypt and decrypt files using AES in Go.

AES in Go

On your Linux server, in a Terminal window, execute these commands:
mkdir -p work/src/my_project/aes
nano work/src/my_project/aes/aes.go
In nano, enter this code, as shown below.
package main

import ( "crypto/aes"; "fmt" )

func main() {
    plaintext := []byte("Hi There, World!")
    key := []byte("1234567812345678")
    cipher, _ := aes.NewCipher(key)

    ciphertext := make([]byte, 16)
    cipher.Encrypt(ciphertext, plaintext)
    fmt.Printf("Ciphertext: %x\n", ciphertext)

    decrypted := []byte("----------------")
    cipher.Decrypt(decrypted, ciphertext)
    fmt.Printf("Decrypted: %s\n", decrypted)
}
Save the file with Ctrl+X, Y, Enter.

Execute these commands to compile the program and run it:

go install my_project/aes
aes
The program runs, printing out the encrypted ciphertext and the decrypted string, as shown below.


A 56.1: Encrypting Text With the Key (5 pts)

Encrypt this text:
100 RED BALLOONS
With this key:
WWWWXXXXYYYYZZZZ
The flag is the ciphertext in hexadecimal notation.


A 56.2: Decrypting Ciphertext With the Key (10 pts)

Decrypt this ciphertext:
ab520094713cdf6bcd3ba5c82ce7f922
With this key:
SUPER_SECRET_KEY
The flag is the plaintext.

Hint: How to transfer hex strings to []byte directly in Go?


A 56.3: Decrypting Long Ciphertext With the Key (15 pts)

Decrypt this ciphertext:
e9aed443f53e8fdf827017838c33238984c7f7e171aff95c
2c74c08ce79ce58114a08d334b2491fbed64bed452d0e179
81be2fca01f11905c653f1bc6a73d321248e75bdc4eb96f4
3b50613a309377fb0443d78902b105ec57d3d03d4dac342d
0d52eacef350673a0e2e1ef32bf2352f4413489e48a4f9ae
495b2838e4dd23a0
With this key:
SIXTEEN_LETTERS!
The flag is found at the end of the plaintext.

Hint: you need to decrypt each 16-byte block separately, as shown here:

Golang AES ECB Encryption


A 56.4: Decrypting an Image With the Key (20 pts)

Decrypt this file:

A56.4.png.enc

With this key:

Sixteen_Letters!
The flag is readable in the decrypted image.


Sources

Go Encryption and Decryption using AES - Tutorial
Package aes


Posted: 2-21-2020