2012-10-08 50 views
2

試圖加密我在GAE 這一碰到sun.misc.BASE64Encoder不是由谷歌App Engine的Java運行時環境支持

「sun.misc.BASE64Encoder不是由谷歌App Engine的Java運行時環境的支持」任何人都可以幫助我使用哪個包? 我正試圖獲得AES加密。 這裏是我正在使用的代碼。

import java.security.*; 
import java.security.spec.InvalidKeySpecException; 
import javax.crypto.*; 
import javax.crypto.spec.SecretKeySpec; 


import sun.misc.*; 

public class AESencrp { 
private static final String ALGO = "AES"; 
private static final byte[] keyValue = 
    new byte[] { 'T', 'h', 'e', 'B', 'e', 's', 't','S', 'e', 'c', 'r','e', 't', 'K', 'e', 'y' }; 

public static String encrypt(String Data) throws Exception { 
    Key key = generateKey(); 
    Cipher c = Cipher.getInstance(ALGO); 
    c.init(Cipher.ENCRYPT_MODE, key); 
    byte[] encVal = c.doFinal(Data.getBytes()); 
    String encryptedValue = new BASE64Encoder().encode(encVal); 
    return encryptedValue; 
} 

public static String decrypt(String encryptedData) throws Exception { 
    Key key = generateKey(); 
    Cipher c = Cipher.getInstance(ALGO); 
    c.init(Cipher.DECRYPT_MODE, key); 
    byte[] decordedValue = new BASE64Decoder().decodeBuffer(encryptedData); 
    byte[] decValue = c.doFinal(decordedValue); 
    String decryptedValue = new String(decValue); 
    return decryptedValue; 
} 

private static Key generateKey() throws Exception { 
    Key key = new SecretKeySpec(keyValue, ALGO); 
    return key; 
} 



} 

回答

3

您可以嘗試Commons Codec。有一個類Base64提供Base64編碼和解碼。

sun.*軟件包不是受支持的公共接口的一部分。查看article瞭解更多詳情。

+1

這就是我得到的 - 導入org.apache.commons無法解析 –

+1

添加了commons-codec-1.4.jar來修復。 –

+0

我無法找到合適的替代 yte [] decordedValue = new BASE64Decoder()。decodeBuffer(encryptedData); 你可以推薦一些方法在commons解碼器的方法decodeBuffer? – bali208

相關問題