Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
burrow
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hang Yu
burrow
Commits
3100e5d4
Commit
3100e5d4
authored
6 years ago
by
Sean Young
Browse files
Options
Downloads
Patches
Plain Diff
key json should store keys bytes in hex
Signed-off-by:
Sean Young
<
sean.young@monax.io
>
parent
8570cbcb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
keys/key_store.go
+17
-9
17 additions, 9 deletions
keys/key_store.go
with
17 additions
and
9 deletions
keys/key_store.go
+
17
−
9
View file @
3100e5d4
...
@@ -39,14 +39,14 @@ const (
...
@@ -39,14 +39,14 @@ const (
type
keyJSON
struct
{
type
keyJSON
struct
{
CurveType
string
CurveType
string
Address
string
Address
string
PublicKey
[]
byte
PublicKey
string
AddressHash
string
AddressHash
string
PrivateKey
privateKeyJSON
PrivateKey
privateKeyJSON
}
}
type
privateKeyJSON
struct
{
type
privateKeyJSON
struct
{
Crypto
string
Crypto
string
Plain
[]
byte
`json:",omitempty"`
Plain
string
`json:",omitempty"`
Salt
[]
byte
`json:",omitempty"`
Salt
[]
byte
`json:",omitempty"`
Nonce
[]
byte
`json:",omitempty"`
Nonce
[]
byte
`json:",omitempty"`
CipherText
[]
byte
`json:",omitempty"`
CipherText
[]
byte
`json:",omitempty"`
...
@@ -55,10 +55,10 @@ type privateKeyJSON struct {
...
@@ -55,10 +55,10 @@ type privateKeyJSON struct {
func
(
k
*
Key
)
MarshalJSON
()
(
j
[]
byte
,
err
error
)
{
func
(
k
*
Key
)
MarshalJSON
()
(
j
[]
byte
,
err
error
)
{
jStruct
:=
keyJSON
{
jStruct
:=
keyJSON
{
CurveType
:
k
.
CurveType
.
String
(),
CurveType
:
k
.
CurveType
.
String
(),
Address
:
hex
.
EncodeToString
(
k
.
Address
[
:
]),
Address
:
hex
.
Encode
Upper
ToString
(
k
.
Address
[
:
]),
PublicKey
:
k
.
Pubkey
(),
PublicKey
:
hex
.
EncodeUpperToString
(
k
.
Pubkey
()
)
,
AddressHash
:
k
.
PublicKey
.
AddressHashType
(),
AddressHash
:
k
.
PublicKey
.
AddressHashType
(),
PrivateKey
:
privateKeyJSON
{
Crypto
:
CryptoNone
,
Plain
:
k
.
PrivateKey
.
RawBytes
()},
PrivateKey
:
privateKeyJSON
{
Crypto
:
CryptoNone
,
Plain
:
hex
.
EncodeUpperToString
(
k
.
PrivateKey
.
RawBytes
()
)
},
}
}
j
,
err
=
json
.
Marshal
(
jStruct
)
j
,
err
=
json
.
Marshal
(
jStruct
)
return
j
,
err
return
j
,
err
...
@@ -77,7 +77,11 @@ func (k *Key) UnmarshalJSON(j []byte) (err error) {
...
@@ -77,7 +77,11 @@ func (k *Key) UnmarshalJSON(j []byte) (err error) {
if
err
!=
nil
{
if
err
!=
nil
{
curveType
=
crypto
.
CurveTypeEd25519
curveType
=
crypto
.
CurveTypeEd25519
}
}
k2
,
err
:=
NewKeyFromPriv
(
curveType
,
keyJ
.
PrivateKey
.
Plain
)
privKey
,
err
:=
hex
.
DecodeString
(
keyJ
.
PrivateKey
.
Plain
)
if
err
!=
nil
{
return
err
}
k2
,
err
:=
NewKeyFromPriv
(
curveType
,
privKey
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -201,9 +205,13 @@ func DecryptKey(passphrase string, keyProtected *keyJSON) (*Key, error) {
...
@@ -201,9 +205,13 @@ func DecryptKey(passphrase string, keyProtected *keyJSON) (*Key, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
pubKey
,
err
:=
hex
.
DecodeString
(
keyProtected
.
PublicKey
)
if
err
!=
nil
{
return
nil
,
err
}
plainText
,
err
:=
gcm
.
Open
(
nil
,
nonce
,
cipherText
,
nil
)
plainText
,
err
:=
gcm
.
Open
(
nil
,
nonce
,
cipherText
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
pkey
,
_
:=
NewKeyFromPub
(
curveType
,
keyProtected
.
Public
Key
)
pkey
,
_
:=
NewKeyFromPub
(
curveType
,
pub
Key
)
return
pkey
,
err
return
pkey
,
err
}
}
address
,
err
:=
crypto
.
AddressFromHexString
(
keyProtected
.
Address
)
address
,
err
:=
crypto
.
AddressFromHexString
(
keyProtected
.
Address
)
...
@@ -289,8 +297,8 @@ func (ks KeyStore) StoreKeyEncrypted(passphrase string, key *Key) error {
...
@@ -289,8 +297,8 @@ func (ks KeyStore) StoreKeyEncrypted(passphrase string, key *Key) error {
}
}
keyStruct
:=
keyJSON
{
keyStruct
:=
keyJSON
{
CurveType
:
key
.
CurveType
.
String
(),
CurveType
:
key
.
CurveType
.
String
(),
Address
:
strings
.
ToUpper
(
hex
.
EncodeToString
(
key
.
Address
[
:
])
)
,
Address
:
hex
.
Encode
Upper
ToString
(
key
.
Address
[
:
]),
PublicKey
:
key
.
Pubkey
(),
PublicKey
:
hex
.
EncodeUpperToString
(
key
.
Pubkey
()
)
,
AddressHash
:
key
.
PublicKey
.
AddressHashType
(),
AddressHash
:
key
.
PublicKey
.
AddressHashType
(),
PrivateKey
:
cipherStruct
,
PrivateKey
:
cipherStruct
,
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment