From 0f28c577cebe23185556fe20cce685976d0976f9 Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Sun, 12 Jun 2016 12:02:16 +0800 Subject: [PATCH] KCP: Chiper generater --- transport/hub/kcpv/crypto.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 transport/hub/kcpv/crypto.go diff --git a/transport/hub/kcpv/crypto.go b/transport/hub/kcpv/crypto.go new file mode 100644 index 00000000..049c9f2d --- /dev/null +++ b/transport/hub/kcpv/crypto.go @@ -0,0 +1,21 @@ +package kcpv + +import ( + "crypto/aes" + "crypto/cipher" + "crypto/sha256" +) + +func generateKeyFromConfigString(key string) []byte { + key += "consensus salt: Let's fight arcifical deceleration with our code. We shall prove our believes with action." + keyw := sha256.Sum256([]byte(key)) + return keyw[:] +} + +func generateBlockWithKey(key []byte) (cipher.Block, error) { + return aes.NewCipher(key) +} + +func GetChipher(key string) (cipher.Block, error) { + return generateBlockWithKey(generateKeyFromConfigString(key)) +}