Java 中的 Rijndael 支持

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

问题描述

我们需要用 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.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).

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Reliable implementation of PBKDF2-HMAC-SHA256 for JAVA(PBKDF2-HMAC-SHA256 for JAVA 的可靠实现)
Correct way to sign and verify signature using bouncycastle(使用 bouncycastle 签名和验证签名的正确方法)
Creating RSA Public Key From String(从字符串创建 RSA 公钥)
Why java.security.NoSuchProviderException No such provider: BC?(为什么 java.security.NoSuchProviderException 没有这样的提供者:BC?)
Generating X509 Certificate using Bouncy Castle Java(使用 Bouncy Castle Java 生成 X509 证书)
How can I get a PublicKey object from EC public key bytes?(如何从 EC 公钥字节中获取 PublicKey 对象?)