java实现的RC4加密解密算法示例

  

本文实例讲述了java实现的RC4加密解密算法。分享给大家供大家参考,具体如下:

  

有一个项目,需要解析一个用户提供的rc4加密后的文件,特意搜索整理了一个Java版本的rc4加解密算法。

        aInput HloveyRC4公共静态字符串(字符串,字符串阿奇)   {   int []=new int [256];   本土知识byte []=new字节[256];   for (int i=0; i<256;我+ +)   [我]=我;   int j=1;   短我=0;i<256;我+ +)   {   本土知识[我]=(字节)阿奇。charAt((我% aKey.length ()));   }   j=0;   for (int i=0; i<255;我+ +)   {   j=(j +本土知识是[我]+[我])% 256;   int temp=[我];   [我]=[j];   是[j]=temp;   }   int i=0;   j=0;   char [] iInputChar=aInput.toCharArray ();   char [] iOutputChar=new char [iInputChar.length];   (短x=0; x< iInputChar.length; x + +)   {   我=256 (i + 1) %;   j=(j +[我])% 256;   int temp=[我];   [我]=[j];   是[j]=temp;   t=(int[我]+ [j] % 256) () % 256;   int iY=[t];   iY char冰冷=(char);   iOutputChar [x]=(char) (iInputChar [x] ^冰冷的);   }   返回新字符串(iOutputChar);   }      之前      

加密和解密都用这一个方法。也就是说参数字符串aInput可以传一个明文,也可以传一个加密后的字符串,程序会自动的识别。然后执行加解密的响应操作。

  

使用例子如下:

        公共静态void main (String [] args) {   字符串inputStr="做个好男人”;   字符串键=坝⒂镒帜浮?   字符串str=HloveyRC4 (inputStr、关键);//打印加密后的字符串   System.out.println (str);//打印解密后的字符串   System.out.println (HloveyRC4 (str,键));   }      之前      

  http://tools.jb51.net/password/CreateMD5Password

  http://tools.jb51.net/password/urlrethunder

  http://tools.jb51.net/password/hash_encrypt

  http://tools.jb51.net/password/hash_md5_sha

  http://tools.jb51.net/password/sha_encode

  

更多关于java相关内容感兴趣的读者可查看本站专题:《java数学运算技巧总结》,《java数据结构与算法教程》、《java字符与字符串操作技巧总结》,《java日期与时间操作技巧汇总》、《java操作DOM节点技巧总结》和《java缓存操作技巧汇总》

  

希望本文所述对大家java程序设计有所帮助。

java实现的RC4加密解密算法示例