Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
b3a3fdf9
Commit
b3a3fdf9
authored
Apr 08, 2015
by
Bas van Kervel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for import/export hex encoded keys, closes #635
parent
6284604b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
5 deletions
+16
-5
main.go
cmd/geth/main.go
+1
-2
bytes.go
common/bytes.go
+12
-0
crypto.go
crypto/crypto.go
+3
-3
No files found.
cmd/geth/main.go
View file @
b3a3fdf9
...
@@ -149,8 +149,7 @@ password to file or expose in any other way.
...
@@ -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.
Imports an unencrypted private key from <keyfile> and creates a new account.
Prints the address.
Prints the address.
The keyfile is assumed to contain an unencrypted private key in canonical EC
The keyfile is assumed to contain an unencrypted private key in hexadecimal format.
raw bytes format.
The account is saved in encrypted format, you are prompted for a passphrase.
The account is saved in encrypted format, you are prompted for a passphrase.
...
...
common/bytes.go
View file @
b3a3fdf9
...
@@ -147,6 +147,18 @@ func Hex2Bytes(str string) []byte {
...
@@ -147,6 +147,18 @@ func Hex2Bytes(str string) []byte {
return
h
return
h
}
}
func
HexBytes2Bytes
(
d
[]
byte
)
[]
byte
{
r
:=
make
([]
byte
,
hex
.
DecodedLen
(
len
(
d
)))
hex
.
Decode
(
r
,
d
)
return
r
}
func
Bytes2HexBytes
(
d
[]
byte
)
[]
byte
{
r
:=
make
([]
byte
,
hex
.
EncodedLen
(
len
(
d
)))
hex
.
Encode
(
r
,
d
)
return
r
}
func
StringToByteFunc
(
str
string
,
cb
func
(
str
string
)
[]
byte
)
(
ret
[]
byte
)
{
func
StringToByteFunc
(
str
string
,
cb
func
(
str
string
)
[]
byte
)
(
ret
[]
byte
)
{
if
len
(
str
)
>
1
&&
str
[
0
:
2
]
==
"0x"
&&
!
strings
.
Contains
(
str
,
"
\n
"
)
{
if
len
(
str
)
>
1
&&
str
[
0
:
2
]
==
"0x"
&&
!
strings
.
Contains
(
str
,
"
\n
"
)
{
ret
=
Hex2Bytes
(
str
[
2
:
])
ret
=
Hex2Bytes
(
str
[
2
:
])
...
...
crypto/crypto.go
View file @
b3a3fdf9
...
@@ -121,7 +121,7 @@ func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error) {
...
@@ -121,7 +121,7 @@ func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error) {
// LoadECDSA loads a secp256k1 private key from the given file.
// LoadECDSA loads a secp256k1 private key from the given file.
func
LoadECDSA
(
file
string
)
(
*
ecdsa
.
PrivateKey
,
error
)
{
func
LoadECDSA
(
file
string
)
(
*
ecdsa
.
PrivateKey
,
error
)
{
buf
:=
make
([]
byte
,
32
)
buf
:=
make
([]
byte
,
64
)
fd
,
err
:=
os
.
Open
(
file
)
fd
,
err
:=
os
.
Open
(
file
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -130,13 +130,13 @@ func LoadECDSA(file string) (*ecdsa.PrivateKey, error) {
...
@@ -130,13 +130,13 @@ func LoadECDSA(file string) (*ecdsa.PrivateKey, error) {
if
_
,
err
:=
io
.
ReadFull
(
fd
,
buf
);
err
!=
nil
{
if
_
,
err
:=
io
.
ReadFull
(
fd
,
buf
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
ToECDSA
(
buf
),
nil
return
ToECDSA
(
common
.
HexBytes2Bytes
(
buf
)
),
nil
}
}
// SaveECDSA saves a secp256k1 private key to the given file with restrictive
// SaveECDSA saves a secp256k1 private key to the given file with restrictive
// permissions
// permissions
func
SaveECDSA
(
file
string
,
key
*
ecdsa
.
PrivateKey
)
error
{
func
SaveECDSA
(
file
string
,
key
*
ecdsa
.
PrivateKey
)
error
{
return
ioutil
.
WriteFile
(
file
,
FromECDSA
(
key
),
0600
)
return
ioutil
.
WriteFile
(
file
,
common
.
Bytes2HexBytes
(
FromECDSA
(
key
)
),
0600
)
}
}
func
GenerateKey
()
(
*
ecdsa
.
PrivateKey
,
error
)
{
func
GenerateKey
()
(
*
ecdsa
.
PrivateKey
,
error
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment