ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
# package ecdsa `import "crypto/ecdsa"` ecdsa包实现了椭圆曲线数字签名算法,参见FIPS 186-3。 ## Index * [type PublicKey](#PublicKey) * [type PrivateKey](#PrivateKey) * [func GenerateKey(c elliptic.Curve, rand io.Reader) (priv \*PrivateKey, err error)](#GenerateKey) * [func Sign(rand io.Reader, priv \*PrivateKey, hash []byte) (r, s \*big.Int, err error)](#Sign) * [func Verify(pub \*PublicKey, hash []byte, r, s \*big.Int) bool](#Verify) ## type [PublicKey](https://github.com/golang/go/blob/master/src/crypto/ecdsa/ecdsa.go#L22 "View Source") ``` type PublicKey struct { elliptic.Curve X, Y *big.Int } ``` PrivateKey代表一个ECDSA公钥。 ## type [PrivateKey](https://github.com/golang/go/blob/master/src/crypto/ecdsa/ecdsa.go#L28 "View Source") ``` type PrivateKey struct { PublicKey D *big.Int } ``` PrivateKey代表一个ECDSA私钥。 ### func [GenerateKey](https://github.com/golang/go/blob/master/src/crypto/ecdsa/ecdsa.go#L53 "View Source") GenerateKey函数生成一对 ``` func GenerateKey(c elliptic.Curve, rand io.Reader) (priv *PrivateKey, err error) ``` 公钥/私钥。 ## func [Sign](https://github.com/golang/go/blob/master/src/crypto/ecdsa/ecdsa.go#L101 "View Source") ``` func Sign(rand io.Reader, priv *PrivateKey, hash []byte) (r, s *big.Int, err error) ``` 使用私钥对任意长度的hash值(必须是较大信息的hash结果)进行签名,返回签名结果(一对大整数)。私钥的安全性取决于密码读取器的熵度(随机程度)。 ## func [Verify](https://github.com/golang/go/blob/master/src/crypto/ecdsa/ecdsa.go#L138 "View Source") ``` func Verify(pub *PublicKey, hash []byte, r, s *big.Int) bool ``` 使用公钥验证hash值和两个大整数r、s构成的签名,并返回签名是否合法。