Skip to content

Commit

Permalink
feat: make key output easier for copying
Browse files Browse the repository at this point in the history
  • Loading branch information
mehditeymorian committed Jun 6, 2023
1 parent ac81e3c commit b340099
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
9 changes: 5 additions & 4 deletions internal/cmd/key/ecdsa.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package key

import (
"fmt"
"github.com/AlecAivazis/survey/v2"
"github.com/mehditeymorian/jwt/internal/cmd"
"github.com/mehditeymorian/jwt/internal/config"
Expand Down Expand Up @@ -39,10 +40,10 @@ func ecdsa(c *cobra.Command, _ []string) {

publicKey, privateKey := keyGenerator.GenerateEcdsaKeys(ellipticCurve)

publicBox := pterm.DefaultBox.WithTitle("Public Key").Sprint(publicKey)
privateBox := pterm.DefaultBox.WithTitle("Private Key").Sprint(privateKey)
render, _ := pterm.DefaultPanel.WithPanels(pterm.Panels{{{Data: publicBox}, {Data: privateBox}}}).Srender()
pterm.Println(render)
pterm.Info.Println("Public Key")
fmt.Println(publicKey)
pterm.Info.Println("Private Key")
fmt.Println(privateKey)

if saveFile {
SaveKey("/public.pem", []byte(publicKey))
Expand Down
12 changes: 9 additions & 3 deletions internal/cmd/key/hmac.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package key

import (
"fmt"
"strconv"

"github.com/AlecAivazis/survey/v2"
Expand Down Expand Up @@ -39,12 +40,17 @@ func hmac(c *cobra.Command, _ []string) {
}

cfg.PrintMode()
pterm.Info.Println("size: " + pterm.Blue(size))
pterm.Info.Println("base64Encoded: " + pterm.Blue(base64Encoded))
pterm.Info.Println("Size: " + pterm.Blue(size))
pterm.Info.Println("Base64 Encoded: " + pterm.Blue(base64Encoded))

hmacKey := keyGenerator.GenerateHmacKey(size, base64Encoded)

pterm.Info.Println("key: " + pterm.Blue(string(hmacKey)))
pterm.Info.Println("Key:")
if base64Encoded {
fmt.Println(string(hmacKey))
} else {
fmt.Println(hmacKey)
}

if saveFile {
SaveKey("/key.txt", hmacKey)
Expand Down
9 changes: 5 additions & 4 deletions internal/cmd/key/rsa.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package key

import (
"fmt"
"strconv"

"github.com/AlecAivazis/survey/v2"
Expand Down Expand Up @@ -41,10 +42,10 @@ func rsa(c *cobra.Command, _ []string) {

publicKey, privateKey := keyGenerator.GenerateRsaKeys(bits)

publicBox := pterm.DefaultBox.WithTitle("Public Key").Sprint(publicKey)
privateBox := pterm.DefaultBox.WithTitle("Private Key").Sprint(privateKey)
render, _ := pterm.DefaultPanel.WithPanels(pterm.Panels{{{Data: publicBox}, {Data: privateBox}}}).Srender()
pterm.Println(render)
pterm.Info.Println("Public Key")
fmt.Println(publicKey)
pterm.Info.Println("Private Key")
fmt.Println(privateKey)

if saveFile {
SaveKey("/public.pem", []byte(publicKey))
Expand Down

0 comments on commit b340099

Please sign in to comment.