Skip to main content
added 81 characters in body
Source Link

As the PyCrypto API says, the IV must be a byte string, not a text string.

Your piece of code will work fine in Python 2, because they are the same thing (that is, they all are class str, unless you deal with Unicode text). In Python 3 they are two completely different types: bytes and str.

The code should therefore be:

iv = bytes([ random.randint(0,0xFF) for i in range(16)] ) 

Such code (beside not being cryptographically secure as Federico points out) will not properly work in Python 2 though. The following alternative works fine in both cases, it is secure and it is more efficient:

iv = Random.new().read(16) 

As the PyCrypto API says, the IV must be a byte string, not a text string.

Your piece of code will work fine in Python 2, because they are the same thing (that is, they all are class str, unless you deal with Unicode text). In Python 3 they are two completely different types: bytes and str.

The code should therefore be:

iv = bytes([ random.randint(0,0xFF) for i in range(16)] ) 

Such code will not properly work in Python 2 though. The following alternative works fine in both cases and it is more efficient:

iv = Random.new().read(16) 

As the PyCrypto API says, the IV must be a byte string, not a text string.

Your piece of code will work fine in Python 2, because they are the same thing (that is, they all are class str, unless you deal with Unicode text). In Python 3 they are two completely different types: bytes and str.

The code should therefore be:

iv = bytes([ random.randint(0,0xFF) for i in range(16)] ) 

Such code (beside not being cryptographically secure as Federico points out) will not properly work in Python 2 though. The following alternative works fine in both cases, it is secure and it is more efficient:

iv = Random.new().read(16) 
added 308 characters in body
Source Link

TheAs the PyCrypto API says, the IV must be a byte string, not a texttext string.

Your piece of code will work fine in Python 2, because they are the same thing (that is, they all are class str, unless you deal with Unicode text). In Python 3 that is a huge differencethey are two completely different types: bytes and str. Try this

The code should therefore be:

iv = bytes([ random.randint(0,0xFF) for i in range(16)] ) 

Such code will not properly work in Python 2 though. The following alternative works fine in both cases and it is more efficient:

iv = Random.new().read(AES.block_size16) 

The IV must be a byte string, not a text string. In Python 3 that is a huge difference. Try this:

iv = Random.new().read(AES.block_size) 

As the PyCrypto API says, the IV must be a byte string, not a text string.

Your piece of code will work fine in Python 2, because they are the same thing (that is, they all are class str, unless you deal with Unicode text). In Python 3 they are two completely different types: bytes and str.

The code should therefore be:

iv = bytes([ random.randint(0,0xFF) for i in range(16)] ) 

Such code will not properly work in Python 2 though. The following alternative works fine in both cases and it is more efficient:

iv = Random.new().read(16) 
Source Link

The IV must be a byte string, not a text string. In Python 3 that is a huge difference. Try this:

iv = Random.new().read(AES.block_size)