experiments

All kinds of coding experiments
Log | Files | Refs | Submodules

commit d2d782f43d34656fedafb1a4678921c1373859ea
parent 468408fcf170be76d7c80ffc0d1af54ce12f15f1
Author: Vetle Haflan <vetle@haflan.dev>
Date:   Thu, 28 Jan 2021 00:31:26 +0100

Add go directory with an encoding experiment

Diffstat:
Ago/encoding/shabase64.go | 18++++++++++++++++++
1 file changed, 18 insertions(+), 0 deletions(-)

diff --git a/go/encoding/shabase64.go b/go/encoding/shabase64.go @@ -0,0 +1,18 @@ +package main + +import ( + "crypto/sha256" + "encoding/base64" + "fmt" + "os" +) + +// Takes a string as input and returns an URL-safe base64 encoded SHA224 sum +func main() { + in := os.Args[1] + sum := sha256.Sum224([]byte(in)) + // Unreserved characters: https://tools.ietf.org/html/rfc3986#section-2.3 + b64enc := base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.").WithPadding('-') + encoded := b64enc.EncodeToString(sum[:]) + fmt.Println(encoded) +}