Skip to content

Commit

Permalink
fix: hex private may not exists (#402)
Browse files Browse the repository at this point in the history
* feat: init btip52

* feat: impletation by go-btfs-api

* feat: p2p remote call

* fix: decryption to cat

* test: fix command test

* test: command test shows that tagline is required

* fix: hex private may not exists
  • Loading branch information
Shawn-Huang-Tron authored Dec 14, 2023
1 parent 68295b1 commit 427f82e
Showing 1 changed file with 7 additions and 2 deletions.
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

0 comments on commit 427f82e

Please sign in to comment.