Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PBEWithMD5和DES算法的Java加密_Java_Android_Encryption_Des - Fatal编程技术网

使用PBEWithMD5和DES算法的Java加密

使用PBEWithMD5和DES算法的Java加密,java,android,encryption,des,Java,Android,Encryption,Des,我正在尝试在Java服务器和Android客户端之间进行加密。经过一些研究 以下是我的加密设置: public static String encryptionAlgoirthm = "DES"; public static short encryptionBitCount = 128; public static String hashingAlgorithm = "PBEWithMD5AndDES"; public static short hashingCount = 512; publi

我正在尝试在Java服务器和Android客户端之间进行加密。经过一些研究

以下是我的加密设置:

public static String encryptionAlgoirthm = "DES";
public static short encryptionBitCount = 128;
public static String hashingAlgorithm = "PBEWithMD5AndDES";
public static short hashingCount = 512;
public static String cipherTransformation = "DES/CBC/PKCS5Padding";
但是,当尝试在我的CentOS VPS上运行服务器时,我得到以下信息:

未找到提供程序[gnu.javax.security.auth.callback.GnuCallbacks:name=gnu-CALLBACKS version=2.1]中[SecretKeyFactory]类型的算法[PBEWithMD5AndDES]。

代码如下:

    KeySpec keySpec = new PBEKeySpec(EncryptionSettings.password, EncryptionSettings.salt, EncryptionSettings.hashingCount, EncryptionSettings.encryptionBitCount);
    SecretKey tmpKey = null;

    try
    {
        tmpKey = SecretKeyFactory.getInstance(EncryptionSettings.hashingAlgorithm).generateSecret(keySpec);
    }
    catch (final InvalidKeySpecException e)
    {
        Console.writeFatalError("Unable to generate key: invalid key specification");
    } 
    catch (final NoSuchAlgorithmException e)
    {
        Console.writeFatalError("Unable to generate key: encryption algorithm not supported - " + e.getMessage());
    }

如何修复此问题?

看起来您正在使用GNU JRE,但它没有JCE。您可以通过下载JCE并将其添加为提供者来解决此问题

Security.addProvider(new BouncyCastleProvider());
还要注意,您的
encryptionBitCount
看起来可疑,因为DES有一个56位的固定密钥sice


DES和MD5被认为是过时的,您可能希望尝试AES作为密码,SHA作为散列。bouncy castle API提供了一个算法
PBewithsha和128位AES-CBC-BC
,这可能会起到作用。

如果粘贴了代码,则拼写错误“
EncryptionalGoirTM