如何使用 Rijndael 和 256 位的块大小进行加密或解密?

2023-01-16Java开发问题
4

本文介绍了如何使用 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 位的块大小进行加密或解密?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

如何使用 JAVA 向 COM PORT 发送数据?
How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)...
2024-08-25 Java开发问题
21

如何使报表页面方向更改为“rtl"?
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)...
2024-08-25 Java开发问题
19

在 Eclipse 项目中使用西里尔文 .properties 文件
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)...
2024-08-25 Java开发问题
18

有没有办法在 Java 中检测 RTL 语言?
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)...
2024-08-25 Java开发问题
11

如何在 Java 中从 DB 加载资源包消息?
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)...
2024-08-25 Java开发问题
13

如何更改 Java 中的默认语言环境设置以使其保持一致?
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)...
2024-08-25 Java开发问题
13