当前位置:编程学习 > C#/ASP.NET >>

各位大哥,有C#\ JAVA 双修的吗?有一段JAVA 3DES加密代码需要C#重写。

没有时间研究JAVA了,只好求助各位大哥了。以下JAVA写的3DES加密代码,需要用C#重写,最好测试能够通过并且和原JAVA代码的测试结果一致,谢谢了。
    public static String EcryptBytes(String s)
            throws Exception
        {
         byte bys[] = s.getBytes("GBK");
            String Algorithm = "DESede";
            String key = "abcdefghij0123456789klmn";
            byte keybyte[] = key.getBytes();
            javax.crypto.SecretKey deskey = new SecretKeySpec(keybyte, Algorithm);
            Cipher cipher = Cipher.getInstance(Algorithm);
            cipher.init(1, deskey);
            ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
            CipherOutputStream cipherStream = new CipherOutputStream(byteStream, cipher);
            GZIPOutputStream gzipStream = new GZIPOutputStream(cipherStream);
            gzipStream.write(bys);
            gzipStream.close();
            StringBuffer sb = new StringBuffer(1200);
            byte eBytes[] = byteStream.toByteArray();
            int len = eBytes.length / 2;
            if(eBytes.length % 2 != 0)
                len++;
            for(int i = 0; i < len; i++)
            {
                int data = 0;
                if(i * 2 + 1 >= eBytes.length)
                    data = (0xff & eBytes[i * 2]) + 0x10000;
                else
                    data = (0xff & eBytes[i * 2]) + (0xff & eBytes[i * 2 + 1]) * 256;
                String str = (new StringBuilder("00000")).append(String.valueOf(data)).toString();
                sb.append(str.substring(str.length() - 5, str.length()));
            }
            return sb.toString();
        } c# java --------------------编程问答-------------------- refer:http://bbs.csdn.net/topics/350158619
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,