Java 默认加密/AES 行为
有谁知道默认的 Java 加密行为的用途是什么:
SecretKeySpec localSecretKeySpec = new SecretKeySpec(arrayOfByte, "AES");
Cipher localCipher = Cipher.getInstance("AES");
具体来说,我希望了解这些类如何生成 IV,以及仅指定“AES”时的默认加密模式是什么。谢谢。
Does anyone know what the default Java crypto behavior is for:
SecretKeySpec localSecretKeySpec = new SecretKeySpec(arrayOfByte, "AES");
Cipher localCipher = Cipher.getInstance("AES");
Specifically I am looking to understand how those classes generate the IV, as well as what is the default encryption mode when just specifying "AES". Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对于 Oracle JDK 7(已测试),AES 的默认密码是 AES/ECB/PKCS5Padding。 Java安全文档没有提到这一点(http://docs.oracle.com/javase/6/docs/technotes/guides/security/StandardNames.html#algspec),必须进行一些JUnit测试才能找出答案。
For Oracle JDK 7 (tested), the default cipher for AES is AES/ECB/PKCS5Padding. The Java Security documentation doesn't mention about this though (http://docs.oracle.com/javase/6/docs/technotes/guides/security/StandardNames.html#algspec), have to do some JUnit testing to find out.
详细信息是特定于提供商的。 JCA 参考指南 指出:
我总是使用完整的形式(算法/模式/填充),不仅因为我认为在实现中遗漏这样的“细节”是不好的做法,而且还为了实现独立于所选提供者(通常是一个提供者)的密文。加密存储/传输,则无法确定稍后/另一端将使用相同的提供程序)。
The details are provider specific. The JCA Reference Guide says that:
I would always use the full form (algorithm/mode/padding), not only because I think that leaving out such "details" to the implementation is bad practice, but also for achieving a ciphertext that is independent of the chosen provider (one usually encrypts for storage/transmission, then one cannot be sure that the same provider will be used later/on the other end).
这些详细信息是特定于提供商的,依赖默认模式和填充可能非常危险。如果您对当前与 Java 捆绑的默认提供程序使用的值感兴趣,您将必须寻找相关算法的源代码。例如,它用于 RSA 算法的默认值位于此处。另外,Java™ 加密体系结构 (JCA) 参考指南有相当多的信息可以回答你们中的一些其他问题。
Those details are provider specific, and relying on the default mode and padding can be very dangerous. If you are interested in what the values that the default provider currently bundled with Java uses you'll have to hunt down the source code for the algorithm in question. For instance, the default values it uses for the RSA algorithm are here. Also, the Java™ Cryptography Architecture (JCA) Reference Guide has quite a bit of information that could answer some of you other questions.
这取决于提供商。不同的提供者可能有不同的默认参数。这是 Java 8 的链接。
https: //docs.oracle.com/javase/8/docs/technotes/guides/security/SunProviders.html#ciphertrans
因此,您不应只使用 AES,而应指定模式和填充。此外,虽然 getInstance 方法可以有提供者的另一个参数,但不建议这样做,因为
It depends on the Providers. Different providers might have different default parameters. This is the link for Java 8.
https://docs.oracle.com/javase/8/docs/technotes/guides/security/SunProviders.html#ciphertrans
Therefore, you should not just use AES but specify the mode and padding. Furthermore, although the getInstance method could have another parameter for the provider, this is not recommended because