aboutsummaryrefslogtreecommitdiff
path: root/cmd/rawCmds.go
diff options
context:
space:
mode:
authorishaan <contact@ishaan.cc>2026-07-12 06:40:42 +0530
committerishaan <contact@ishaan.cc>2026-07-12 06:40:42 +0530
commit65017dfaff1376a16f4d11e76a8aa2d625e05aec (patch)
treeab099d2b5d037e2670e6761c99a506accaef78d8 /cmd/rawCmds.go
parentcfbacac3872a98303481a7930b8d497058499b30 (diff)
no step on snek
Diffstat (limited to 'cmd/rawCmds.go')
-rw-r--r--cmd/rawCmds.go98
1 files changed, 0 insertions, 98 deletions
diff --git a/cmd/rawCmds.go b/cmd/rawCmds.go
deleted file mode 100644
index ff00cab..0000000
--- a/cmd/rawCmds.go
+++ /dev/null
@@ -1,98 +0,0 @@
-package main
-
-import (
- "fmt"
- "os"
- "strings"
-
- "golang.org/x/crypto/argon2"
- "golang.org/x/crypto/chacha20poly1305"
-)
-
-var salt = []byte{
- 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8,
- 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10,
-}
-
-func rawEncryptFile(file string) {
- fileBytes, err := os.ReadFile(file)
- if err != nil {
- panic(err)
- }
-
- fmt.Printf("Enter a super secure passphrase: ")
- password, err := takeSecureUserInput()
- if err != nil {
- panic(err)
- }
-
- key := argon2.IDKey(password, salt, 1, 2*1024*1024, 2, 32)
- aead, err := chacha20poly1305.New(key)
- if err != nil {
- panic(err)
- }
-
- nonce := make([]byte, aead.NonceSize(), aead.NonceSize()+len(fileBytes)+aead.Overhead())
-
- encrypted := aead.Seal(nonce, nonce, fileBytes, nil)
-
- fmt.Print("output path: ")
- var outPath string
- _, err = fmt.Scanln(&outPath)
- if err != nil {
- panic(err)
- }
- os.WriteFile(outPath, encrypted, 0644)
-}
-
-func rawDecryptFile(file string) {
- fileBytes, err := os.ReadFile(file)
- if err != nil {
- panic(err)
- }
-
- fmt.Printf("Enter the super secure passphrase: ")
- password, err := takeSecureUserInput()
- if err != nil {
- panic(err)
- }
-
- key := argon2.IDKey(password, salt, 1, 2*1024*1024, 2, 32)
- aead, err := chacha20poly1305.New(key)
- if err != nil {
- panic(err)
- }
-
- nonce, ciphertext := fileBytes[:aead.NonceSize()], fileBytes[aead.NonceSize():]
-
- plaintext, err := aead.Open(nil, nonce, ciphertext, nil)
- if err != nil {
- if strings.Contains(err.Error(), "message authentication failed") {
- fmt.Fprintln(os.Stderr, "wrong password or corrupted data")
- os.Exit(1)
- }
- panic(err)
- }
-
- fmt.Print("output path: ")
- var outPath string
- _, err = fmt.Scanln(&outPath)
- if err != nil {
- panic(err)
- }
-
- if _, err := os.ReadFile(outPath); err == nil {
- var overwriteConfirm string
- fmt.Printf("file '%s' already exists. Overwrite? [y/N] ", outPath)
- fmt.Scanln(&overwriteConfirm)
-
- if overwriteConfirm != "y" && overwriteConfirm != "Y" {
- fmt.Fprintln(os.Stderr, "write aborted")
- os.Exit(1)
- }
- }
-
- if err := os.WriteFile(outPath, plaintext, 0644); err != nil {
- panic(err)
- }
-}