Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Don't know where you got the following code from</p> <pre><code>data_bytes = str.encode(request_params) key_bytes = str.encode(dev_key) iv_bytes = str.encode(dev_iv) </code></pre> <p>but you should know that it is equivalent to the following:</p> <pre><code>data_bytes = request_params.encode("ascii") key_bytes = dev_key.encode("ascii") iv_bytes = dev_iv.encode("ascii") </code></pre> <p>which means that non-ASCII characters in any of the three variables will cause an error (I hope you don't make up an AES key of ASCII characters only?).</p> <p>In Python 2.x, <code>str</code> objects (<code>byte[]</code> in C#) are bytes and <code>unicode</code> objects (<code>string</code> in C#) are for text. This confusing fact was changed in Python 3.x, by the way.<br/> That means if <code>request_params</code> is a Unicode object, you should encode it as UTF-8, and if it's a <code>str</code> object, you should assume (or check) that it is already encoded as UTF-8. So it might be something like:</p> <pre><code>if isinstance(request_params, unicode): data_bytes = request_params.encode("utf-8") else: request_params.decode("utf-8") # optional check whether it is correct UTF-8 data_bytes = request_params </code></pre> <p>As for key/IV, they will always be <em>binary</em> data (e.g. 16 bytes for AES-128), not text. So they don't have a character encoding. Remove those two lines of code and probably replace them with</p> <pre><code>assert len(dev_key) == block_size and len(dev_iv) == block_size </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload