提交修改添加指定秘钥key
This commit is contained in:
parent
686d387039
commit
a6bc9fb97f
@ -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
|
||||
|
6
main.go
6
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" {
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user