Function to get private key from ASN.1 serialized structure (#109)

* func to get privkey from raw bytes

* comments fix

* review fixes; version

* version
This commit is contained in:
Anastasia Prasolova 2018-12-05 22:04:31 +03:00 committed by Anthony De Meulemeester
parent 5b57a10250
commit fa1da2cb91
2 changed files with 11 additions and 1 deletions

View file

@ -1 +1 @@
0.45.12
0.45.14

View file

@ -6,6 +6,7 @@ import (
"crypto/elliptic"
"crypto/rand"
"crypto/sha256"
"crypto/x509"
"encoding/hex"
"errors"
"fmt"
@ -57,6 +58,15 @@ func NewPrivateKeyFromBytes(b []byte) (*PrivateKey, error) {
return &PrivateKey{b}, nil
}
// NewPrivateKeyFromRawBytes returns a NEO PrivateKey from the ASN.1 serialized keys.
func NewPrivateKeyFromRawBytes(b []byte) (*PrivateKey, error) {
privkey, err := x509.ParseECPrivateKey(b)
if err != nil {
return nil, err
}
return NewPrivateKeyFromBytes(privkey.D.Bytes())
}
// PublicKey derives the public key from the private key.
func (p *PrivateKey) PublicKey() ([]byte, error) {
var (