Android SecretKeyFactory问题.找不到实现? [英] Android SecretKeyFactory problems. Implementation not found?

查看:63
本文介绍了Android SecretKeyFactory问题.找不到实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个用于Android的应用程序,该应用程序使用加密来保存用户信息,但我无法弄清楚自己在做什么错.我正在尝试使用"PBKDF2WithHmacSHA1"算法创建SecretKeyFactory的实例,但是该应用程序会在程序的那一刻继续抛出异常(无论是在模拟器中还是在实际硬件上都无所谓).

代码:

  SecretKeyFactory secretFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); 

例外:

java.security.NoSuchAlgorithmException:SecretKeyFactory PBKDF2WithHmacSHA1找不到实现...

这是很奇怪的事情……如果我将这段代码用作常规Java应用程序进行编译,它将可以正常工作……不会引发任何异常,并且我可以创建加密文件(并对其进行解密)而不会出错.

我还尝试输入其他算法(例如AES,PBEWithHmacSHA1AndDESede,PBEWithMD5AndDES等),并且它们在代码的那一行都产生相同的错误/异常(针对Android编译时).

我安装了Java的最新版本(JDK 1.6.0.18),应用于Eclipse和插件的所有更新以及Android SDK的最新版本.我也在运行Windows 7 64位.

请帮助,在两天的互联网搜索中我没有找到答案.谢谢.

解决方案

它可能不是受支持的算法,也不是在Android上的命名方式.

您是否查看过javax.crypto类? https://developer.android.com/reference/javax/crypto/EncryptedPrivateKeyInfo.html

如果有帮助,这里是使用其他算法的示例. http://www.anddev.org/viewtopic.php?p=11737

顺便说一句,在此帖子中添加"from-irc"标签以获取Google回复. http://android-developers.blogspot.com/2010/01/irc-offce-hours-update.html

I'm trying to create an application for Android that uses encryption to save user information and I cannot figure out what I'm doing wrong. I'm trying to create an instance of the SecretKeyFactory using the "PBKDF2WithHmacSHA1" algorithm, but the application keeps on throwing exceptions at that point in the program (it doesn't matter if it's in the emulator or on real hardware).

Code:

SecretKeyFactory secretFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");

Exception:

java.security.NoSuchAlgorithmException: SecretKeyFactory PBKDF2WithHmacSHA1 implementation not found ...

Here's the weird thing... if I take this code and compile it as a regular Java application, it works... no exceptions are thrown and I can create encrypted files (and decrypt them) without errors.

I have also tried entering other algorithms (e.g. AES, PBEWithHmacSHA1AndDESede, PBEWithMD5AndDES, etc.) and they all produce the same error/exception at that line in the code (when compiling for Android).

I have the latest version of Java installed (JDK 1.6.0.18) , all updates applied to Eclipse and plug-ins, and the latest version of the Android SDK. I'm also running Windows 7 64-bit.

Please help, I have not found an answer to this in two days of Internet searching. Thanks.

解决方案

It might just not be a supported algorithm or that naming of it on Android.

Have you looked around the javax.crypto classes? https://developer.android.com/reference/javax/crypto/EncryptedPrivateKeyInfo.html

Here is an example using a different algorithm if that helps. http://www.anddev.org/viewtopic.php?p=11737

btw, add a "from-irc" tag to this post to get a google response. http://android-developers.blogspot.com/2010/01/irc-offce-hours-update.html

这篇关于Android SecretKeyFactory问题.找不到实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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