Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hex private may not exists #402

Merged
merged 8 commits into from
Dec 14, 2023
Merged
9 changes: 7 additions & 2 deletions core/commands/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"bytes"
"crypto/rand"
"encoding/base64"
"errors"
"io"
"os"
Expand All @@ -12,6 +13,7 @@ import (
cp "github.com/bittorrent/go-btfs-common/crypto"
"github.com/bittorrent/go-btfs/core/commands/cmdenv"
"github.com/bittorrent/go-btfs/core/corehttp/remote"
cpt "github.com/bittorrent/go-btfs/transaction/crypto"
ethCrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/ecies"
peer "github.com/libp2p/go-libp2p/core/peer"
Expand Down Expand Up @@ -123,10 +125,13 @@ var decryptCmd = &cmds.Command{
return err
}
}
ecdsaPrivateKey, err := ethCrypto.HexToECDSA(conf.Identity.HexPrivKey)

pkbytesOri, err := base64.StdEncoding.DecodeString(conf.Identity.PrivKey)
if err != nil {
return err
}
ecdsaPrivateKey := cpt.Secp256k1PrivateKeyFromBytes(pkbytesOri[4:])

eciesPrivateKey := ecies.ImportECDSA(ecdsaPrivateKey)
endata, err := io.ReadAll(readClose)
if err != nil {
Expand All @@ -135,7 +140,7 @@ var decryptCmd = &cmds.Command{
defer readClose.Close()
dedata, err := ECCDecrypt(endata, *eciesPrivateKey)
if err != nil {
panic(err)
return errors.New("decryption is failed, maybe the content of encryption is not encrypted by your public key")
}
fileName := "./decrypt-file-of-" + cid
f, err := os.Create(fileName)
Expand Down
Loading