使用Java crypto导致NoSuchAlgorithmException [英] Using Java crypto leads to NoSuchAlgorithmException

查看:524
本文介绍了使用Java crypto导致NoSuchAlgorithmException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码的加密部分。它编译良好,但在运行时失败了这个异常:

Here's the encryption portion of my code. It compiles fine but fails with that exception at runtime:

import java.util.Random;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;

...

byte[] salt = new byte[8];
Random rand = new Random();
rand.nextBytes(salt);

PBEKeySpec keySpec = new PBEKeySpec(password.toCharArray());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithSHAAndTwofish-CBC");
SecretKey key = keyFactory.generateSecret(keySpec);
PBEParameterSpec paramSpec = new PBEParameterSpec(salt, 1000);

Cipher cipher = Cipher.getInstance("PBEWithSHAAndTwofish-CBC");
cipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
byte[] ciphertext = cipher.doFinal(plaintext);

这个算法不是Java 1.5吗?我不介意使用另一种算法,我只是不知道什么是可用的。我希望我不必使用外部库像bouncycastle,因为我努力的天试图得到它的工作无效(通过包括在我的.jar应用程序,它触发无效的签名文件摘要错误) 。

Does this algorithm not come with Java 1.5? I don't mind using another algorithm, I just don't know what is available. I hope I don't have to use an external library like bouncycastle, because I've struggled for days trying to get it working to no avail (by including it in my .jar application it triggers an "Invalid signature file digest" error).

推荐答案

看起来你可能需要使用一些其他的密码,如果你不想依赖一些外部库如BouncyCastle。

Looks like you may have to use some other cipher if you do not wish to rely on some external library like BouncyCastle.

请参阅有关Sun crypto providers的文档,以了解有关直接开箱即用的支持的更多详细信息。

See the documentation about Sun crypto providers for more details about what's supported straight out of the box.

这篇关于使用Java crypto导致NoSuchAlgorithmException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆