Example #1
0
func Decrypt(v, k []byte) ([]byte, error) {
	if len(k) != 16 {
		return nil, KeyError
	}
	r := C.btea((*C.int)(unsafe.Pointer(&v[0])), C.int(-len(v)/4), (*C.int)(unsafe.Pointer(&k[0])))
	if r != 0 {
		return nil, XXTeaError
	}
	return PKCS5UnPadding(v), nil
}
Example #2
0
func Encrypt(v, k []byte) ([]byte, error) {
	if len(k) != 16 {
		return nil, KeyError
	}
	if len(v) < 8 {
		v = PKCS5Padding(v, 8)
	} else {
		v = PKCS5Padding(v, 4)
	}
	r := C.btea((*C.int)(unsafe.Pointer(&v[0])), C.int(len(v)/4), (*C.int)(unsafe.Pointer(&k[0])))
	if r != 0 {
		return nil, XXTeaError
	}
	return v, nil
}