diff --git a/README.md b/README.md index 1024770..36cfe66 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ go 实现 AES 加解密文件 ``` cmd PS C:\Users\61778\Desktop> .\goED.exe --help Usage of C:\Users\61778\Desktop\goED.exe: + -key string + 加密秘钥-限制大小写字母数字16位 -mode string 加密或者解密 en de (default "de") -outPath string diff --git a/main.go b/main.go index e85b9a5..c6ba715 100644 --- a/main.go +++ b/main.go @@ -69,6 +69,7 @@ func deFileToOutPath(path string, outPath string) { var mode = flag.String("mode", "de", "加密或者解密 en de") var path = flag.String("path", "", "文件路径") var outPath = flag.String("outPath", "", "指定输出文件路径") +var key = flag.String("key", "", "加密秘钥-限制大小写字母数字16位 可以不指定") func main() { flag.Parse() @@ -79,6 +80,11 @@ func main() { if len(*outPath) != 0 { out = *outPath } + if len(*key) == 16 { + util.InitBykey(*key) + } else if (len(*key) > 0) && (len(*key) < 16) { + fmt.Printf("秘钥限制大小写字母数字16位") + } if len(*path) == 0 { fmt.Printf("path 不能为空") } else if *mode != "en" && *mode != "de" { diff --git a/util/EncodeAndDecode.go b/util/EncodeAndDecode.go index ad1b55e..bf9d986 100644 --- a/util/EncodeAndDecode.go +++ b/util/EncodeAndDecode.go @@ -26,6 +26,16 @@ func init() { } } +func InitBykey(key string) { + AesEcpt.key = []byte(key) + AesEcpt.iv = []byte("aebksHkG4jAEk2Ag") + var err error + AesEcpt.block, err = aes.NewCipher(AesEcpt.key) + if err != nil { + panic(err) + } +} + // 加密 func (a *AesEncrypter) AesBase64Encrypt(in string) (string, error) { origData := []byte(in)