Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
add license prop to secman brew config, add encrypt command
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx committed Mar 18, 2022
1 parent 7ebba81 commit 747aa74
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ brews:
name: homebrew-tap
homepage: "https://secman.dev"
description: "👊 Human-friendly and amazing TUI secrets manager"
license: "MIT"

checksum:
name_template: "checksums.txt"
Expand Down
75 changes: 75 additions & 0 deletions app/encrypt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package app

import (
"io"
"os"
"fmt"
"crypto/aes"
"crypto/md5"
"crypto/rand"
"crypto/cipher"
"crypto/sha256"
"crypto/sha512"

"github.com/spf13/cobra"
)

func EncryptCMD() *cobra.Command {
cmd := &cobra.Command{
Use: "encrypt",
Short: "Encrypt a value.",
Long: "Encrypt a value. with aes, sha256, and md5 algorithms.",
Run: func(cmd *cobra.Command, args []string) {
if EncryptOpts.AES {
if len(EncryptOpts.AESKey) < 32 {
fmt.Println("AES key must be 32 characters or longer.")
os.Exit(1)
} else {
text := []byte(args[0])
key := []byte(EncryptOpts.AESKey)

c, err := aes.NewCipher(key)
if err != nil {
fmt.Println(err)
}

gcm, err := cipher.NewGCM(c)
if err != nil {
fmt.Println(err)
}

nonce := make([]byte, gcm.NonceSize())

if _, err = io.ReadFull(rand.Reader, nonce); err != nil {
fmt.Println(err)
}

fmt.Printf("%x\n", gcm.Seal(nonce, nonce, text, nil))
}
} else if EncryptOpts.SHA256 {
hash := sha256.Sum256([]byte(args[0]))

fmt.Printf("%x\n", hash)
} else if EncryptOpts.SHA512 {
hash := sha512.Sum512([]byte(args[0]))

fmt.Printf("%x\n", hash)
} else if EncryptOpts.MD5 {
hash := md5.Sum([]byte(args[0]))

fmt.Printf("%x\n", hash)
} else {
fmt.Println("No encryption algorithm selected.")
os.Exit(1)
}
},
}

cmd.Flags().BoolVarP(&EncryptOpts.AES, "aes", "a", false, "Encrypt with aes algorithm.")
cmd.Flags().BoolVarP(&EncryptOpts.SHA256, "sha256", "s", false, "Encrypt with sha256 algorithm.")
cmd.Flags().BoolVarP(&EncryptOpts.SHA512, "sha512", "S", false, "Encrypt with sha512 algorithm.")
cmd.Flags().BoolVarP(&EncryptOpts.MD5, "md5", "m", false, "Encrypt with md5 algorithm.")
cmd.Flags().StringVarP(&EncryptOpts.AESKey, "aes-key", "k", "", "Encrypt with aes key.")

return cmd
}
8 changes: 8 additions & 0 deletions app/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ var AuthOpts = options.AuthOptions{
var WhoamiOpts = options.WhoamiOptions{
ShowUser: false,
}

var EncryptOpts = options.EncryptOptions{
AES: false,
SHA256: false,
SHA512: false,
MD5: false,
AESKey: "",
}
1 change: 1 addition & 0 deletions cmd/secman/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func Execute(f *factory.Factory, version string, buildDate string) *cobra.Comman
rootCmd.AddCommand(
app.AuthCMD(),
app.DocsCMD,
app.EncryptCMD(),
app.DoctorCMD(version),
app.InitCMD,
app.InfoCMD(version),
Expand Down
8 changes: 8 additions & 0 deletions pkg/options/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ type RootOptions struct {
type WhoamiOptions struct {
ShowUser bool
}

type EncryptOptions struct {
AES bool
SHA256 bool
SHA512 bool
MD5 bool
AESKey string
}

0 comments on commit 747aa74

Please sign in to comment.