問題描述
我們需要用 Java 進行一些 Rijndael 開發(fā).
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?
它需要是開源的.本質(zhì)上,它只是使用 Rijndael 對數(shù)據(jù)進行標準加密/解密.
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.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(sessionKey, "AES"), new IvParameterSpec(iv));
byte[] ciphertext = cipher.doFinal(plaintext);
就是這樣,用于加密/解密.如果您正在處理大量數(shù)據(jù),那么您最好讀取 16 字節(jié)的倍數(shù)的塊并調(diào)用 update 而不是 doFinal(您只需在最后一個塊上調(diào)用 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).
這篇關(guān)于Java 中的 Rijndael 支持的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!