From ad0a7df81b4b0f3e00f9ccb7e759c3aa8f1fd4ef Mon Sep 17 00:00:00 2001 From: Idris Hanafi Date: Wed, 5 Mar 2025 14:05:16 -0500 Subject: [PATCH 1/2] bugfix: incorrect raw byte conversion to string --- src/cmd/turnkey/pkg/decrypt.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cmd/turnkey/pkg/decrypt.go b/src/cmd/turnkey/pkg/decrypt.go index 2ebac32..89f6da4 100644 --- a/src/cmd/turnkey/pkg/decrypt.go +++ b/src/cmd/turnkey/pkg/decrypt.go @@ -2,6 +2,7 @@ package pkg import ( "crypto/ecdsa" + "encoding/hex" "github.com/rotisserie/eris" "github.com/spf13/cobra" @@ -74,7 +75,7 @@ var decryptCmd = &cobra.Command{ OutputError(err) } - plaintext := string(plaintextBytes) + plaintext := hex.EncodeToString(plaintextBytes) // output the plaintext if no filepath is passed if plaintextPath == "" { From 2d898c10122f087f012d466dc7d83d1b58ca3fb4 Mon Sep 17 00:00:00 2001 From: Idris Hanafi Date: Thu, 6 Mar 2025 13:40:52 -0500 Subject: [PATCH 2/2] feat: adding flag for decrypted output types --- src/cmd/turnkey/pkg/decrypt.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cmd/turnkey/pkg/decrypt.go b/src/cmd/turnkey/pkg/decrypt.go index 89f6da4..b6ef942 100644 --- a/src/cmd/turnkey/pkg/decrypt.go +++ b/src/cmd/turnkey/pkg/decrypt.go @@ -16,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) } @@ -75,7 +79,12 @@ var decryptCmd = &cobra.Command{ OutputError(err) } - plaintext := hex.EncodeToString(plaintextBytes) + var plaintext string + if hexOutput { + plaintext = hex.EncodeToString(plaintextBytes) + } else { + plaintext = string(plaintextBytes) + } // output the plaintext if no filepath is passed if plaintextPath == "" {