mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 08:32:40 +08:00
加密算法
This commit is contained in:
@ -3,6 +3,7 @@ package crypto
|
||||
import (
|
||||
"crypto"
|
||||
"crypto/ecdsa"
|
||||
"crypto/rand"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"errors"
|
||||
@ -10,6 +11,8 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// var _ Signer = &ecdsaOptions{}
|
||||
|
||||
type ecdsaOptions struct {
|
||||
hashOptions
|
||||
prv *ecdsa.PrivateKey
|
||||
@ -89,12 +92,16 @@ func ParsePublicKey(pem []byte) Option {
|
||||
return publicKeyOption(pem)
|
||||
}
|
||||
|
||||
func (opt *ecdsaOptions) Sign(msg []byte) ([]byte, error) {
|
||||
sum := opt.getHash(msg)
|
||||
return ecdsa.SignASN1(rand.Reader, opt.prv, sum)
|
||||
}
|
||||
|
||||
func (opt *ecdsaOptions) Verify(msg, rText, sText []byte) bool {
|
||||
var r, s big.Int
|
||||
_ = r.UnmarshalText(rText)
|
||||
_ = s.UnmarshalText(sText)
|
||||
|
||||
sum := opt.getHash(msg)
|
||||
|
||||
return ecdsa.Verify(opt.pub, sum, &r, &s)
|
||||
}
|
||||
|
Reference in New Issue
Block a user