简体   繁体   English

PBKDF2WithHmacSHA512 SecretKeyFactory 不可用

[英]PBKDF2WithHmacSHA512 SecretKeyFactory not available

This is a really odd error.这是一个非常奇怪的错误。 On two machines, the code is running perfectly.在两台机器上,代码运行完美。 I just set this up on a brand new machine and this isn't working.我只是在一台全新的机器上设置了它,但它不起作用。 I'm getting the following error when running the script;运行脚本时出现以下错误;

java.lang.RuntimeException: java.security.NoSuchAlgorithmException: PBKDF2WithHmacSHA512 SecretKeyFactory not available

The line of code that is causing the error is;导致错误的代码行是;

SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance( "PBKDF2WithHmacSHA512" );

Using JDK 1.7.0使用 JDK 1.7.0

The code is all compiling correctly, it is just failing at run time on this line.代码全部正确编译,只是在此行的运行时失败。 I have a feeling this is some how related to a JAR file that is different or a JDK that is slightly different, but after checking everything across the different machines, everything looks identical.我有一种感觉,这与不同的 JAR 文件或略有不同的 JDK 有某种关联,但是在检查了不同机器上的所有内容后,一切看起来都相同。

Thoughts?想法?

Support for PBKDF2WithHmacSHA512 was added in Java 8, it is not available in Java 7 by default (Java 7 itself only supports PBKDF2WithHmacSHA1). Java 8 中添加了对 PBKDF2WithHmacSHA512 的支持,默认情况下在 Java 7 中不可用(Java 7 本身仅支持 PBKDF2WithHmacSHA1)。

Compare:比较:

  • SecretKeyFactory Algorithms for Java 7 Java 7 的SecretKeyFactory算法

    PBKDF2WithHmacSHA1 Constructs secret keys using the Password-Based Key Derivation Function function found in PKCS #5 v2.0. PBKDF2WithHmacSHA1使用 PKCS #5 v2.0 中的基于密码的密钥派生函数函数构造密钥。

  • SecretKeyFactory Algorithms for Java 8 Java 8 的SecretKeyFactory算法

    PBKDF2With<prf> Password-based key-derivation algorithm found in PKCS #5 2.0 using the specified pseudo-random function ( <prf> ). PBKDF2With<prf>使用指定的伪随机函数 ( <prf> ) 在 PKCS #5 2.0 中找到的基于密码的密钥派生算法。 Example: PBKDF2WithHmacSHA256.示例:PBKDF2WithHmacSHA256。

So you need to either upgrade to Java 8, or downgrade to PBKDF2WithHmacSHA1, or check if there is a JCE provider that provides PBKDF2WithHmacSHA512 for Java 7 (for example, Bouncy Castle).因此,您需要升级到 Java 8,或降级到 PBKDF2WithHmacSHA1,或者检查是否有 JCE 提供程序为 Java 7 提供 PBKDF2WithHmacSHA512(例如,Bouncy Castle)。

If your code is running ok on another machine with Java 7, then check if lib/ext of that Java install contains additional libraries, for example Bouncy Castle has a JCE provider that supports PBKDF2WithHmacSHA512.如果您的代码在另一台装有 Java 7 的机器上运行正常,则检查该 Java 安装的lib/ext是否包含其他库,例如 Bouncy Castle 有一个支持 PBKDF2WithHmacSHA512 的 JCE 提供程序。 In that case, you will need to include that same library in the Java install of the other machine.在这种情况下,您需要在另一台机器的 Java 安装中包含相同的库。

I was getting the same error because I was running a unit test with PowerMockRunner , ie:我遇到了同样的错误,因为我正在使用PowerMockRunner运行单元测试,即:

@RunWith(PowerMockRunner.class)
public class MyTest {
    //...
}

Removing @RunWith(PowerMockRunner.class) solved the issue for me.删除@RunWith(PowerMockRunner.class)为我解决了这个问题。

If any Android developer came here with the same issue, continue reading.如果有任何Android 开发人员遇到同样的问题,请继续阅读。

I was having the same problem.我遇到了同样的问题。

NoSuchAlgorithmException: SecretKeyFactory PBKDF2withHmacSHA256 implementation not found NoSuchAlgorithmException:未找到 SecretKeyFactory PBKDF2withHmacSHA256 实现

I tried to upgrade from Java7 to Java8 but it didn't helped.我尝试从Java7升级到Java8但没有帮助。 Strange was that it was working on some devices and failing on the others.奇怪的是,它在某些设备上运行正常,而在其他设备上却失败了。 You'll think that SecretKeyFactory is in javax so it's JDK part and has nothing to do with Android API level.你会认为SecretKeyFactoryjavax所以它是JDK一部分,与 Android API 级别无关。

Thing is that on Android system there are various security providers for different API levels and SecretKeyFactory provides implementations of algorithms from that providers, and based on the information here and here PBKDF2withHmacSHA512 is available from API 26 only.事实是,在 Android 系统上,有针对不同 API 级别的各种安全提供程序,而SecretKeyFactory提供了来自该提供程序的算法的实现,并且基于此处此处的信息, PBKDF2withHmacSHA512仅可从 API 26 获得。 If you want to have functionality working on older Android systems you can switch to PBKDF2withHmacSHA1 which is available from API 10 or do/use some custom implementations of desired ones.如果您想在较旧的 Android 系统上使用功能,您可以切换到 API 10 中提供的PBKDF2withHmacSHA1 ,或者执行/使用所需的一些自定义实现。

Other option is copy pasting algorithm's code from https://gist.github.com/jtan189/3804290 and put in your project.其他选项是https://gist.github.com/jtan189/3804290复制粘贴算法的代码并放入您的项目中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SecretKeyFactory.getInstance(“PBKDF2WithHmacSHA512”)抛出NoSuchAlgorithmException - SecretKeyFactory.getInstance(“PBKDF2WithHmacSHA512”) throws NoSuchAlgorithmException PBKDF2WithHmacSHA512 对比。 PBKDF2WithHmacSHA1 - PBKDF2WithHmacSHA512 Vs. PBKDF2WithHmacSHA1 PBKDF2WithHmacSHA512 抛出 NoSuchAlgorithmException - PBKDF2WithHmacSHA512 throwing NoSuchAlgorithmException 用于 AES 加密的 PHP 中的 PBKDF2WithHmacSHA512 Java 等效项 - PBKDF2WithHmacSHA512 Java equivalent in PHP for AES encryption 使用PBKDF2WithHmacSHA512进行密码保护在生产设置(AWS)上花费了大量处理时间 - password protection using PBKDF2WithHmacSHA512 is taking lot of processing time on production setup(AWS) 来自“PBKDF2WithHmacSHA512”的java散列与python CRYPT(digest_alg =&#39;pbkdf2(1000,20,sha512)&#39;,salt = True)(密码)[0]不同 - java hash from “PBKDF2WithHmacSHA512” is differs from python CRYPT(digest_alg='pbkdf2(1000,20,sha512)', salt=True)(password)[0]) java.security.NoSuchAlgorithmException:算法PBKDF2WithHmacSHA1不可用 - java.security.NoSuchAlgorithmException: Algorithm PBKDF2WithHmacSHA1 not available PBKDF2WithHmacSHA1令人困惑 - PBKDF2WithHmacSHA1 confusing PBKDF2WithHmacSHA1 Java 到 Swift 3 - PBKDF2WithHmacSHA1 Java to Swift 3 Java PBKDF2WithHmacSHA1问题 - Java PBKDF2WithHmacSHA1 issue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM