Example #1
0
//Decrypt a message.
func decryptMessage(key []byte, ciphertext *bytes.Buffer) (buf *bytes.Buffer) {
	iv := doDigest(key)
	aescrypt, aes_err := aes.NewCipher(key)
	if aes_err != nil {
		printerr(aes_err)
	}
	cipher := cipher.NewCBCDecrypter(aescrypt, iv)
	out := bytes.NewBuffer(make([]byte, 512))
	cipher.CryptBlocks(out.Bytes(), ciphertext.Bytes())
	return out
}
Example #2
0
func (self *AnyPortInterface) decrypt(req []byte) ([]byte, error) {
	src := make([]byte, self.key_cipher.BlockSize()*4)
	if _, err := base64.StdEncoding.Decode(src, req); err != nil {
		return nil, err
	}

	dst := make([]byte, self.key_cipher.BlockSize()*2)
	cipher := cipher.NewCBCDecrypter(self.key_cipher, AnyPortIV)
	cipher.CryptBlocks(dst, src[:self.key_cipher.BlockSize()*2])

	return bytes.TrimRight(dst, "\x00"), nil
}