How to encrypt or decrypt with Rijndael and a block-size of 256 bits?(如何使用 Rijndael 和 256 位的块大小进行加密或解密?)
问题描述
出于某些原因,我需要使用 256 位块大小而不是使用 128 位块大小的 AES 来实现 Rijndael 解/压缩(原因:数据在 PHP 中使用 Rijndael 进行加密...).
For certain reasons I need to implement Rijndael de/compression with a blocksize of 256 bits instead of AES which uses a block size of 128 bits (reason: data is encrypted in PHP using Rijndael...).
如何更改密码的块大小?
How can I change the block-size for a cipher?
如果我只是用 "RIJNDAEL/CFB/PKCS5Padding" 得到一个密码并尝试用 256 位初始化一个 IV,我会得到一个异常,因为块大小只有 128 位.
p>
If i just get a cipher with "RIJNDAEL/CFB/PKCS5Padding"
and try to initialize a IV with 256 bits I get an exception, because the block-size is only 128 bits.
推荐答案
除了 128 位块大小的 Rijndael 之外,任何 Sun JCE 提供程序都不支持:这是 AES 算法.要获得 256 位块大小的 rijndael,您将不得不去其他地方.我建议使用 Bouncycastle java 库.RijndaelEngine 类有一个构造函数接受以位为单位的块大小.大多数人发现 PaddedBufferedBlockCipher 类与合适的填充一起使用时更方便,例如
There is no support in any of the Sun JCE providers for anything other than Rijndael with the 128-bit blocksize: this is the AES algorithm. To get rijndael with the 256-bit blocksize you will have to go somewhere else. I suggest the Bouncycastle java library. The RijndaelEngine class has a constructor that accepts a block size in bits. Most people find the PaddedBufferedBlockCipher class to be more convenient when used with suitable padding, e.g.
PaddedBufferedBlockCipher c = new PaddedBufferedBlockCipher(new RijndaelEngine(256), new PKCS7Padding());
这篇关于如何使用 Rijndael 和 256 位的块大小进行加密或解密?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 Rijndael 和 256 位的块大小进行加密或解


- Eclipse 插件更新错误日志在哪里? 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01