diff --git a/tools/encodings.go b/tools/encodings.go
@@ -3,6 +3,7 @@ package tools
import (
b32 "encoding/base32"
b64 "encoding/base64"
+ "encoding/hex"
"errors"
"fmt"
"math/rand"
@@ -20,7 +21,7 @@ const (
)
// / Available encodings type
-var Encodings = [2]string{"base64", "base32"}
+var Encodings = [3]string{"base64", "base32", "hex"}
// String is used both by fmt.Print and by Cobra in help text
func (e *BytesEncodingType) String() string {
@@ -30,11 +31,11 @@ func (e *BytesEncodingType) String() string {
// / Set must have pointer receiver so it doesn't change the value of a copy
func (e *BytesEncodingType) Set(v string) error {
switch v {
- case "base64", "base32":
+ case "base64", "base32", "hex":
*e = BytesEncodingType(v)
return nil
default:
- return errors.New(`must be one of "base64", "base32"`)
+ return errors.New(`unknown encoding type`)
}
}
@@ -62,10 +63,8 @@ func EncodeForInterpolation(method BytesEncodingType, toEncode []byte) string {
case EncodingBase32:
return fmt.Sprintf("\"%s\"", b32.StdEncoding.EncodeToString(toEncode))
- /*
case EncodingHex:
return fmt.Sprintf("\"%s\"", hex.EncodeToString(toEncode))
- */
default:
return ""
diff --git a/tools/utils.go b/tools/utils.go
@@ -102,6 +102,13 @@ go 1.20
}
func GetMainTemplate(encoding string, key string, sc string) string {
+
+ /* if hex encoding is used, it does not require to go through StdEncoding */
+ encCall := "enc.StdEncoding"
+ if encoding == "hex" {
+ encCall = "enc"
+ }
+
return fmt.Sprintf(`
package main
@@ -115,8 +122,8 @@ var Code = %s
func main() {
- decodedSc, _ := enc.StdEncoding.DecodeString(Code)
- decodedKey, _ := enc.StdEncoding.DecodeString(Key)
+ decodedSc, _ := %s.DecodeString(Code)
+ decodedKey, _ := %s.DecodeString(Key)
decrypted, err := Decrypt(decodedSc, decodedKey)
if err != nil {
@@ -125,5 +132,5 @@ func main() {
ExecuteOrderSixtySix(decrypted)
}
- `, encoding, key, sc)
+ `, encoding, key, sc, encCall, encCall)
}
| |