在客户端使用java解密 [英] Decryption at client side using java

查看:226
本文介绍了在客户端使用java解密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在服务器端加密会话ID,但当我试图在客户端解密会话ID时,会出现一些错误。任何人都可以帮助解决错误。

  public static String decrypt(String sessionId)
{
try
{
密码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)));
返回decryptedSessionId;

catch(Exception e)
{
e.printStackTrace();

}
返回null;

$ / code>

即将发生的错误是:
Class'javax.crypto .Cipher'在JRE仿真库中不存在,因此它不能用于某些GWT模块的客户端代码中。



此检查报告JDK类的客户端代码中的用法这在JRE仿真库中不存在。



我使用的加密方法是:

pre > 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()));
返回encryptedSessionId;

catch(Exception e)
{
e.printStackTrace();
}
返回null;


我对这个东西很陌生,请帮我解决错误

解决方案

好的,你不能在客户端的GWT编码中使用java标准加密库。不支持。



使用 gwt-crypto 来加密/解密必要的东西。



GWT-crypto中的GWT客户端不支持AES ,但你可以使用TripleDES。 TripleDES也是非常安全的实现。

I encypted the session Id at server side but when I am trying to decrypt the session id at client side some error is coming. please can anyone help resolving the error.

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;
}

The error that is coming is : Class 'javax.crypto.Cipher' is not present in JRE Emulation Library so it cannot be used in client code of "some" GWT module.

This inspection reports usages in client code of JDK classes which is not present in JRE Emulation Library.

The method for encryption that I used is :

    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;

}

I am new to this stuff please help me resolving the errors

解决方案

Well, you cannot use java standard encryption library in GWT coding on client side. It's not supported.

Use gwt-crypto to encrypt/decrypt the necessary stuff.

AES is not be supported on client side for GWT in GWT-crypto, but you can use TripleDES. TripleDES is also very much secure implementation.

这篇关于在客户端使用java解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆