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
This commit is contained in:
nemunaire 2018-02-20 15:07:00 +01:00 committed by Pierre-Olivier Mercier
parent fa45457bb7
commit b51b1e010a
2 changed files with 20 additions and 0 deletions

1
hmac-generator/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
hmac-generator

19
hmac-generator/main.go Normal file
View File

@ -0,0 +1,19 @@
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)))))
}