简体   繁体   English

PBKDF2WithHmacSHA512 抛出 NoSuchAlgorithmException

[英]PBKDF2WithHmacSHA512 throwing NoSuchAlgorithmException

I am writing an app in Eclipse for android.我正在 Eclipse 中为 android 编写一个应用程序。 I tried using PBKDF2WithHmacSHA1 at first to hash my passwords, which worked well.我首先尝试使用 PBKDF2WithHmacSHA1 来散列我的密码,效果很好。 But because of the weaknesses in SHA1, I decided to upgrade it to PBKDF2WithHmacSHA512.但是由于SHA1的弱点,我决定将其升级为PBKDF2WithHmacSHA512。 However, eclipse is now throwing a NoSuchAlgorithmException.但是,eclipse 现在抛出 NoSuchAlgorithmException。

SecretKeyFactory.getInstance("PBKDF2WithHmacSHA512") throws NoSuchAlgorithmException SecretKeyFactory.getInstance("PBKDF2WithHmacSHA512") 抛出 NoSuchAlgorithmException

I followed the instructions in the link above.我按照上面链接中的说明进行操作。 However, the java file linked in the question above requires the sun.crypto library, which I don't have on Eclipse.但是,上面问题中链接的 java 文件需要 sun.crypto 库,而我在 Eclipse 上没有。 I was also advised not to use Sun library, but to use java official library.还建议我不要使用 Sun 库,而是使用 java 官方库。

My question is, is there anyway of using PBKDF2WithHmacSHA512 on Eclipse?我的问题是,是否有在 Eclipse 上使用 PBKDF2WithHmacSHA512 的方法? Or if possible, can someone teach me how to break it into parts of doing the PBKDF2 first and then HmacSHA512 the result?或者,如果可能的话,有人可以教我如何将其分解为先执行 PBKDF2 的部分,然后再执行 HmacSHA512 的结果吗?

Thank you.谢谢你。

Be careful when using SecretKeyFactory in android, please check supported API version, you will be got exception if using the wrong version like bellow: https://developer.android.com/reference/javax/crypto/SecretKeyFactory在 android 中使用 SecretKeyFactory 时要小心,请检查支持的 API 版本,如果使用错误的版本会出现异常,如下所示: https : //developer.android.com/reference/javax/crypto/SecretKeyFactory

在此处输入图片说明

This exception is thrown when a particular cryptographic algorithm is requested but is not available in the environment.当请求特定的加密算法但在环境中不可用时会引发此异常。 So based on the requirement above 👆 if you also want to use this algorithm on the low android version, I would recommend you use Bouncy Castle Library.所以基于上面的需求👆,如果你也想在低安卓版本上使用这个算法,我会推荐你​​使用Bouncy Castle Library。

// Gradle

implementation 'org.bouncycastle:bcpkix-jdk15to18:1.70'
implementation 'org.bouncycastle:bcprov-jdk15to18:1.70'


// Use "PBKDF2WithHmacSHA512" with android O version and above

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  val skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA512")
  val pwSpec = PBEKeySpec(secret.toCharArray(), salt, iterations, keyLength)
  skf.generateSecret(pwSpec).encoded
}

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

相关问题 SecretKeyFactory.getInstance(“PBKDF2WithHmacSHA512”)抛出NoSuchAlgorithmException - SecretKeyFactory.getInstance(“PBKDF2WithHmacSHA512”) throws NoSuchAlgorithmException PBKDF2WithHmacSHA512 对比。 PBKDF2WithHmacSHA1 - PBKDF2WithHmacSHA512 Vs. PBKDF2WithHmacSHA1 PBKDF2WithHmacSHA512 SecretKeyFactory 不可用 - PBKDF2WithHmacSHA512 SecretKeyFactory not available 用于 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 ='pbkdf2(1000,20,sha512)',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