Java 中的 Rijndael 支持
我们需要用 Java 进行一些 Rijndael 开发。
有什么对我们有帮助的文章、图书馆等建议吗?
有关密钥库维护以及如何安全存储密钥的任何指示吗?
编辑:
它需要是开源的。 本质上,它只是使用 Rijndael 对数据进行标准加密/解密。
We have a requirement to do some Rijndael development in Java.
Any recommendations for articles, libraries etc. that would help us?
Any pointers to keystore maintenance and how store the keys securely?
Edit:
It would need to be open source. Essentially, it's just standard encrypt / decrypt of data using Rijndael.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Java 包含开箱即用的 AES。 Rijndael 是 AES。 您不需要任何外部库。 你只需要这样的东西:
就是这样,用于加密/解密。 如果您正在处理大量数据,那么您最好读取 16 字节倍数的块并调用 update 而不是 doFinal (您只需在最后一个块上调用 doFinal )。
Java includes AES out of the box. Rijndael is AES. You don't need any external libraries. You just need something like this:
And that's it, for encryption/decryption. If you are processing large amounts of data then you're better off reading chunks that are multiples of 16 bytes and calling update instead of doFinal (you just call doFinal on the last block).
对于一个很棒的免费库,我强烈推荐 BouncyCastle。 它得到积极维护,质量很高,并且有一个很好的数组代码示例。 对于参考文档,您必须更多地依赖一般 JCE 文档。
我不能说我们使用什么库来满足 FIPS 认证要求。 但 CryptoJ 还有其他更便宜的替代品。
一般来说,我建议为使用 Rijndael 等对称密码加密的每条消息生成一个新密钥,然后使用 RSA 等非对称算法加密该密钥。 这些私钥可以存储在受密码保护的基于软件的密钥存储中,例如 PKCS #12 或 Java 的“JKS”,或者为了更好的安全性,存储在“智能卡”硬件令牌或其他加密硬件模块上。
For a great free library, I highly recommend BouncyCastle. It is actively maintained, high quality, and has a nice array of code examples. For reference documentation, you'll have to rely more on the general JCE docs.
I can't say what library we use to meet FIPS certification requirements. But there are alternatives to CryptoJ that are much, much cheaper.
In general, I'd recommend generating a new key for each message you encrypt with a symmetric cipher like Rijndael, and then encrypting that key with an asymmetric algorithm like RSA. These private keys can be stored in a password-protected, software-based key store like PKCS #12 or Java's "JKS", or, for better security, on "smart card" hardware token or other crypto hardware module.
正如我的公司最近发现的那样,AES 并不完全是 Rijndael。 AES 的限制是密钥必须为 128、192 或 256 位 - 然而,Rijndael 也允许使用 160 和 224 位的密钥。
正如上面的 erickson 所指出的,BouncyCastle 提供了一个 Rijndael 对象,它支持额外的密钥长度:128/160/192/224/256 位。 具体来说,看一下轻量级API。
Gnu-crypto 是另一个开源库 - 但是,它也不提供对 160 和 224 位密钥的支持。
因此,如果您专门寻求 Rijndael 的全面支持,那么 BouncyCastle 是我迄今为止找到的唯一支持。
As my company recently found out, AES is not quite Rijndael. AES has the restriction that keys MUST be 128, 192, or 256 bit - however, Rijndael allows for keys that are 160 and 224 as well.
As indicated by erickson above, BouncyCastle provides a Rijndael object that DOES support the additional key lengths: 128/160/192/224/256 bits. Specifically, take a look at the lightweight API.
Gnu-crypto is another open source library - however, it also does NOT provide support for 160 and 224 bit keys.
So, if you are specifically looking for full Rijndael support, then BouncyCastle is the only one I've found so far.
javax.crypto 具有 AES 支持: http://java.sun.com /developer/technicalArticles/Security/AES/AES_v1.html
对于安全密钥存储,通常的方法是使用加密哈希函数从用户输入(密码)中导出加密密钥,并使用导出的密钥加密钥匙串。 或者,如果您只需要一个密钥,则可以使用派生密钥本身。
始终记住,系统的安全性与所使用的哈希函数的强度直接相关。 使用加密安全哈希函数,如果可能的话,再加上盐,并进行多次哈希处理(例如数百次)。
话虽如此,这个问题非常模糊。
javax.crypto has AES support: http://java.sun.com/developer/technicalArticles/Security/AES/AES_v1.html
As for secure key storage, the usual method is to derive an encryption key from user input (a passphrase) using a cryptographic hash function, and use the derived key to encrypt the keychain. Or, if you only need one key, you can use the derived key itself.
Always keep in mind that the security of the system is directly related to the strength of the hash function used. Use a cryptographically secure hash function, along with a salt if possible, and hash more than once (hundreds of times, for example).
That being said, the question is very vague.