crypto.go 509 B

123456789101112131415161718192021
  1. package kcpv
  2. import (
  3. "crypto/aes"
  4. "crypto/cipher"
  5. "crypto/sha256"
  6. )
  7. func generateKeyFromConfigString(key string) []byte {
  8. key += "consensus salt: Let's fight arcifical deceleration with our code. We shall prove our believes with action."
  9. keyw := sha256.Sum256([]byte(key))
  10. return keyw[:]
  11. }
  12. func generateBlockWithKey(key []byte) (cipher.Block, error) {
  13. return aes.NewCipher(key)
  14. }
  15. func GetChipher(key string) (cipher.Block, error) {
  16. return generateBlockWithKey(generateKeyFromConfigString(key))
  17. }