experiments

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

shabase64.go (474B)


      1 package main
      2 
      3 import (
      4 	"crypto/sha256"
      5 	"encoding/base64"
      6 	"fmt"
      7 	"os"
      8 )
      9 
     10 // Takes a string as input and returns an URL-safe base64 encoded SHA224 sum
     11 func main() {
     12 	in := os.Args[1]
     13 	sum := sha256.Sum224([]byte(in))
     14 	// Unreserved characters: https://tools.ietf.org/html/rfc3986#section-2.3
     15 	b64enc := base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.").WithPadding('-')
     16 	encoded := b64enc.EncodeToString(sum[:])
     17 	fmt.Println(encoded)
     18 }