enhance(spiral):增加螺旋加密算法的兼容模式。

This commit is contained in:
徐涛
2023-07-18 16:10:46 +08:00
parent 85ebee0185
commit 0992fbe3b6
3 changed files with 23 additions and 4 deletions

View File

@@ -7,6 +7,10 @@ import (
"github.com/spf13/cobra"
)
var (
spiralCompatible bool
)
var spiralCmd = &cobra.Command{
Use: "spiral",
Short: "螺旋随机密钥自解密算法工具",
@@ -28,7 +32,13 @@ var spiralDecodeCmd = &cobra.Command{
}
func spiralEncodeExecute(cmd *cobra.Command, args []string) {
encodedResult, err := spiral.Encrypt(args[0])
var strength spiral.Strength
if spiralCompatible {
strength = spiral.Compatible
} else {
strength = spiral.Enhanced
}
encodedResult, err := spiral.Encrypt(args[0], strength)
if err != nil {
fmt.Printf("加密失败,%s\n", err)
return
@@ -37,7 +47,13 @@ func spiralEncodeExecute(cmd *cobra.Command, args []string) {
}
func spiralDecodeExecute(cmd *cobra.Command, args []string) {
decodedResult, err := spiral.Decrypt(args[0])
var strength spiral.Strength
if spiralCompatible {
strength = spiral.Compatible
} else {
strength = spiral.Enhanced
}
decodedResult, err := spiral.Decrypt(args[0], strength)
if err != nil {
fmt.Printf("解密失败,%s\n", err)
return
@@ -46,6 +62,7 @@ func spiralDecodeExecute(cmd *cobra.Command, args []string) {
}
func init() {
spiralCmd.PersistentFlags().BoolVarP(&spiralCompatible, "compatible", "c", false, "兼容模式,兼容旧版本的螺旋随机密钥自解密算法")
spiralCmd.AddCommand(spiralEncodeCmd, spiralDecodeCmd)
rootCmd.AddCommand(spiralCmd)
}