From a6bc9fb97f23dbcdd494742d5b0bc119ac343a9d Mon Sep 17 00:00:00 2001 From: 15128022404 <1421485150@qq.com> Date: Fri, 14 Oct 2022 16:35:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BF=AE=E6=94=B9=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=8C=87=E5=AE=9A=E7=A7=98=E9=92=A5key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ main.go | 6 ++++++ util/EncodeAndDecode.go | 10 ++++++++++ 3 files changed, 18 insertions(+) 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)