我正在尝试在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上运行服务器时,我得到以下结果:
Algorithm [PBEWithMD5AndDES] of type [SecretKeyFactory] from provider [gnu.javax.security.auth.callback.GnuCallbacks: name=GNU-CALLBACKS version=2.1] is not found.
以下是代码:
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());
}
我该如何解决这个问题?
答案 0 :(得分:1)
看起来你正在使用GNU JRE并且它没有JCE。您可以通过下载bouncy castle JCE并将其添加为提供商来解决此问题;
Security.addProvider(new BouncyCastleProvider());
另请注意,您的encryptionBitCount
看起来很可疑,因为DES的固定密钥为56位。
DES和MD5被认为已过时,您可能希望尝试使用AES作为密码,而使用SHA作为散列。充气城堡API提供了一种算法PBEWITHSHAAND128BITAES-CBC-BC
,可以解决这个问题。