Sign implements the Sign method from SigningMethod. For this signing method, key must be an *ecdsa.PrivateKey.
(data []byte, key interface{})
| 76 | // Sign implements the Sign method from SigningMethod. |
| 77 | // For this signing method, key must be an *ecdsa.PrivateKey. |
| 78 | func (m *SigningMethodECDSA) Sign(data []byte, key interface{}) (Signature, error) { |
| 79 | |
| 80 | ecdsaKey, ok := key.(*ecdsa.PrivateKey) |
| 81 | if !ok { |
| 82 | return nil, ErrInvalidKey |
| 83 | } |
| 84 | |
| 85 | r, s, err := ecdsa.Sign(rand.Reader, ecdsaKey, m.sum(data)) |
| 86 | if err != nil { |
| 87 | return nil, err |
| 88 | } |
| 89 | |
| 90 | signature, err := asn1.Marshal(ECPoint{R: r, S: s}) |
| 91 | if err != nil { |
| 92 | return nil, err |
| 93 | } |
| 94 | return Signature(signature), nil |
| 95 | } |
| 96 | |
| 97 | func (m *SigningMethodECDSA) sum(b []byte) []byte { |
| 98 | h := m.Hash.New() |