feed.encrypt4
This file contains 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
//Encrypt the results | |
func Encrypt(bites []byte) []byte { | |
plainText, err := pad(bites, aes.BlockSize) | |
if err != nil { | |
log.Print(err) | |
return make([]byte, 0) | |
} | |
block, _ := aes.NewCipher(encryptionKey) | |
cipherText := make([]byte, aes.BlockSize+len(plainText)) | |
iv := cipherText[:aes.BlockSize] | |
if _, err := io.ReadFull(rand.Reader, iv); err != nil { | |
return make([]byte, 0) | |
} | |
mode := cipher.NewCBCEncrypter(block, iv) | |
mode.CryptBlocks(cipherText[aes.BlockSize:], plainText) | |
return []byte(fmt.Sprintf("%x", cipherText)) | |
} | |
//Decrypt a command | |
func Decrypt(text string) string { | |
cipherText, _ := hex.DecodeString(text) | |
block, err := aes.NewCipher(encryptionKey) | |
if err != nil { | |
log.Print(err) | |
return "" | |
} | |
iv := cipherText[:aes.BlockSize] | |
cipherText = cipherText[aes.BlockSize:] | |
mode := cipher.NewCBCDecrypter(block, iv) | |
mode.CryptBlocks(cipherText, cipherText) | |
cipherText, _ = unpad(cipherText, aes.BlockSize) | |
return fmt.Sprintf("%s", cipherText) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment