2012-01-10 165 views
2

我想在Java服務器和Android客戶端之間做一些加密工作。經過一番研究,並使用PBEWithMD5AndDES算法進行Java加密

這裏是我的加密設置:

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

如果你粘貼的代碼,那麼你拼錯「'encryptionAlgoirthm'」 – rossum 2012-01-10 12:36:10

回答

1

看起來你使用的是GNU JRE,它沒有JCE。您可以通過下載bouncy castle JCE並將其添加爲提供程序來解決此問題;

​​

還請注意,您的encryptionBitCount看起來可疑的DES具有56位的固定密鑰SICE。

DES和MD5被認爲已經過時,您可能想要嘗試使用AES作爲密碼,而使用SHA作爲散列。充氣城堡API提供了一個算法PBEWITHSHAAND128BITAES-CBC-BC,它可以做到這一點。

相關問題