Last active
August 29, 2015 13:59
-
-
Save smagch/10665698 to your computer and use it in GitHub Desktop.
(date + sha224) byte array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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