├── README.md ├── encrypt.sh ├── aes.go └── daes.go /README.md: -------------------------------------------------------------------------------- 1 | # En-de-crypt-cli -------------------------------------------------------------------------------- /encrypt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | go run aes.go 3 | 4 | -------------------------------------------------------------------------------- /aes.go: -------------------------------------------------------------------------------- 1 | package main 2 | import ( 3 | "crypto/aes" 4 | "crypto/cipher" 5 | "crypto/rand" 6 | "fmt" 7 | "io" 8 | "io/ioutil" 9 | 10 | ) 11 | 12 | func main(){ 13 | fmt.Println("Encryption program v0.01") 14 | 15 | 16 | 17 | fmt.Println("Enter Your text which is to be encrypted: ") 18 | var first string 19 | fmt.Scanln(&first) 20 | fmt.Println("Enter Your passphrase (passphrase should be 32 bytes): ") 21 | var passphrase string 22 | fmt.Scanln(&passphrase) 23 | text := []byte(first) 24 | key := []byte(passphrase) 25 | c,err := aes.NewCipher(key) 26 | if err != nil{ 27 | fmt.Println(err) 28 | } 29 | 30 | gcm,err := cipher.NewGCM(c) 31 | if err != nil{ 32 | fmt.Println(err) 33 | } 34 | nonce := make([]byte, gcm.NonceSize()) 35 | 36 | if _, err = io.ReadFull(rand.Reader,nonce); err != nil{ 37 | 38 | fmt.Println(err) 39 | } 40 | //fmt.Println(gcm.Seal(nonce, nonce, text, nil)) 41 | err = ioutil.WriteFile("myfile.data", gcm.Seal(nonce, nonce, text, nil), 0777) 42 | 43 | if err != nil { 44 | fmt.Println(err) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /daes.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "crypto/aes" 5 | "crypto/cipher" 6 | "fmt" 7 | "io/ioutil" 8 | ) 9 | 10 | func main() { 11 | fmt.Println("Decryption Program v0.01") 12 | fmt.Println("Enter Your passphrase (passphrase should be 32 bytes): ") 13 | var passphrase string 14 | fmt.Scanln(&passphrase) 15 | fmt.Println("Enter Your data filename (format = xyz.data): ") 16 | var filename string 17 | fmt.Scanln(&filenam) 18 | 19 | key := []byte(passphrase) 20 | 21 | ciphertext, err := ioutil.ReadFile(filename.data) 22 | 23 | if err != nil { 24 | fmt.Println(err) 25 | } 26 | 27 | c, err := aes.NewCipher(key) 28 | if err != nil { 29 | fmt.Println(err) 30 | } 31 | 32 | gcm, err := cipher.NewGCM(c) 33 | if err != nil { 34 | fmt.Println(err) 35 | } 36 | 37 | nonceSize := gcm.NonceSize() 38 | if len(ciphertext) < nonceSize { 39 | fmt.Println(err) 40 | } 41 | 42 | nonce, ciphertext := ciphertext[:nonceSize], ciphertext[nonceSize:] 43 | plaintext, err := gcm.Open(nil, nonce, ciphertext, nil) 44 | if err != nil { 45 | fmt.Println(err) 46 | } 47 | fmt.Println(string(plaintext)) 48 | } 49 | --------------------------------------------------------------------------------