<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-109  評論-187  文章-25  trackbacks-0

    ?

    ?1 import ?java.io.BufferedReader;
    ?2 import ?java.io.InputStreamReader;
    ?3 import ?java.security.MessageDigest;
    ?4
    ?5 import ?sun.misc.BASE64Decoder;
    ?6 import ?sun.misc.BASE64Encoder;
    ?7
    ?8 public ? class ?ConvertNounce? {
    ?9
    10 ???? // ?Digest?=?H(B64(H(username:password)):nonce)
    11 ???? // ?b1=B64(H(username:password));
    12 ???? //
    13 ???? //
    14 ???? /**
    15 ?????*? @param ?args
    16 ????? */

    17 ???? public ? static ? void ?main(String[]?args)? throws ?Exception? {
    18 ????????
    19
    20 ????????
    21 ???? // ????if(args.length!=3)?throw?new?Exception("args?is?wrong?,there?is?must?by?three?args?:username?password?nextNounce");
    22
    23 ????????InputStreamReader?reader? = ? new ?InputStreamReader(System.in);
    24 ????????BufferedReader?input? = ? new ?BufferedReader(reader);
    25 ????
    26 ????????
    27 ????????System.out.println( " input?username: " );
    28 ????????String?username? = input.readLine();
    29 ????????System.out.println( " input?password: " );
    30 ????????String?pwd? = ?input.readLine();
    31 ????????System.out.println( " input?nextNounce: " );
    32 ????????
    33 ????????String?serverNounce? = ?input.readLine();
    34 ????????String?clientNounce? = ? null ;
    35
    36 ????????System.out.println( "" );
    37 ????????
    38 ????????System.out.println( " userName= " + username);
    39 ????????System.out.println( " password= " + pwd);
    40 ????????System.out.println( " nextNounce= " + serverNounce);
    41 ???????? byte []?b1? = ?calculateDigestAndEcode64(username,?pwd);
    42 ????????
    43 ???? // ????System.out.println("b1="+new?String(b1));
    44 ????????
    45 ???????? // server?下來的nounce一定要先做B64的解碼,否則算出來的結果對不上
    46 ????????serverNounce? = new ?String( new ?BASE64Decoder().decodeBuffer(serverNounce));
    47 ????????
    48 ???? // ????System.out.println(serverNounce);
    49
    50 ???????? byte []?bserverNounce? = ?serverNounce.getBytes();
    51
    52 ???????? byte []?buf? = ? new ? byte [b1.length? + ? 1 ? + ?bserverNounce.length];
    53
    54 ????????System.arraycopy(b1,? 0 ,?buf,? 0 ,?b1.length);
    55
    56 ????????buf[b1.length]? = ?( byte )? ' : ' ;
    57 ????????System.arraycopy(bserverNounce,? 0 ,?buf,?b1.length + 1 ,
    58 ????????????????????????bserverNounce.length);
    59 ????????MessageDigest?md? = ?MessageDigest.getInstance( " MD5 " );
    60 ????????
    61 ???? // ????System.out.println(new?String(buf));
    62
    63 ???????? byte []?digest? = ?md.digest(buf);
    64 ????????
    65 ???? // ????System.out.println(new?String(digest));
    66
    67 ????????clientNounce? = ? new ?BASE64Encoder().encode(digest);
    68 ????????System.out.println( "" );
    69 ????????System.out.println( " result?Nounce= " + clientNounce);
    70 ????????
    73 ????}

    74
    75 ???? public ? static ? byte []?calculateDigestAndEcode64(String?username,
    76 ????????????String?password)? throws ?Exception? {
    77
    78 ????????MessageDigest?md? = ?MessageDigest.getInstance( " MD5 " );
    79 ????????String?cred? = ? "" ;
    80 ???????? if ?(username? != ? null )? {
    81 ????????????cred? = ?username.trim();
    82 ????????}

    83 ????????cred? += ? " : " ;
    84 ???????? if ?(password? != ? null )? {
    85 ????????????cred? += ?password.trim();
    86 ????????}

    87 ???? // ????System.out.println(cred);
    88 ???????? // ?System.out.println(new?String(md.digest(cred.getBytes())));
    89 ???????? return ? new ?BASE64Encoder().encode(md.digest(cred.getBytes()))
    90 ????????????????.getBytes();
    91 ????}

    92 ????
    93 ????
    94
    95 }

    96
    posted on 2007-01-11 14:57 小小程序程序員混口飯吃 閱讀(1369) 評論(0)  編輯  收藏 所屬分類: java
    主站蜘蛛池模板: 国产精品亚洲成在人线| 亚洲精品成人在线| 亚洲精品**中文毛片| 国产免费爽爽视频在线观看| 亚洲AV无码成人精品区日韩| 国产高清视频免费在线观看| 日韩亚洲国产二区| 亚洲成AV人综合在线观看| 久久一本岛在免费线观看2020| 日韩一级在线播放免费观看| 亚洲无码一区二区三区| 成人片黄网站A毛片免费| 亚洲成AV人片一区二区密柚| 中文无码成人免费视频在线观看| 婷婷精品国产亚洲AV麻豆不片| 免费人成大片在线观看播放电影| 四虎影视永久免费视频观看| 七次郎成人免费线路视频| 中国亚洲女人69内射少妇| 国产激情免费视频在线观看| 亚洲婷婷在线视频| 在线免费观看污网站| 五月婷婷免费视频| 亚洲成在人天堂一区二区| 男女免费观看在线爽爽爽视频| 亚洲国产精品成人午夜在线观看 | 国产精品免费视频网站| 美女被艹免费视频| 亚洲精品乱码久久久久66| 91精品国产免费久久国语蜜臀 | 五月婷婷亚洲综合| 成人无码WWW免费视频| 亚洲日韩乱码中文无码蜜桃臀| 无人在线观看完整免费版视频| 亚洲精品福利在线观看| 成年女人视频网站免费m| 国产精品免费视频观看拍拍| 亚洲视频2020| 一本色道久久88综合亚洲精品高清| 免费无码H肉动漫在线观看麻豆 | 亚洲国产精品不卡在线电影|