forked from TrueCloudLab/frostfs-node
[#1216] neofs-cli: Reuse key retrieving code between modules
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
006d6e8b48
commit
8d79168129
5 changed files with 169 additions and 127 deletions
26
cmd/neofs-cli/internal/key/nep2.go
Normal file
26
cmd/neofs-cli/internal/key/nep2.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package key
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
)
|
||||
|
||||
const nep2Base58Length = 58
|
||||
|
||||
// FromNEP2 extracts private key from NEP2-encrypted string.
|
||||
func FromNEP2(encryptedWif string) (*ecdsa.PrivateKey, error) {
|
||||
pass, err := getPassword()
|
||||
if err != nil {
|
||||
printVerbose("Can't read password: %v", err)
|
||||
return nil, ErrInvalidPassword
|
||||
}
|
||||
|
||||
k, err := keys.NEP2Decrypt(encryptedWif, pass, keys.NEP2ScryptParams())
|
||||
if err != nil {
|
||||
printVerbose("Invalid key or password: %v", err)
|
||||
return nil, ErrInvalidPassword
|
||||
}
|
||||
|
||||
return &k.PrivateKey, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue