2023-07-09 11:16:52 +00:00
|
|
|
package crypto
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/ecdsa"
|
|
|
|
"crypto/rand"
|
|
|
|
"crypto/sha256"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2023-07-09 15:39:05 +00:00
|
|
|
func (t *JWK) SignRequest(requestID string, timestamp int64) ([]byte, error) {
|
|
|
|
signBytes := sha256.Sum256([]byte(fmt.Sprintf("%s:%d", requestID, timestamp)))
|
2023-07-09 11:16:52 +00:00
|
|
|
|
|
|
|
privKey, privErr := t.GetPrivateKey()
|
|
|
|
if privErr != nil {
|
2023-07-09 15:39:05 +00:00
|
|
|
return nil, privErr
|
2023-07-09 11:16:52 +00:00
|
|
|
}
|
|
|
|
|
2023-07-09 15:39:05 +00:00
|
|
|
return ecdsa.SignASN1(rand.Reader, privKey, signBytes[:])
|
2023-07-09 11:16:52 +00:00
|
|
|
}
|