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

Commit 747aa74

Browse files
committed
add license prop to secman brew config, add encrypt command
1 parent 7ebba81 commit 747aa74

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed

.goreleaser.yml

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ brews:
7979
name: homebrew-tap
8080
homepage: "https://secman.dev"
8181
description: "👊 Human-friendly and amazing TUI secrets manager"
82+
license: "MIT"
8283

8384
checksum:
8485
name_template: "checksums.txt"

app/encrypt.go

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package app
2+
3+
import (
4+
"io"
5+
"os"
6+
"fmt"
7+
"crypto/aes"
8+
"crypto/md5"
9+
"crypto/rand"
10+
"crypto/cipher"
11+
"crypto/sha256"
12+
"crypto/sha512"
13+
14+
"github.com/spf13/cobra"
15+
)
16+
17+
func EncryptCMD() *cobra.Command {
18+
cmd := &cobra.Command{
19+
Use: "encrypt",
20+
Short: "Encrypt a value.",
21+
Long: "Encrypt a value. with aes, sha256, and md5 algorithms.",
22+
Run: func(cmd *cobra.Command, args []string) {
23+
if EncryptOpts.AES {
24+
if len(EncryptOpts.AESKey) < 32 {
25+
fmt.Println("AES key must be 32 characters or longer.")
26+
os.Exit(1)
27+
} else {
28+
text := []byte(args[0])
29+
key := []byte(EncryptOpts.AESKey)
30+
31+
c, err := aes.NewCipher(key)
32+
if err != nil {
33+
fmt.Println(err)
34+
}
35+
36+
gcm, err := cipher.NewGCM(c)
37+
if err != nil {
38+
fmt.Println(err)
39+
}
40+
41+
nonce := make([]byte, gcm.NonceSize())
42+
43+
if _, err = io.ReadFull(rand.Reader, nonce); err != nil {
44+
fmt.Println(err)
45+
}
46+
47+
fmt.Printf("%x\n", gcm.Seal(nonce, nonce, text, nil))
48+
}
49+
} else if EncryptOpts.SHA256 {
50+
hash := sha256.Sum256([]byte(args[0]))
51+
52+
fmt.Printf("%x\n", hash)
53+
} else if EncryptOpts.SHA512 {
54+
hash := sha512.Sum512([]byte(args[0]))
55+
56+
fmt.Printf("%x\n", hash)
57+
} else if EncryptOpts.MD5 {
58+
hash := md5.Sum([]byte(args[0]))
59+
60+
fmt.Printf("%x\n", hash)
61+
} else {
62+
fmt.Println("No encryption algorithm selected.")
63+
os.Exit(1)
64+
}
65+
},
66+
}
67+
68+
cmd.Flags().BoolVarP(&EncryptOpts.AES, "aes", "a", false, "Encrypt with aes algorithm.")
69+
cmd.Flags().BoolVarP(&EncryptOpts.SHA256, "sha256", "s", false, "Encrypt with sha256 algorithm.")
70+
cmd.Flags().BoolVarP(&EncryptOpts.SHA512, "sha512", "S", false, "Encrypt with sha512 algorithm.")
71+
cmd.Flags().BoolVarP(&EncryptOpts.MD5, "md5", "m", false, "Encrypt with md5 algorithm.")
72+
cmd.Flags().StringVarP(&EncryptOpts.AESKey, "aes-key", "k", "", "Encrypt with aes key.")
73+
74+
return cmd
75+
}

app/opts.go

+8
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,11 @@ var AuthOpts = options.AuthOptions{
2626
var WhoamiOpts = options.WhoamiOptions{
2727
ShowUser: false,
2828
}
29+
30+
var EncryptOpts = options.EncryptOptions{
31+
AES: false,
32+
SHA256: false,
33+
SHA512: false,
34+
MD5: false,
35+
AESKey: "",
36+
}

cmd/secman/root.go

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func Execute(f *factory.Factory, version string, buildDate string) *cobra.Comman
6464
rootCmd.AddCommand(
6565
app.AuthCMD(),
6666
app.DocsCMD,
67+
app.EncryptCMD(),
6768
app.DoctorCMD(version),
6869
app.InitCMD,
6970
app.InfoCMD(version),

pkg/options/opts.go

+8
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ type RootOptions struct {
2828
type WhoamiOptions struct {
2929
ShowUser bool
3030
}
31+
32+
type EncryptOptions struct {
33+
AES bool
34+
SHA256 bool
35+
SHA512 bool
36+
MD5 bool
37+
AESKey string
38+
}

0 commit comments

Comments
 (0)