gpt4 book ai didi

java - KeyGenerator 中 AES 与 DES 的 key 大小

转载 作者:行者123 更新时间:2023-12-02 02:27:11 25 4
gpt4 key购买 nike

我正在使用 javax.crypto.KeyGenerator 生成 key 。

下面是我的 AES 代码:

Key key = null;
SecureRandom rand = new SecureRandom();
KeyGenerator generator;
try {
generator = KeyGenerator.getInstance("AES");
generator.init(rand);
generator.init(128);
key = generator.generateKey();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
System.out.println("AES key is : ");
System.out.println(Base64.getEncoder().encodeToString(key.getEncoded()));

DES 代码:

Key key = null;
SecureRandom rand = new SecureRandom();
KeyGenerator generator;
try {
generator = KeyGenerator.getInstance("DES");
generator.init(rand);
generator.init(56);
key = generator.generateKey();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
System.out.println("DES key is : ");
System.out.println(Base64.getEncoder().encodeToString(key.getEncoded()));

正如您所见,当我使用 DES 时,我必须将 56 传递给 init() 方法,而不是 AES 中的 128。

有人可以解释一下为什么我不能使用 128 位以及这两种类型中哪种加密更可取?

最佳答案

AES 是 DES 的高级版本,具有更大的 key 大小。因此,如果您需要更安全的加密,那么使用 AES 应该是您的选择。

Data Encryption Standard (DES) : DES is an implementation of a Feistel Cipher. It uses 16 round Feistel structure. The block size is 64-bit. Though, key length is 64-bit, DES has an effective key length of 56 bits, since 8 of the 64 bits of the key are not used by the encryption algorithm (function as check bits only).

Advanced Encryption Standard(AES) :The more popular and widely adopted symmetric encryption algorithm likely to be encountered nowadays is the Advanced Encryption Standard (AES). It is found at least six time faster than triple DES. A replacement for DES was needed as its key size was too small. With increasing computing power, it was considered vulnerable against exhaustive key search attack. Triple DES was designed to overcome this drawback but it was found slow

关于java - KeyGenerator 中 AES 与 DES 的 key 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47647338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com