good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
0c7df373
Commit
0c7df373
authored
Feb 10, 2015
by
Felix Lange
Browse files
Options
Downloads
Patches
Plain Diff
crypto: add key loading functions
parent
f1ebad25
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
crypto/crypto.go
+28
-0
28 additions, 0 deletions
crypto/crypto.go
crypto/key.go
+2
-1
2 additions, 1 deletion
crypto/key.go
with
30 additions
and
1 deletion
crypto/crypto.go
+
28
−
0
View file @
0c7df373
...
@@ -8,6 +8,8 @@ import (
...
@@ -8,6 +8,8 @@ import (
"crypto/rand"
"crypto/rand"
"crypto/sha256"
"crypto/sha256"
"fmt"
"fmt"
"io"
"os"
"encoding/hex"
"encoding/hex"
"encoding/json"
"encoding/json"
...
@@ -99,6 +101,32 @@ func FromECDSAPub(pub *ecdsa.PublicKey) []byte {
...
@@ -99,6 +101,32 @@ func FromECDSAPub(pub *ecdsa.PublicKey) []byte {
return
elliptic
.
Marshal
(
S256
(),
pub
.
X
,
pub
.
Y
)
return
elliptic
.
Marshal
(
S256
(),
pub
.
X
,
pub
.
Y
)
}
}
// HexToECDSA parses a secp256k1 private key.
func
HexToECDSA
(
hexkey
string
)
(
*
ecdsa
.
PrivateKey
,
error
)
{
b
,
err
:=
hex
.
DecodeString
(
hexkey
)
if
err
!=
nil
{
return
nil
,
errors
.
New
(
"invalid hex string"
)
}
if
len
(
b
)
!=
32
{
return
nil
,
errors
.
New
(
"invalid length, need 256 bits"
)
}
return
ToECDSA
(
b
),
nil
}
// LoadECDSA loads a secp256k1 private key from the given file.
func
LoadECDSA
(
file
string
)
(
*
ecdsa
.
PrivateKey
,
error
)
{
buf
:=
make
([]
byte
,
32
)
fd
,
err
:=
os
.
Open
(
file
)
if
err
!=
nil
{
return
nil
,
err
}
defer
fd
.
Close
()
if
_
,
err
:=
io
.
ReadFull
(
fd
,
buf
);
err
!=
nil
{
return
nil
,
err
}
return
ToECDSA
(
buf
),
nil
}
func
GenerateKey
()
(
*
ecdsa
.
PrivateKey
,
error
)
{
func
GenerateKey
()
(
*
ecdsa
.
PrivateKey
,
error
)
{
return
ecdsa
.
GenerateKey
(
S256
(),
rand
.
Reader
)
return
ecdsa
.
GenerateKey
(
S256
(),
rand
.
Reader
)
}
}
...
...
This diff is collapsed.
Click to expand it.
crypto/key.go
+
2
−
1
View file @
0c7df373
...
@@ -25,11 +25,12 @@ package crypto
...
@@ -25,11 +25,12 @@ package crypto
import
(
import
(
"bytes"
"bytes"
"code.google.com/p/go-uuid/uuid"
"crypto/ecdsa"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/elliptic"
"encoding/json"
"encoding/json"
"io"
"io"
"code.google.com/p/go-uuid/uuid"
)
)
type
Key
struct
{
type
Key
struct
{
...
...
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