我在服务器端插入了会话ID,但是当我尝试在客户端解密会话ID时,会出现一些错误。请任何人都可以帮助解决该错误。
public static String decrypt(String sessionId)
{
try
{
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
final SecretKeySpec secretKey = new SecretKeySpec(key, "AES");
cipher.init(Cipher.DECRYPT_MODE, secretKey);
final String decryptedSessionId = new String(cipher.doFinal(Base64.decodeBase64(sessionId)));
return decryptedSessionId;
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
即将出现的错误是:
JRE仿真库中没有类'javax.crypto.Cipher',因此无法在“某些” GWT模块的客户端代码中使用。
此检查报告JRE类库中不存在的JDK类的客户端代码中的使用情况。
我使用的加密方法是:
public static String encrypt(String sessionId)
{
try
{
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
final SecretKeySpec secretKey = new SecretKeySpec(key, "AES");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
final String encryptedSessionId = Base64.encodeBase64String(cipher.doFinal(sessionId.getBytes()));
return encryptedSessionId;
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
我是新手,请帮助我解决错误
最佳答案
好吧,您不能在客户端的GWT编码中使用Java标准加密库。不支持。
使用gwt-crypto加密/解密必要的内容。
GWT加密中的GWT客户端不支持AES,但是您可以使用TripleDES。 TripleDES也是非常安全的实现。
关于java - 使用Java在客户端解密,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45737528/