|
|
@ -8,6 +8,22 @@ import (
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//PathExists 判断一个文件或文件夹是否存在
|
|
|
|
|
|
|
|
//输入文件路径,根据返回的bool值来判断文件或文件夹是否存在
|
|
|
|
|
|
|
|
func PathExists(path string) (bool, string) {
|
|
|
|
|
|
|
|
if len(path) == 0 {
|
|
|
|
|
|
|
|
return false, "path 不能为空"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := os.Stat(path)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
return true, "存在"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
|
|
|
|
return false, "path路径文件不存在"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false, "path路径文件不存在"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func readFileToStr(path string) string {
|
|
|
|
func readFileToStr(path string) string {
|
|
|
|
content, err := ioutil.ReadFile(path)
|
|
|
|
content, err := ioutil.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -73,30 +89,38 @@ var key = flag.String("key", "", "加密秘钥-限制大小写字母数字16位
|
|
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
flag.Parse()
|
|
|
|
//fmt.Println(*mode)
|
|
|
|
//验证操作文件路径是否有效
|
|
|
|
//fmt.Println(*path)
|
|
|
|
flag, message := PathExists(*path)
|
|
|
|
|
|
|
|
if !flag {
|
|
|
|
|
|
|
|
fmt.Printf(message)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 输出路径设置
|
|
|
|
var out string = *path
|
|
|
|
var out string = *path
|
|
|
|
var modeName string
|
|
|
|
var modeName string
|
|
|
|
if len(*outPath) != 0 {
|
|
|
|
if len(*outPath) != 0 {
|
|
|
|
out = *outPath
|
|
|
|
out = *outPath
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//验证秘钥是否有效
|
|
|
|
if len(*key) == 16 {
|
|
|
|
if len(*key) == 16 {
|
|
|
|
util.InitBykey(*key)
|
|
|
|
util.InitBykey(*key)
|
|
|
|
} else if (len(*key) > 0) && (len(*key) < 16) {
|
|
|
|
} else if (len(*key) > 0) && (len(*key) < 16) {
|
|
|
|
fmt.Printf("秘钥限制大小写字母数字16位")
|
|
|
|
fmt.Printf("秘钥限制大小写字母数字16位")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(*path) == 0 {
|
|
|
|
//验证mode 输入是否正确
|
|
|
|
fmt.Printf("path 不能为空")
|
|
|
|
if *mode != "en" && *mode != "de" {
|
|
|
|
} else if *mode != "en" && *mode != "de" {
|
|
|
|
|
|
|
|
fmt.Printf("mode 只能是 en 或者 de")
|
|
|
|
fmt.Printf("mode 只能是 en 或者 de")
|
|
|
|
|
|
|
|
//执行加密
|
|
|
|
} else if *mode == "en" {
|
|
|
|
} else if *mode == "en" {
|
|
|
|
modeName = "加密"
|
|
|
|
modeName = "加密"
|
|
|
|
enFileToOutPath(*path, out)
|
|
|
|
enFileToOutPath(*path, out)
|
|
|
|
|
|
|
|
//执行解密
|
|
|
|
} else if *mode == "de" {
|
|
|
|
} else if *mode == "de" {
|
|
|
|
modeName = "解密"
|
|
|
|
modeName = "解密"
|
|
|
|
deFileToOutPath(*path, out)
|
|
|
|
deFileToOutPath(*path, out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Println(modeName + "成功,被" + modeName + "文件是在: " + *path + " " + modeName + "后文件生产在:" + out)
|
|
|
|
fmt.Println(modeName + "成功,被" + modeName + "文件是在: " + *path + " " + modeName + "后文件生产在:" + out)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//test()
|
|
|
|
//test()
|
|
|
|
// testGenFile("C:\\METSIM\\example\\gascleaning_1.5_30.sfw",
|
|
|
|
// testGenFile("C:\\METSIM\\example\\gascleaning_1.5_30.sfw",
|
|
|
|
// "C:\\Users\\61778\\Desktop\\testGoED\\gascleaning_1.5_30.sfw.EN",
|
|
|
|
// "C:\\Users\\61778\\Desktop\\testGoED\\gascleaning_1.5_30.sfw.EN",
|
|
|
|