Skip to content

Instantly share code, notes, and snippets.

@smagch
Last active August 29, 2015 13:59
Show Gist options
  • Select an option

  • Save smagch/10665698 to your computer and use it in GitHub Desktop.

Select an option

Save smagch/10665698 to your computer and use it in GitHub Desktop.
(date + sha224) byte array
package main
// http://play.golang.org/p/F3XbXbmAgr
import (
"fmt"
"encoding/binary"
"crypto/sha256"
"io"
"time"
)
func GetByteId() []byte {
h := sha256.New224()
io.WriteString(h, "foobar")
return h.Sum(nil)
}
func main() {
// 32 = 4 + 28 = (date) + (sha224)
u := [32]byte{}
// time by int32
t := time.Now()
n := t.Day() + int(t.Month()) * 32 + t.Year() * 32 * 16
// sha224
b := GetByteId()
// write time as uint32
// the first entry should be 0
binary.BigEndian.PutUint32(u[0:], uint32(n))
copy(u[4:], b)
fmt.Println(u)
fmt.Println(b)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment