python长整型字节数_Python将整数转换为16字节字节
已解決
密碼學Python
Python將整數轉換為16字節字節10
我正在嘗試在我的代碼中使用AES-CTR-128。 我使用Python 2.7并利用cryptography模塊進行加密。
我需要設置特定的Counter值,例如counter_iv = 112.當我嘗試時import?os
from?cryptography.hazmat.primitives.ciphers?import?Cipher,?algorithms,?modes
from?cryptography.hazmat.backends?import?default_backend
backend?=?default_backend()
key?=?os.urandom(32)
counter_iv?=?112
cipher?=?Cipher(algorithms.AES(key),?modes.CTR(counter_iv),?backend=backend)
encryptor?=?cipher.encryptor()
ciphertext?=?encryptor.update(b"a?secret?message")?+?encryptor.finalize()
這給了我一個錯誤信息:Traceback?(most?recent?call?last):
File?"aestest.py",?line?14,?in?cipher?=?Cipher(algorithms.AES(key),?modes.CTR(counter_iv),?backend=backend)
File?"/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/primitives/ciphers/modes.py",?line?139,?in?__init__
raise?TypeError("nonce?must?be?bytes")
TypeError:?nonce?must?be?bytes
我認為它告訴我counter_iv應該是一個16字節的字符串。
我的問題是如何將整數或長整數轉換為16字節的字符串?
此外,有沒有辦法將整數轉換為任何長度的字符串? 謝謝你的幫助。
月下風華
2019.07.23
4022
收藏
總結
以上是生活随笔為你收集整理的python长整型字节数_Python将整数转换为16字节字节的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: sublime配置python3_Sub
- 下一篇: python 组合数库函数_Python