Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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(Èý)


JavaÔÓ̸£¨Áù£© 
        ÕâÆªÊDZÊÕß´òËãдµÄJ2se²¿·ÖµÄ×îºóһƪÁË£¬ÕâÆª½áÊøÖ®ºó£¬ÔÙдJ2ee²¿·Ö£¬²»ÖªµÀÊÇ·ñ»¹ºÏÊÊдÔÚÕâ¸ö°æ¿é£¿´ó¼Ò¿ÉÒÔ¸øµãÒâ¼û£¬Ð»Ð»´ó¼Ò¶ÔСµÜÕâô¹ÄÀøÒ»Â·Ð´ÍêǰÁùƪJavaÔÓ̸µÄJ2se²¿·Ö¡£×îºóÕâÆª´òËã̸һ̸JavaÖеÄRMI»úÖÆºÍJVMɳÏ䰲ȫ¿ò¼Ü¡£&nbs ......

ÓÃjava¶ÁÎļþÄÚÈÝ

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;
/**
 *
 * ¶àÖÖ·½Ê½¶ÁÎ ......

java¼ÆËã³ÌÐòÔËÐÐʱ³¤

long startTime=System.currentTimeMillis(); //»ñÈ¡¿ªÊ¼Ê±¼ä 
doSomeThing(); //²âÊԵĴúÂë¶Î
long endTime=System.currentTimeMillis(); //»ñÈ¡½áÊøÊ±¼ä
System.out.println("³ÌÐòÔËÐÐʱ¼ä£º "+(end-start)+"ms"); ......

javaÐÔÄܵÄÓÅ»¯(¶þ)

    Èý£®ÓÅ»¯JAVA³ÌÐòÉè¼ÆºÍ±àÂ룬Ìá¸ßJAVA³ÌÐòÐÔÄܵÄһЩ·½·¨¡£
   
ͨ¹ýʹÓÃÒ»Ð©Ç°Ãæ½éÉܹýµÄ¸¨ÖúÐÔ¹¤¾ßÀ´ÕÒµ½³ÌÐòÖÐµÄÆ¿¾±£¬È»ºó¾Í¿ÉÒÔ¶ÔÆ¿¾±²¿·ÖµÄ´úÂë½øÐÐÓÅ»¯¡£Ò»°ãÓÐÁ½ÖÖ·½°¸£º¼´ÓÅ»¯´úÂë»ò¸ü¸ÄÉè¼Æ·½·¨¡£ÎÒÃÇÒ»°ã»áÑ¡
ÔñºóÕߣ¬ÒòΪ²»È¥µ÷ÓÃÒÔÏ´úÂëÒª±Èµ÷ÓÃһЩÓÅ»¯µÄ´úÂë¸üÄÜÌá ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ