Base64 in Go: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 4: Line 4:


=Overview=
=Overview=
=Decoding=
<syntaxhighlight lang='go'>
<syntaxhighlight lang='go'>
l, _ := base64.StdEncoding.Decode(base64Text, []byte(message))
base64EncodedStr := "..."
 
data, err := base64.StdEncoding.DecodeString(base64EncodedStr)
 
if err != nil {
func base64Encode(str string) string {
     ...
    return base64.StdEncoding.EncodeToString([]byte(str))
}
 
func base64Decode(str string) (string, bool) {
    data, err := base64.StdEncoding.DecodeString(str)
    if err != nil {
        return "", true
     }
    return string(data), false
}
}
s := string(data)
</syntaxhighlight>
=Encoding=
<syntaxhighlight lang='go'>
base64EncodedStr := base64.StdEncoding.EncodeToString([]byte(str))
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 01:53, 13 March 2024

Internal

Overview

Decoding

base64EncodedStr := "..."
data, err := base64.StdEncoding.DecodeString(base64EncodedStr)
if err != nil {
    ...
}
s := string(data)

Encoding

base64EncodedStr := base64.StdEncoding.EncodeToString([]byte(str))