package main
import (
"encoding/base64";
"io";
"os";
)
func main() {
e := base64.NewEncoder(base64.StdEncoding, os.Stdout)
io.Copy(e, os.Stdin)
e.Close()
}
all about go, ruby, python, perl, java, scala, osgi, RCP computing, network, hacking, security, encryption. and other interesting stuff
Posts mit dem Label base64 werden angezeigt. Alle Posts anzeigen
Posts mit dem Label base64 werden angezeigt. Alle Posts anzeigen
Freitag, 26. November 2010
GO BASE64: small stdin to stdout copy
Freitag, 27. November 2009
base64 in golang
package main
import (
"encoding/base64";
"bytes";
"fmt";
)
func main() {
// create the buffer
bb := &bytes.Buffer{};
bbURL := &bytes.Buffer{};
// create two base64 encoder (standard and for url)
encoder := base64.NewEncoder(base64.StdEncoding, bb);
encoderURL := base64.NewEncoder(base64.URLEncoding, bbURL);
data := "hallo this is a test, a=23&var2=blabla+-?!%$/\\";
fmt.Println("data : ", data);
// to encode data, use Write([]bytes),
// therefore you must convert string to bytes
// with string.Bytes(d string)
encoder.Write([]byte(data));
encoder.Close();
encoderURL.Write([]byte(data));
encoderURL.Close();
// voila
fmt.Println("encoded Std: ", bb.String());
fmt.Println("encoded URL: ", bbURL.String());
}
Abonnieren
Kommentare (Atom)