Made it a bit cleaner :)
This commit is contained in:
35
pkg/engine/keys.go
Normal file
35
pkg/engine/keys.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"crypto/ecdh"
|
||||
"encoding/hex"
|
||||
)
|
||||
|
||||
type KeyPair struct {
|
||||
PrivateKey *ecdh.PrivateKey
|
||||
PublicKey *ecdh.PublicKey
|
||||
}
|
||||
|
||||
func (kp *KeyPair) EncodePublicKey() string {
|
||||
return hex.EncodeToString(kp.PublicKey.Bytes())
|
||||
}
|
||||
|
||||
func (kp *KeyPair) EncodePrivateKey() string {
|
||||
return hex.EncodeToString(kp.PrivateKey.Bytes())
|
||||
}
|
||||
|
||||
func (e *Engine) DecodePrivateKey(hexKey string) (*ecdh.PrivateKey, error) {
|
||||
bytes, err := hex.DecodeString(hexKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return e.curve.NewPrivateKey(bytes)
|
||||
}
|
||||
|
||||
func (e *Engine) DecodePublicKey(hexKey string) (*ecdh.PublicKey, error) {
|
||||
bytes, err := hex.DecodeString(hexKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return e.curve.NewPublicKey(bytes)
|
||||
}
|
||||
Reference in New Issue
Block a user