JavaÖеÄmac¼ÆËã
±¨Îļø±ðÔÚÉí·ÝÈÏÖ¤ÖÐÕ¼ÖØÒªÎ»Öã¬ÊÇÈÏ֤ϵͳµÄÒ»¸öÖØÒª»·½Ú£¬ÔÚ½ðÈÚºÍÉÌҵϵͳÖй㷺ӦÓá£
±¨Îļø±ð³£Óñ¨Îļø±ðÂ루Message Authentication Code,¼´MAC£©×÷Ϊ¼ø±ðµÄ»ù´¡£¬
Æä»ù±¾ÔÀíÊÇ£ºÓÃÒ»¸öÃÜÔ¿£¨£¨private Key£©£©Éú³ÉÒ»¸öСÊý¾Ý¿é¸½¼ÓÔÚÒª´«ÊäµÄ±¨ÎĺóÃæ¡£ÕâÖÖ¼¼ÊõÊǼٶ¨Í¨Ñ¶Ë«·½¹²ÏíÒ»¸öÃÜÔ¿K£¬µ±Í¨Ñ¶µÄÒ»·½Òª¸øÁíÒ»·½´«ÊäÊý¾ÝMʱ£¬Í¨¹ýÌØ¶¨µÄËã·¨¼ÆËã³ö¸Ã±¨ÎÄMµÄMAC£½F£¨K£¬M£©£¬ÕâÀïµÄF¾ÍÊÇÖ¸¼ø±ðÔËË㺯Êý£¬È»ºó±¨ÎÄÊý¾ÝMºÍMACÒ»Æð´«Ë͸øÁíÒ»·½¡£µ±ÁíÒ»·½ÊÕµ½Êý¾Ýʱ£¬ÏÈÓÃͬÑùµÄËã·¨F¼ÆËãMAC£¬ºÍ´«Êä¹ýÀ´µÄMAC½øÐбȽϣ¬Èç¹ûÏàͬ£¬ÔòÈÏΪÊý¾ÝÊÇÕýÈ·µÄ¡£ ¼ø±ðº¯Êý³£±»ÈÏΪÊǼÓÃÜËã·¨µÄÒ»ÖÖ£¬µ«ÊÇÇø±ðÔÚÓÚËü²»ÓÃÓÚÄæÔËË㣬ÓÐÒ»¶¨µÄ°²È«ÐÔ¡£ ͨ³£¶ÔÓÚ²»Í¬µÄÓ¦ÓÃϵͳ²ÉÓø÷×ÔÌØ¶¨µÄ¼ø±ðº¯Êý£¬ÕâÑùÔÚÒ»¶¨³Ì¶ÈÉϱ£Ö¤ÁËÊý¾ÝµÄ°²È«ÐÔ¡£
´Ój2sdk1.4ÒÔºó£¬javaÌṩÁËÀàjavax.crypto.MacÀ౨Îļø±ð
byte[] macData = "this is a mac test".getBytes(); //get a instance of Mac, using HmacMD5 algorithm
Mac mac = Mac.getInstance("HmacMD5"); //init the IV of the algorithm, 8 bytes. may read from file
byte[] ivInitKey = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07 };
IvParameterSpec spec = new IvParameterSpec(ivInitKey); // the secrete key bytes of the Mac validation, May read from file too
byte[] keyBytes = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f }; //generate the secrete Key Object using secrete bytes and DESede algorithm
SecretKey key = new SecretKeySpec(keyBytes, "DESede"); // init Mac mac.init(key, spec);
byte[] macCode = mac.doFinal(macData);
macCode ¾ÍÊÇÉú³ÉµÄMac£¬ÓÃͬÑùµÄÃÜÔ¿ÄܲúÉúͬÑùµÄmac¡£
ͨѶ˫·½Ö»Òª±£Ö¤ÓÃͬÑùµÄÃÜÔ¿¾ÍÄܱ£Ö¤µÃµ½Í¬ÑùµÄMac£¬´ïµ½±¨ÎÄÑéÖ¤µÄÄ¿µÄ¡£
¿´À´¿´È¥£¬ÕâºÍÍøÂçÉϳ£ÓõÄchecksumÔÀíÊÇÒ»ÑùµÄ¡£
Ïà¹ØÎĵµ£º
public class testthree {
public static void main(String[] args) {
testthree t = new testthree();
t.test();
}
private static void test() {
int d = 0;
int f = 4;
int x = 0;
int y = 6;
for (i ......
/*ÄÚ²¿ÀàʹÓÃʾÀý*/
package demo;
class Outer{
int outer_i=100;
static int outer_j=200;
final int outer_k=300;
void test(){
Inner in = new Inner();
in.display();
}
static class Inner{
void display(){
  ......
package demo;
class InOut{
String str=new String("Between");
static int i=666;
int j=888;
final int k=999;
public void amethod(final int iArgs){
int it315;
final int x=111;
/*static*/ class Bicycle
{
//&n ......
¸øÊý×鸳ֵµÄ±ã½Ý·½Ê½£º String s=reader.nextLine(); char a[]=s.toCharArray();ÕâÑù¾Í²»ÓÃʹÓÃÂé·³µÄforÑ»·À´¸³ÖµÁË
Êä³öÊý×éÄÚÈݵıã½Ý·½Ê½£ºString code=new String(a); //aÊÇÒ»¸öÊý×éÃû
System.out.println("ÔÎÄÊÇ"+code);
&nb ......
ÏÖÔÚ ËùÓÃJava°æ±¾,DateÀ๹Ôì·½·¨Date(0)µÄʱ¼ä²»ÊÇThu Jan 01 01:00:00 GMT 1970ÁË£¬¶øÊÇThu Jan 01 08:00:00 CST 1970¡££¨ 1970 Äê1 ÔÂ1 ÈÕ8ʱ0·Ö0Ãë ÐÇÆÚ4£©
Ϊʲô Date b1=new Date(623289600000); ²»¿ÉÒÔ£¬ÏÂÃæµÄÈ´¿ÉÒÔÄØ£¿
long a=623289600000L;
Date b1=new Date(a); Ò ......