I am trying to do some encryption stuff between a Java server and Android client. After some research, And
Here are my encryption settings:
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";
But when trying to run the server on my CentOS VPS I get the following:
Algorithm [PBEWithMD5AndDES] of type [SecretKeyFactory] from provider [gnu.javax.security.auth.callback.GnuCallbacks: name=GNU-CALLBACKS version=2.1] is not found.
Here is the code:
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());
}
How do I fix this?
Looks like you are using the GNU JRE and it doesn’t have a JCE in it. You can solve this by downloading the bouncy castle JCE and add it as a provider;
Note also that your
encryptionBitCountlooks suspicious as DES has a fixed key sice of 56 bits.DES and MD5 are considered obsolete, you might want to try AES for the cipher and SHA for the hashing instead. The bouncy castle API provides an algorithm
PBEWITHSHAAND128BITAES-CBC-BCwhich might do the trick.