Skip to content

bugfix: incorrect raw byte conversion to string #72

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/cmd/turnkey/pkg/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pkg

import (
"crypto/ecdsa"
"encoding/hex"

"github.com/rotisserie/eris"
"github.com/spf13/cobra"
Expand All @@ -15,12 +16,16 @@ var (

// EncryptionKeypair is the loaded Encryption Keypair.
EncryptionKeypair *encryptionkey.Key

// Controls whether output is UTF-8 string or hex string
hexOutput bool
)

func init() {
decryptCmd.Flags().StringVar(&exportBundlePath, "export-bundle-input", "", "filepath to read the export bundle from.")
decryptCmd.Flags().StringVar(&plaintextPath, "plaintext-output", "", "optional filepath to write the plaintext from that will be decrypted.")
decryptCmd.Flags().StringVar(&signerPublicKeyOverride, "signer-quorum-key", "", "optional override for the signer quorum key. This option should be used for testing only. Leave this value empty for production decryptions.")
decryptCmd.Flags().BoolVar(&hexOutput, "hex-output", false, "when true, outputs as hex-encoded string (useful for binary data like private keys); when false (default), outputs as UTF-8 text (suitable for mnemonics and text)")

rootCmd.AddCommand(decryptCmd)
}
Expand Down Expand Up @@ -74,7 +79,12 @@ var decryptCmd = &cobra.Command{
OutputError(err)
}

plaintext := string(plaintextBytes)
var plaintext string
if hexOutput {
plaintext = hex.EncodeToString(plaintextBytes)
} else {
plaintext = string(plaintextBytes)
}

// output the plaintext if no filepath is passed
if plaintextPath == "" {
Expand Down
Loading