本文介绍了NoSuchProviderException当用3DES加密字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Java。我跟着这个加密和解密使用3DES算法。

I am new to Java. I followed this tutorial about Encryption and Decryption using 3DES algorithm.

我已经实现这样的:


  1. 创建一个类,并放置在上面的链接提供的3DES code。

  2. 在调用下面上面的链接加密方法:

  1. Created a class and placed the 3DES code provided in the above link.
  2. Called the encrypt method in the above link as below:

String encryptedPassword = Encrypter.encrypt(edtText.getText().toString()); 


我得到在logcat的例外如下:

I am getting the exception in logcat as below:

 05-02 15:19:10.804: W/System.err(4445): java.security.NoSuchProviderException: Provider not available: SunJCE
    05-02 15:19:10.820: W/System.err(4445):     at javax.crypto.Cipher.getInstance(Cipher.java:209)
    05-02 15:19:10.820: W/System.err(4445):     at com.example.utilities.Encrypter.encrypt(Encrypter.java:46)
    05-02 15:19:10.820: W/System.err(4445):     at com.example.screens.RegisterScreen.onClick(RegisterScreen.java:152)
    05-02 15:19:10.820: W/System.err(4445):     at android.view.View.performClick(View.java:2485)
    05-02 15:19:10.820: W/System.err(4445):     at android.view.View$PerformClick.run(View.java:9080)
    05-02 15:19:10.828: W/System.err(4445):     at android.os.Handler.handleCallback(Handler.java:587)
    05-02 15:19:10.828: W/System.err(4445):     at android.os.Handler.dispatchMessage(Handler.java:92)
    05-02 15:19:10.828: W/System.err(4445):     at android.os.Looper.loop(Looper.java:130)
    05-02 15:19:10.828: W/System.err(4445):     at android.app.ActivityThread.main(ActivityThread.java:3687)
    05-02 15:19:10.835: W/System.err(4445):     at java.lang.reflect.Method.invokeNative(Native Method)
    05-02 15:19:10.835: W/System.err(4445):     at java.lang.reflect.Method.invoke(Method.java:507)
    05-02 15:19:10.835: W/System.err(4445):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
    05-02 15:19:10.835: W/System.err(4445):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
    05-02 15:19:10.835: W/System.err(4445):     at dalvik.system.NativeStart.main(Native Method)

请帮助我。如何解决这个....

Please help me. How to solve this....

推荐答案

对不起,我是懒惰。行

Cipher ecipher = Cipher.getInstance("DESede/CBC/PKCS5Padding","SunJCE");

显示您指定一个特定的供应商。通常你会希望有一个很好的理由这样做,例如,你可能被要求使用符合FIPS的供应商。 SunJCE提供没有在Android上存在。只要使用默认的供应商,你留下了这样的说法得到根本。因此,尝试:

shows that you are specifying a particular provider. Normally you would want a very good reason for doing this, for example you might be required to use a FIPS-compliant provider. The SunJCE provider does not exist on Android. Just use the default provider, which you get simply by leaving out that argument. So try:

Cipher ecipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");

同样,改变

Cipher dcipher = Cipher.getInstance("DESede/CBC/PKCS5Padding","SunJCE");

Cipher dcipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");

这篇关于NoSuchProviderException当用3DES加密字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 02:15