Java代码翻译为C#代码

 public static String decrypt(String data, String key) {

        if (key.length() < 16) {
            throw new RuntimeException("Invalid AES key length (must be 16 bytes)");
        } else if (key.length() > 16) {
            key = key.substring(0, 16);
        }
        try {
            // 十六进制转换为二进制
            byte[] decryptFrom = parseHexStr2Byte(data);
            Cipher cipher = Cipher.getInstance(AES_ALGORITHM);// 创建密码器
            cipher.init(Cipher.DECRYPT_MODE, genKey(key));// 初始化
            byte[] result = cipher.doFinal(decryptFrom);
            return new String(result,"utf-8"); // 加密
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

实在没分了,实在翻译不过来,翻译过来又是乱码,实在没办法了。帮帮忙!

parseHexStr2Byte 和 Cipher 等,有对应语言版本的实现?

Java 与 C# 下,DES 加密与解密的算法的问题,是否完全一样、或者说兼容还不确定吧。

http://www.cnblogs.com/lzrabbit/p/3639503.html
http://www.oschina.net/code/snippet_242957_9931

不用翻译,直接将代码改成 .cs文件名即可。
这些代码和C#一模一样

         public static String Decrypt(String data, String key)
        {
            if (key.Length < 16)
            {
                throw new Exception("Invalid AES key length (must be 16 bytes)");
            }
            else if (key.Length > 16)
            {
                key = key.Substring(0, 16);
            }
            try
            {
                // 十六进制转换为二进制
                //byte[] decryptFrom = parseHexStr2Byte(data); 
                //Cipher cipher = Cipher.getInstance(AES_ALGORITHM);// 创建密码器
                //cipher.init(Cipher.DECRYPT_MODE, genKey(key));// 初始化
                byte[] result;
                //result = cipher.doFinal(decryptFrom);
                return System.Text.Encoding.UTF8.GetString(result);
            }
            catch (Exception ex)
            {
                //TODO:处理Exception
            }
            return null;
        }

注释的代码需要调用的类的代码没有贴出来,无法帮你转了。

搜索 'Couldn't look up your hostname [22:41] == Nickname is already in use: 71222142 [22:42] == ERROR: Closing Link: 60.26.222.120 (Registration timed out) [22:42] == Disconnected from server: Connection' 共找到0个相关内容