Rijndael在Java中的支持 [英] Rijndael support in Java

查看:217
本文介绍了Rijndael在Java中的支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要在Java中进行一些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?

编辑:

它需要是开源的。基本上,它只是使用Rijndael的数据的标准加密/解密。

It would need to be open source. Essentially, it's just standard encrypt / decrypt of data using Rijndael.

推荐答案

Java包括AES开箱即用。 Rijndael是AES。您不需要任何外部库。你只需要这样的:

Java includes AES out of the box. Rijndael is AES. You don't need any external libraries. You just need something like this:

byte[] sessionKey = null; //Where you get this from is beyond the scope of this post
byte[] iv = null ; //Ditto
byte[] plaintext = null; //Whatever you want to encrypt/decrypt
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
//You can use ENCRYPT_MODE or DECRYPT_MODE
cipher.calling init(Cipher.ENCRYPT_MODE, new SecretKeySpec(sessionKey, "AES"), new IvParameterSpec(iv));
byte[] ciphertext = cipher.doFinal(plaintext);

这就是加密/解密。如果你正在处理大量的数据,那么你最好读取16个字节的倍数的块,并调用update而不是doFinal(你只需在最后一个块上调用doFinal)。

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).

这篇关于Rijndael在Java中的支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆