简体   繁体   English

如何在Python中指定AES密钥?

[英]How can I specify an AES key in Python?

I'm working on converting a Java program into Python and part of its core networking uses AES encryption to handle packets going up and down the line. 我正在将Java程序转换为Python,并且其部分核心网络使用AES加密来处理上下传输的数据包。 Java's AES is initialized like so: Java的AES初始化如下:

byte[] key = { 0x13, 0x00, 0x00, 0x00 };
sKeySpec = new SecretKeySpec(key, "AES");

I want to do the same in Python, and will use PyCrypto, but I'm not sure how to initialize the above in it as it only allows string-based "secret keys." 我想在Python中做同样的事情,并且将使用PyCrypto,但是我不确定如何在其中初始化以上内容,因为它仅允许基于字符串的“秘密密钥”。

然后使用一个字符串

key = '\x13\x00\x00\x00'

为什么不尝试使用Jython,因为您可以直接导入.class文件而无需重新编写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 java 代码中获取 AES 密钥,以便我可以将其保存在文本文件中? - How to get AES key from java code so that i can save it in a text file? 如何使用已生成的 AES 256 GCM 96 密钥(来自 Hashicorp Vault)加密数据? - How can I encrypt data with an already generated AES 256 GCM 96 key (coming from Hashicorp Vault)? 我如何将生成的 AES 密钥从 Diffie-Hellman 类添加到我使用密钥的类中 - How can i add generated AES key from Diffie-Hellman class to the class where i use the key 如何保护我的 Java AES 加密密钥 - How do I protect my Java AES encryption key 如何使用JavaKeyStore将AES密钥存储在数据库中,目前我将密钥存储在扩展名为.JCEKS的文件夹中, - How to store the AES Key in database using JavaKeyStore, currently i am storing the key in a folder with .JCEKS extension, 如何在Java中为AES算法创建自己的密钥? - How can I create my own keys for the AES algorithm in Java? 我们可以在AES或DES中使用相同的密钥吗 - can we used same key in AES or DES 如何在Spring JPA中指定主键可以为null - How to specify that a primary key can be null in Spring jpa 如果我们用AES密钥包装256位AES密钥,那么包装的密钥的大小可以超过32个字节吗? - If we wrap a 256 bit AES key with AES key, then size of a wrapped key can be more than 32 bytes? 如何指定区域日期格式? - How can I specify the regional date format?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM