求一个加密算法! 可以加密和解密。汉字和英文都要可以。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 package com.sxzlc.test.rc4;public class RC4 {public static byte[] RC42(byte[] aInput, byte[] aKey) {int[] iS = new int[256];byte[] iK = new byte[256];for (int i = 0; i < 256; i++)iS[i] = i;int j = 1;for (short i = 0; i < 256; i++) {iK[i] = (byte) aKey[i%aKey.length];}j = 0;for (int i = 0; i < 256; i++) {j = (j + iS[i] + iK[i]) &0xff;int temp = iS[i]&0xff;iS[i] = iS[j]&0xff;iS[j] = temp;}int i = 0;j = 0;for (int x = 0; x < aInput.length; x++) {i = (i + 1) &0xff;j = (j + iS[i]) &0xff;int temp = iS[i]&0xff;iS[i] = iS[j]&0xff;iS[j] = temp;int t = ((iS[i] + iS[j] ))&0xff;int iY = iS[t];byte iCY = (byte) (iY&0xff);aInput[x] = (byte) ((aInput[x]^iCY)&0xff);}return aInput;} public static void main(String[] args) { String inputStr = "你们好啊"; String key = "961633"; byte[] bytes = inputStr.getBytes();//打印加密后的字符串 bytes = RC4.RC42(inputStr.getBytes(), key.getBytes());inputStr = new String(bytes);System.out.println( inputStr ); //打印加密后的字符串 bytes = RC4.RC42(inputStr.getBytes(), key.getBytes());inputStr = new String(bytes);System.out.println( inputStr ); }} 附送MD5import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;public class MD5Digest{ private MessageDigest md5 = null; private StringBuffer digestBuffer = null; public MD5Digest() throws NoSuchAlgorithmException { md5 = MessageDigest.getInstance("MD5"); digestBuffer = new StringBuffer(); } public String md5crypt(String s) { digestBuffer.setLength(0); byte abyte0[] = md5.digest(s.getBytes()); for(int i = 0; i < abyte0.length; i++) digestBuffer.append(toHex(abyte0[i])); return digestBuffer.toString(); } public String toHex(byte one){ String HEX="0123456789ABCDEF"; char[] result=new char[2]; result[0]=HEX.charAt((one & 0xf0) >> 4); result[1]=HEX.charAt(one & 0x0f); String mm=new String(result); return mm; }} 有谁知道java中new string(“abc”)是调用了什么东西 世纪光棍节送给所有程序员的程序礼物!!!!!!!..... 一个类中的成员变量是这个类本身的对象 请问table能不能合并单元格? 请问各位用java怎么来对usb接口进行数据的读写操作? 菜鸟提问 新手问一个小问题 Applet 怎样读取服务器上的文件? SCJD是什么东西,在线等待。 管道流错误(java.io.IOException:write end dead;) 未必你真懂:String s=new String("abc")请问创建几个对象? 什么是数据库万能字典表?
package com.sxzlc.test.rc4;public class RC4 {
public static byte[] RC42(byte[] aInput, byte[] aKey) {
int[] iS = new int[256];
byte[] iK = new byte[256];for (int i = 0; i < 256; i++)
iS[i] = i;int j = 1;for (short i = 0; i < 256; i++) {
iK[i] = (byte) aKey[i%aKey.length];
}j = 0;for (int i = 0; i < 256; i++) {
j = (j + iS[i] + iK[i]) &0xff;
int temp = iS[i]&0xff;
iS[i] = iS[j]&0xff;
iS[j] = temp;
}int i = 0;
j = 0;for (int x = 0; x < aInput.length; x++) {
i = (i + 1) &0xff;
j = (j + iS[i]) &0xff;
int temp = iS[i]&0xff;
iS[i] = iS[j]&0xff;
iS[j] = temp;
int t = ((iS[i] + iS[j] ))&0xff;
int iY = iS[t];
byte iCY = (byte) (iY&0xff);
aInput[x] = (byte) ((aInput[x]^iCY)&0xff);
}return aInput;}
public static void main(String[] args)
{
String inputStr = "你们好啊";
String key = "961633";
byte[] bytes = inputStr.getBytes();
//打印加密后的字符串
bytes = RC4.RC42(inputStr.getBytes(), key.getBytes());
inputStr = new String(bytes);
System.out.println( inputStr );
//打印加密后的字符串
bytes = RC4.RC42(inputStr.getBytes(), key.getBytes());
inputStr = new String(bytes);
System.out.println( inputStr );
}}
import java.security.NoSuchAlgorithmException;public class MD5Digest
{ private MessageDigest md5 = null;
private StringBuffer digestBuffer = null; public MD5Digest()
throws NoSuchAlgorithmException
{
md5 = MessageDigest.getInstance("MD5");
digestBuffer = new StringBuffer();
} public String md5crypt(String s)
{
digestBuffer.setLength(0);
byte abyte0[] = md5.digest(s.getBytes());
for(int i = 0; i < abyte0.length; i++)
digestBuffer.append(toHex(abyte0[i])); return digestBuffer.toString();
}
public String toHex(byte one){
String HEX="0123456789ABCDEF";
char[] result=new char[2];
result[0]=HEX.charAt((one & 0xf0) >> 4);
result[1]=HEX.charAt(one & 0x0f);
String mm=new String(result);
return mm;
}
}