(Golang) Base64 by Thomas Roccia

Created the Saturday 12 September 2020. Updated 1 year, 4 months ago.

Description:

This Go program uses the Base64 encoding scheme to encode and decode a string. The program takes a single command line argument, which is the string to be encoded and decoded. The program first uses the base64 package to encode the string using the Standard encoding alphabet. The encoded string is then printed to the screen. The program then decodes the encoded string using the same alphabet, and prints the resulting decoded string to the screen. This example demonstrates how the Base64 encoding scheme can be used to encode and decode binary data in a compact and easily transmitted format. In the context of malware, this technique can be used to conceal payloads or encode network communication in order to avoid detection and analysis.

Code

            package main

import (
    "encoding/base64"
    "fmt"
    "os"
)

func main() {

    arg1 := os.Args[1]

    encoded := base64.StdEncoding.EncodeToString([]byte(arg1))
    fmt.Println(encoded)

    decoded, err := base64.StdEncoding.DecodeString(encoded)
    if err != nil {
        panic("error")
    }
    fmt.Println(string(decoded))
}