Пример #1
0
func (ev *EncryptEventV2) Decode(buffer *bytes.Buffer) (err error) {
	ev.EncryptType, err = DecodeUInt32Value(buffer)
	if err != nil {
		return err
	}
	length, err := DecodeUInt32Value(buffer)
	if err != nil {
		return
	}
	switch ev.EncryptType {
	case ENCRYPTER_NONE:
		err, ev.Ev = DecodeEvent(buffer)
		return err
	case ENCRYPTER_SE1:
		newbuf := util.SimpleDecrypt(bytes.NewBuffer(buffer.Next(int(length))))
		err, ev.Ev = DecodeEvent(newbuf)
		newbuf.Reset()
	case ENCRYPTER_RC4:
		src := buffer.Next(int(length))
		dst := make([]byte, int(length))
		cipher, _ := rc4.NewCipher([]byte(rc4Key))
		cipher.XORKeyStream(dst, src)
		err, ev.Ev = DecodeEvent(bytes.NewBuffer(dst))
	default:
		return errors.New("Not supported encrypt type:" + strconv.Itoa(int(ev.EncryptType)))
	}
	return err
}
Пример #2
0
func (ev *EncryptEvent) Decode(buffer *bytes.Buffer) (err error) {
	ev.EncryptType, err = DecodeUInt32Value(buffer)
	if err != nil {
		return err
	}
	switch ev.EncryptType {
	case ENCRYPTER_NONE:
		err, ev.Ev = DecodeEvent(buffer)
		return err
	case ENCRYPTER_SE1:
		newbuf := util.SimpleDecrypt(buffer)
		//fmt.Printf("Decrypt decode %d bytes\n", newbuf.Len())
		err, ev.Ev = DecodeEvent(newbuf)
		newbuf.Reset()
	default:
		return errors.New("Not supported encrypt type:" + strconv.Itoa(int(ev.EncryptType)))
	}
	return err
}