removing key param from encode and using getHeader/getKey to get current key