first commit
This commit is contained in:
No files matched your search
+11
-16
@@ -4,7 +4,6 @@ import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
@@ -112,24 +111,20 @@ type SatuSehatConfig struct {
|
||||
// return cfg.ConsID, cfg.SecretKey, cfg.UserKey, fmt.Sprint(tstamp), xSignature
|
||||
// }
|
||||
func (cfg BpjsConfig) SetHeader() (string, string, string, string, string) {
|
||||
timenow := time.Now().UTC()
|
||||
t, err := time.Parse(time.RFC3339, "1970-01-01T00:00:00Z")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
tstamp := time.Now().Unix()
|
||||
message := strings.TrimSpace(cfg.ConsID) + "&" + fmt.Sprint(tstamp)
|
||||
|
||||
tstamp := timenow.Unix() - t.Unix()
|
||||
secret := []byte(cfg.SecretKey)
|
||||
message := []byte(cfg.ConsID + "&" + fmt.Sprint(tstamp))
|
||||
hash := hmac.New(sha256.New, secret)
|
||||
hash.Write(message)
|
||||
mac := hmac.New(sha256.New, []byte(strings.TrimSpace(cfg.SecretKey)))
|
||||
mac.Write([]byte(message))
|
||||
|
||||
// to lowercase hexits
|
||||
hex.EncodeToString(hash.Sum(nil))
|
||||
// to base64
|
||||
xSignature := base64.StdEncoding.EncodeToString(hash.Sum(nil))
|
||||
// BENAR: langsung base64 dari raw bytes (bukan hex dulu)
|
||||
xSignature := base64.StdEncoding.EncodeToString(mac.Sum(nil))
|
||||
|
||||
return cfg.ConsID, cfg.SecretKey, cfg.UserKey, fmt.Sprint(tstamp), xSignature
|
||||
return strings.TrimSpace(cfg.ConsID),
|
||||
strings.TrimSpace(cfg.SecretKey),
|
||||
strings.TrimSpace(cfg.UserKey),
|
||||
fmt.Sprint(tstamp),
|
||||
xSignature
|
||||
}
|
||||
|
||||
type ConfigBpjs struct {
|
||||
|
||||
Reference in New Issue
Block a user