Created
May 2, 2018 16:00
-
-
Save rusco/166cda4e086d5fab8793559625c13e19 to your computer and use it in GitHub Desktop.
simple RC4 encryption routine with build flags for keyword
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// simple RC4 encryption routine with build flags for keyword, 02.05.2018 | |
// | |
package main | |
import ( | |
"crypto/rc4" | |
"fmt" | |
) | |
//overwrite key with build flags | |
var sesame = "csharp" | |
func enc(data []byte, key string) ([]byte, error) { | |
c, err := rc4.NewCipher([]byte(key)) | |
if err != nil { | |
fmt.Printf("%v\n", err) | |
return nil, err | |
} | |
src := make([]byte, len(data)) | |
c.XORKeyStream(src, data) | |
c.Reset() | |
fmt.Printf("after encoding, src=% x\n", src) | |
return src, nil | |
} | |
func main() { | |
value := "This data will be encrypted" | |
encoded, _ := enc([]byte(value), sesame) | |
decoded, _ := enc([]byte(encoded), sesame) | |
fmt.Printf("encoded: %s\n", encoded) | |
fmt.Printf("decoded: %s\n", decoded) | |
fmt.Printf("debug sesam : %s\n", sesame) | |
} | |
//go build -ldflags="-s -w -X main.sesame=golang" rc4.go |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment