aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-04-09 17:31:44 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-04-09 17:31:44 +0800
commit558683d10cb059a55b181d94d82c2c7292f96680 (patch)
tree54d6af8801184d96987a0f4c83161220544f1338
parent79cc3cc98e0c2622612de242b95da60218cca20a (diff)
parentef393da9334adcf99187c0825df025596ae41fb3 (diff)
downloaddexon-558683d10cb059a55b181d94d82c2c7292f96680.tar
dexon-558683d10cb059a55b181d94d82c2c7292f96680.tar.gz
dexon-558683d10cb059a55b181d94d82c2c7292f96680.tar.bz2
dexon-558683d10cb059a55b181d94d82c2c7292f96680.tar.lz
dexon-558683d10cb059a55b181d94d82c2c7292f96680.tar.xz
dexon-558683d10cb059a55b181d94d82c2c7292f96680.tar.zst
dexon-558683d10cb059a55b181d94d82c2c7292f96680.zip
Merge pull request #678 from bas-vk/feature_635
Support for import/export hex encoded keys
-rw-r--r--cmd/geth/main.go3
-rw-r--r--crypto/crypto.go13
2 files changed, 11 insertions, 5 deletions
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index 9437f8eb4..02964dadf 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -149,8 +149,7 @@ password to file or expose in any other way.
Imports an unencrypted private key from <keyfile> and creates a new account.
Prints the address.
-The keyfile is assumed to contain an unencrypted private key in canonical EC
-raw bytes format.
+The keyfile is assumed to contain an unencrypted private key in hexadecimal format.
The account is saved in encrypted format, you are prompted for a passphrase.
diff --git a/crypto/crypto.go b/crypto/crypto.go
index 7d1d51fa6..9865c87c4 100644
--- a/crypto/crypto.go
+++ b/crypto/crypto.go
@@ -121,7 +121,7 @@ func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error) {
// LoadECDSA loads a secp256k1 private key from the given file.
func LoadECDSA(file string) (*ecdsa.PrivateKey, error) {
- buf := make([]byte, 32)
+ buf := make([]byte, 64)
fd, err := os.Open(file)
if err != nil {
return nil, err
@@ -130,13 +130,20 @@ func LoadECDSA(file string) (*ecdsa.PrivateKey, error) {
if _, err := io.ReadFull(fd, buf); err != nil {
return nil, err
}
- return ToECDSA(buf), nil
+
+ key, err := hex.DecodeString(string(buf))
+ if err != nil {
+ return nil, err
+ }
+
+ return ToECDSA(key), nil
}
// SaveECDSA saves a secp256k1 private key to the given file with restrictive
// permissions
func SaveECDSA(file string, key *ecdsa.PrivateKey) error {
- return ioutil.WriteFile(file, FromECDSA(key), 0600)
+ k := hex.EncodeToString(FromECDSA(key))
+ return ioutil.WriteFile(file, []byte(k), 0600)
}
func GenerateKey() (*ecdsa.PrivateKey, error) {