Documentation ¶
Overview ¶
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GeneratePrivateKey ¶
func GeneratePrivateKey(keystorePath string) (*sm2.PrivateKey, error)
GeneratePrivateKey creates an EC private key using a P-256 curve and stores it in keystorePath. func GeneratePrivateKey(keystorePath string) (*ecdsa.PrivateKey, error) {
priv, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) if err != nil { return nil, errors.WithMessage(err, "failed to generate private key") } pkcs8Encoded, err := x509.MarshalPKCS8PrivateKey(priv) if err != nil { return nil, errors.WithMessage(err, "failed to marshal private key") } pemEncoded := pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: pkcs8Encoded}) keyFile := filepath.Join(keystorePath, "priv_sk") err = ioutil.WriteFile(keyFile, pemEncoded, 0600) if err != nil { return nil, errors.WithMessagef(err, "failed to save private key to file %s", keyFile) } return priv, err }
TODO SM2
func LoadPrivateKey ¶
func LoadPrivateKey(keystorePath string) (*sm2.PrivateKey, error)
LoadPrivateKey loads a private key from a file in keystorePath. It looks for a file ending in "_sk" and expects a PEM-encoded PKCS8 EC private key.
Types ¶
type ECDSASignature ¶
type ECDSASigner ¶
type ECDSASigner struct {
PrivateKey *ecdsa.PrivateKey
}
* ECDSA signer implements the crypto.Signer interface for ECDSA keys. The Sign method ensures signatures are created with Low S values since Fabric normalizes all signatures to Low S. See https://github.com/bitcoin/bips/blob/master/bip-0146.mediawiki#low_s for more detail.
func (*ECDSASigner) Public ¶
func (e *ECDSASigner) Public() crypto.PublicKey
Public returns the ecdsa.PublicKey associated with PrivateKey.
func (*ECDSASigner) Sign ¶
func (e *ECDSASigner) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error)
Sign signs the digest and ensures that signatures use the Low S value.