Java¼ÓÃܺÍÊý×ÖÇ©Ãû±à³Ì¿ìËÙÈëÃÅ
±¾ÎÄÖ÷Ҫ̸һÏÂÃÜÂëѧÖеļÓÃܺÍÊý×ÖÇ©Ãû£¬ÒÔ¼°ÆäÔÚjavaÖÐÈçºÎ½øÐÐʹÓ᣶ÔÃÜÂëѧÓÐÐËȤµÄ»ï°é£¬ÍƼö¿´Bruce SchneierµÄÖø×÷£ºApplied Crypotography¡£ÔÚjdk1.5µÄ·¢Ðа汾Öа²È«ÐÔ·½ÃæÓÐÁ˺ܴóµÄ¸Ä½ø£¬Ò²ÌṩÁ˶ÔRSAËã·¨µÄÖ±½ÓÖ§³Ö£¬ÏÖÔÚÎÒÃÇ´ÓʵÀýÈëÊÖ½â¾öÎÊÌ⣨±¾ÎĽöÊÇ×÷Ϊ¼òµ¥½éÉÜ£©£º
¡¡¡¡Ò»¡¢ÃÜÂëѧÉϳ£ÓõĸÅÄî¡¡
¡¡¡¡1£©ÏûÏ¢ÕªÒª£º
¡¡¡¡ÕâÊÇÒ»ÖÖÓëÏûÏ¢ÈÏÖ¤Âë½áºÏʹÓÃÒÔÈ·±£ÏûÏ¢ÍêÕûÐԵļ¼Êõ¡£Ö÷ҪʹÓõ¥ÏòÉ¢Áк¯ÊýËã·¨£¬¿ÉÓÃÓÚ¼ìÑéÏûÏ¢µÄÍêÕûÐÔ£¬ºÍͨ¹ýÉ¢ÁÐÃÜÂëÖ±½ÓÒÔÎı¾ÐÎʽ±£´æµÈ£¬Ä¿Ç°¹ã·ºÊ¹ÓõÄËã·¨ÓÐMD4¡¢MD5¡¢SHA-1£¬jdk1.5¶ÔÉÏÃ涼ÌṩÁËÖ§³Ö£¬ÔÚjavaÖнøÐÐÏûÏ¢ÕªÒªºÜ¼òµ¥£¬ java.security.MessageDigestÌṩÁËÒ»¸ö¼òÒ׵IJÙ×÷·½·¨£º
Java´úÂë
/**
*MessageDigestExample.java
*Copyright 2005-2-16
*/
import java.security.MessageDigest;
/**
*µ¥Ò»µÄÏûÏ¢ÕªÒªËã·¨£¬²»Ê¹ÓÃÃÜÂë.¿ÉÒÔÓÃÀ´¶ÔÃ÷ÎÄÏûÏ¢£¨È磺ÃÜÂ룩Òþ²Ø±£´æ
*/
public class MessageDigestExample{
¡¡public static void main(String[] args) throws Exception{
¡¡¡¡if(args.length!=1){
¡¡¡¡¡¡System.err.println("Usage:java MessageDigestExample text");
¡¡¡¡¡¡System.exit(1);
¡¡¡¡}
¡¡¡¡byte[] plainText=args[0].getBytes("UTF8");
¡¡¡¡//ʹÓÃgetInstance("Ëã·¨")À´»ñµÃÏûÏ¢ÕªÒª,ÕâÀïʹÓÃSHA-1µÄ160λËã·¨
¡¡¡¡MessageDigest messageDigest=MessageDigest.getInstance("SHA-1");
¡¡¡¡System.out.println("\n"+messageDigest.getProvider().getInfo());
¡¡¡¡//¿ªÊ¼Ê¹ÓÃËã·¨
¡¡¡¡messageDigest.update(plainText);
¡¡¡¡System.out.println("\nDigest:");
¡¡¡¡//Êä³öËã·¨ÔËËã½á¹û
¡¡¡¡System.out.println(new String(messageDigest.digest(),"UTF8"));
¡¡}
}
/**
*MessageDigestExample.java
*Copyright 2005-2-16
*/
Ïà¹ØÎĵµ£º
cd /usr/lib/jvm/java
-1.5.0-sun-1.5.0.15/jre/lib/fonts
sudo mkdir fallback
cd fallback
sudo cp /usr/share/fonts/truetype/arphic/uming.ttc /usr/lib/jvm/java
-1.5.0-sun-1.5.0.15/jre/lib/fonts/fallback
sudo mkfontdir
sudo mkfontscale ......
System.currentTimeMillis()£º¿ÉÒÔÌáÈ¡µ½µ±Ç°Ê±¼äµÄºÁÃëÊý£¬²úÉúÒ»¸öµ±Ç°µÄºÁÃ룬Õâ¸öºÁÃëÆäʵ¾ÍÊÇ×Ô1970Äê1ÔÂ1ÈÕ0ʱÆðµÄºÁÃëÊý¡£
³£¼û×÷ÓãºÒ»°ã¶¼ÊÇÓÃ2¸öʱ¼äµÄ²îÖµÀ´µÃµ½ÔËÐÐʱ¼äµÄ£¬³£ÓÃÀ´±È½Ï2¸öËã·¨µÄЧÂÊ£¡
long start = System.currentTimeMillis();
// ÕâÀï¿ÉÒÔ¼ÓÉÏÄãÒªÖªµÀµÄ·½·¨ÔËÐеÄʱ¼ä£¡£¡
......
×¢£º1.·½·¨µÄ²ÎÊý length ÊÇÉú³ÉµÄËæ»úÊýµÄ³¤¶È¡£
2. Ö»ÏëÒª´óдµÄ×Öĸ ¿ÉÒÔʹ int choice =65£» Ö»ÏëҪСдµÄ×Öĸ£¬¾Í int choice =97£»
import java.util.Random;
public String getCharAndNumr(int length)
{
String val = " ......
Ãô½Ý¿ª·¢µÄÀíÄîÒѾÁ÷ÐÐÁ˺ܳ¤µÄʱ¼ä£¬ÔÚÃô½Ý¿ª·¢ÖеĿª·¢µü´ú½×¶ÎÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýÎå¸ö²½Ö裬À´ÓÐЧµÄÌá¸ßÕû¸öÏîÄ¿µÄ´úÂëÖÊÁ¿¡£
JavaÏîÄ¿¿ª·¢¹ý³ÌÖУ¬ÓÉÓÚ¿ª·¢ÈËÔ±µÄ¾Ñé¡¢Java´úÂë±àдϰ¹ß£¬ÒÔ¼°È±·¦Í³Ò»µÄ±ê×¼ºÍ¹ÜÀíÁ÷³Ì£¬ÍùÍùµ¼ÖÂÕû¸öÏîÄ¿µÄ´úÂëÖÊÁ¿½Ï²î£¬ÄÑÓÚά
»¤£¬ÐèÒª½Ï´óµÄ²âÊÔͶÈëºÍÖÜÆÚµÈÎÊÌâ¡£ÕâЩÎÊÌâÔÚÒ»¸ ......
Ãô½Ý¿ª·¢Öбàд¸ßÖÊÁ¿Java´úÂë
2010-03-08 10:32
|
1709
´ÎÔĶÁ
|
¡¾ÒÑÓÐ9
ÌõÆÀÂÛ¡¿·¢±íÆÀÂÛ
À´Ô´£º±ÈÌØÍø À´Ô´£ºIBM/ÍõÓÀ¿ý
|
Êղص½ÎÒµÄÍøÕª
Ãô½Ý¿ª·¢µÄÀíÄîÒѾÁ÷ÐÐÁ˺ܳ¤µÄʱ¼ä£¬ÔÚÃô½Ý¿ª·¢ÖеĿª·¢µü´ú½×¶ÎÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýÎå¸ö²½Ö裬À´ÓÐЧµÄÌá¸ßÕû¸öÏîÄ¿µÄ´úÂëÖÊÁ¿¡ ......