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;
}
}
這就是我得到的 - 導入org.apache.commons無法解析 –
添加了commons-codec-1.4.jar來修復。 –
我無法找到合適的替代 yte [] decordedValue = new BASE64Decoder()。decodeBuffer(encryptedData); 你可以推薦一些方法在commons解碼器的方法decodeBuffer? – bali208