我在服务器端加密会话Id,但是当我试图在客户端解密会话ID时,会出现一些错误。请任何人都可以帮助解决这个错误。使用java在客户端解密使用java
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;
}
即未来的错误是: 类“javax.crypto.Cipher中”不存在于JRE仿真库,因此它不能在“一些” 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将代码移动到服务器端(RPC)时。这样就不需要仿真了。也许你可以在客户端使用JDK。 –
**切勿使用[ECB模式](https://crypto.stackexchange.com/q/14487/13022)**。它是确定性的,因此不具有语义安全性。您至少应该使用[CBC](https://crypto.stackexchange.com/q/22260/13022)或[CTR](https://crypto.stackexchange.com/a/2378/)这样的随机模式。 13022)。最好对密文进行身份验证,以便像[padding oracle attack](https://crypto.stackexchange.com/q/18185/13022)这样的攻击是不可能的。这可以通过验证模式(如GCM或EAX)或[加密 - 然后MAC](https://crypto.stackexchange.com/q/202/13022)方案完成。 –