java php DES ¼ÓÃܽâÃÜ
import java.io.IOException;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class DES {
private byte[] desKey;
public DES(String desKey) {
this.desKey = desKey.getBytes();
}
public byte[] desEncrypt(byte[] plainText) throws Exception {
SecureRandom sr = new SecureRandom();
byte rawKeyData[] = desKey;
DESKeySpec dks = new DESKeySpec(rawKeyData);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey key = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE, key, sr);
byte data[] = plainText;
byte encryptedData[] = cipher.doFinal(data);
return encryptedData;
}
public byte[] desDecrypt(byte[] encryptText) throws Exception {
SecureRandom sr = new SecureRandom();
byte rawKeyData[] = desKey;
DESKeySpec dks = new DESKeySpec(rawKeyData);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey key = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, key, sr);
byte encryptedData[] = encryptText;
byte decryptedData[] = cipher.doFinal(encryptedData);
return decryptedData;
}
public String encrypt(String input) throws Exception {
return base64Encode(desEncrypt(input.getBytes()));
}
public String decrypt(String input) throws Exception {
byte[] result = base64Decode(input);
return new String(desDecrypt(result));
}
public static String base64Encode(byte[] s) {
if (s == null)
return null;
BASE64Encoder b = new sun.misc.BASE64Encoder();
return b.encode(s);
}
public static byte[] base64Decode(String s) throws IOException {
if (s == null)
return null;
BASE64Decoder decoder = new BASE64Decoder();
byte[] b = decoder.de
Ïà¹ØÎĵµ£º
JavaÔÓ̸£¨Áù£©
ÕâÆªÊDZÊÕß´òËãдµÄJ2se²¿·ÖµÄ×îºóһƪÁË£¬ÕâÆª½áÊøÖ®ºó£¬ÔÙдJ2ee²¿·Ö£¬²»ÖªµÀÊÇ·ñ»¹ºÏÊÊдÔÚÕâ¸ö°æ¿é£¿´ó¼Ò¿ÉÒÔ¸øµãÒâ¼û£¬Ð»Ð»´ó¼Ò¶ÔСµÜÕâô¹ÄÀøÒ»Â·Ð´ÍêǰÁùƪJavaÔÓ̸µÄJ2se²¿·Ö¡£×îºóÕâÆª´òËã̸һ̸JavaÖеÄRMI»úÖÆºÍJVMɳÏ䰲ȫ¿ò¼Ü¡£&nbs ......
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.io.Reader;
/**
*
* ¶àÖÖ·½Ê½¶ÁÎ ......
long startTime=System.currentTimeMillis(); //»ñÈ¡¿ªÊ¼Ê±¼ä
doSomeThing(); //²âÊԵĴúÂë¶Î
long endTime=System.currentTimeMillis(); //»ñÈ¡½áÊøÊ±¼ä
System.out.println("³ÌÐòÔËÐÐʱ¼ä£º "+(end-start)+"ms"); ......
JavaÔÓ̸£¨¾Å£©££Struts
J2eeµÄ¿ªÔ´¿ò¼ÜºÜ¶à£¬±ÊÕßÖ»ÄܽéÉÜ×Ô¼ºÊìϤµÄ¼¸¸ö£¬ÆäËûµÄĿǰÔÚÖйúITÐÐÒµÓ¦Óõò»ÊǺܶࡣϣÍû´ó¼Ò¶ÔгöµÄ¿ò¼Ü²»ÒªÃ¤Ä¿µÄÍÆ³ç£¬Ê×ÏÈÒ»¶¨ÒªÊìϤËü±È¾ÉµÄµ½µ×ºÃÔÚÄÄÀеÄÀíÄîºÍÌØÐÔ ......
±àÕß°´£ºJavaÄÚ´æÐ¹Â©ÊÇÿ¸öJava³ÌÐòÔ±¶¼»áÓöµ½µÄÎÊÌ⣬³ÌÐòÔÚ±¾µØÔËÐÐÒ»ÇÐÕý³££¬¿ÉÊDz¼Êðµ½Ô¶¶Ë¾Í»á³öÏÖÄÚ´æÎÞÏÞÖÆµÄÔö³¤£¬×îºóϵͳ̱»¾£¬ÄÇôÈç
ºÎ×î¿ì×îºÃµÄ¼ì²â³ÌÐòµÄÎȶ¨ÐÔ£¬·Àֹϵͳ±ÀÅÌ£¬×÷ÕßÓÃ×ÔÒѵÄÇ×Éí¾ÀúÓë¸÷Î»ÍøÓÑ·ÖÏí½â¾öÕâЩÎÊÌâµÄ°ì·¨¡£
×÷ΪInternet×îÁ÷Ðеı ......