Logging a ASN.1 DER encoded form produces unreadable characters in terminal

go
terminal

#1

I was using Go to do some RSA stuff, and I logged a ASN.1 DER encoded form out, and the console didn’t like it…

Replicate with the following Go code:

package main

import (
    "crypto/rsa"
    "crypto/x509"
    "crypto/rand"
    "fmt"
)

func main () {
    
    privKey, err := rsa.GenerateKey(rand.Reader, 512)
    fmt.Println(string(x509.MarshalPKCS1PrivateKey(privKey)))
}

The text in my console:

└┼≥├:·/┬⎺⎼┐⎽⎻▒ce $ ±⎺ ⎼┤┼ ▒⎼±┤└e┼├⎽↓±⎺ ^C
└┼≥├:·/┬⎺⎼┐⎽⎻▒ce $ ^C
└┼≥├:·/┬⎺⎼┐⎽⎻▒ce $ ^C
└┼≥├:·/┬⎺⎼┐⎽⎻▒ce $ ┌└▒⎺ ⎼☃⎻
b▒⎽▒: ┌└▒⎺: c⎺└└▒┼d ┼⎺├ °⎺┤┼d
└┼≥├:·/┬⎺⎼┐⎽⎻▒ce $ 

Pretty fun stuff!


#2

Discovered a lost language you have.

Help you I cannot.

:older_man: :question:
:mag_right: :accept:


#3

I am the chosen one.


#4

A lifelong adventure of cryptographer awaits you it does.

:man_with_turban:


#5

Dumping binary data into your terminal will spawn cthulhu :octopus:.

$ reset will fix it.

Do take note that this is not cloud9 specific. $ cat simply dumps the data in the file to it’s standard output ( your terminal when you’re not piping the output to something), including control characters which are causing this behavior…