This repository has been archived on 2024-03-03. You can view files and clone it, but cannot push or open issues or pull requests.
adlin/hmac-generator/main.go
nemunaire b51b1e010a hmac-generator: new program, to be able to test with curl
42sh$ echo toto | curl -d @- -H "X-ADLIN-Authentication: $(hmac-generator secret)" https://adlin.nemunai.re/api/secret
2019-02-22 01:45:13 +01:00

20 lines
341 B
Go

package main
import (
"crypto/hmac"
"crypto/sha512"
"encoding/base64"
"fmt"
"os"
"time"
)
func main() {
sharedSecret := "adelina"
if len(os.Args) > 1 {
sharedSecret = os.Args[1]
}
fmt.Println(base64.StdEncoding.EncodeToString(hmac.New(sha512.New, []byte(sharedSecret)).Sum([]byte(fmt.Sprintf("%d", time.Now().Unix()/10)))))
}