使用PBEWithMD5和DES算法的Java加密
我正在尝试在Java服务器和Android客户端之间进行加密。经过一些研究 以下是我的加密设置:使用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
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
”