Skip to content

Commit

Permalink
Update ash.go
Browse files Browse the repository at this point in the history
MD5 fix for 32 Bytes password
some small changes
  • Loading branch information
abolix authored Jun 2, 2020
1 parent 144cd52 commit 500de2a
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions ash.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package main
import (
"crypto/aes"
"crypto/cipher"
"crypto/md5"
"crypto/rand"
"encoding/hex"
"flag"
"fmt"
"io"
Expand All @@ -21,16 +23,25 @@ func fileExists(fileName string) bool {
return !info.IsDir()
}

func ConvertTo32(Password string) string {
PasswordLength := len(Password)
MD5Hasher := md5.New()
MD5Hasher.Write([]byte(Password))
PasswordMD5 := hex.EncodeToString(MD5Hasher.Sum(nil))
PasswordLength = 32 - PasswordLength
Password = Password + PasswordMD5[0:PasswordLength]
return Password
}
func Encrypt(fileName string, Password string) {

File, err := ioutil.ReadFile(fileName)
Data := []byte("(" + fileName + ")" + string(File))
PasswordLength := len(Password)
SplitText := "x"
PasswordLength = 32 - PasswordLength
for i := 1; i <= PasswordLength; i++ {
Password += SplitText
if err != nil {
fmt.Println(err)
}
Data := []byte("(" + fileName + ")" + string(File))

// Ciper Needs 32 Byte Password
Password = ConvertTo32(Password)
key := []byte(Password)

c, err := aes.NewCipher(key)
Expand All @@ -54,21 +65,16 @@ func Encrypt(fileName string, Password string) {

fmt.Println(err)
}
os.Remove(fileName)
os.Remove(fileName) // Remove Original File
fmt.Println("File Encrypted as " + RegexMatch + ".ash !")
}

func Decrypt(filename string, Password string) {

PasswordLength := len(Password)
SplitText := "x"
PasswordLength = 32 - PasswordLength
for i := 1; i <= PasswordLength; i++ {
Password += SplitText
}
// TODO : .ash extenstion is not necessary
Password = ConvertTo32(Password)
key := []byte(Password)
ciphertext, err := ioutil.ReadFile(filename)

ciphertext, err := ioutil.ReadFile(filename)
if err != nil {
fmt.Println(err)
}
Expand Down Expand Up @@ -106,9 +112,6 @@ func Decrypt(filename string, Password string) {
fmt.Println("File Decrypted Successfully !")
}
func main() {
// Shima -e -f test.png -p 1234
// Shima -d -f test.png -p 1234

encrypt := flag.Bool("e", false, "encrypt")
decrypt := flag.Bool("d", false, "decrypt")
fileName := flag.String("f", "", "fileName")
Expand All @@ -125,8 +128,8 @@ func main() {
os.Exit(1)
}

if len(*password) >= 32 {
fmt.Println("Password Can't Be Empty , Please Use -p to enter Password")
if len(*password) > 32 {
fmt.Println("Password Can't be more than 32 characters")
os.Exit(1)
}

Expand Down

0 comments on commit 500de2a

Please sign in to comment.