fix key and iv generating. using the method from python port.