Java??4???????????????
???????????? ???????[ 2015/6/23 11:06:41 ] ??????????????? Java
????3.SHA
??????????????Secure Hash Algorithm???????????????????????Digital Signature Standard DSS?????漲??????????????Digital Signature Algorithm DSA???????????С??2^64λ???????SHA1????????160λ????????????????????????????????????????????????????????á??????????????????????????????????????????????????Σ??????С???????????????????????????????????????????????????????????????λ?????????????м????????????????????????????????????к????????????????????“???”????“??”??????????????????????????????????????????
????java????
????package com.cn.???????;
????import java.math.BigInteger;
????import java.security.MessageDigest;
????/*
????SHA(Secure Hash Algorithm??????????????????????????????????????????
??????????????????????????????????????SHA??MD5??????????????????
????????SHA??????????????????????MD5??????*/
????public class SHA{
????public static final String KEY_SHA="SHA";
????public static String getResult(String inputStr)
????{
????BigInteger sha=null;
????System.out.println("=======???????????:"+inputStr);
????byte[]inputData=inputStr.getBytes();
????try{
????MessageDigest messageDigest=MessageDigest.getInstance(KEY_SHA);
????messageDigest.update(inputData);
????sha=new BigInteger(messageDigest.digest());
????System.out.println("SHA?????:"+sha.toString(32));
????}catch(Exception e){e.printStackTrace();}
????return sha.toString(32);
????}
????public static void main(String args[])
????{
????try{
????String inputStr="??????";
????getResult(inputStr);
????}catch(Exception e){
????e.printStackTrace();
????}
????}
????}
????SHA-1??MD5????
??????????????MD4??????SHA-1??MD5????????????????????????????????????????????????????????
????l????й???????????????????????????SHA-1????MD5????32λ???????м??????????κ??????????????????????????????MD5??2^128?????????????????SHA-1????2^160???????????????????SHA-1????й????и????????
????l????????????????????MD5????????????????????????SHA-1??ò????????????????
????l?????????????????SHA-1??????????MD5????
????4.HMAC
????HMAC(Hash Message Authentication Code???????????????????????Hash???????Э?顣???????????????????????ù????????????????????????????????????????????????????????????????????????????????????С??С????飬??MAC???????????????У???????????????????????????????м?????????
????java??????
????package com.cn.???????;
????/*
????HMAC
????HMAC(Hash Message Authentication Code???????????????????????Hash???????Э?顣
???????????????????????????ù???????????????????????????????????????????????????????????????
?????????????????????????С??С????飬
??????MAC???????????????У???????????????????????????????м?????????*/
????import javax.crypto.KeyGenerator;
????import javax.crypto.Mac;
????import javax.crypto.SecretKey;
????import javax.crypto.spec.SecretKeySpec;
????import com.cn.comm.Tools;
????/**
????*???????????
????*/
????public abstract class HMAC{
????public static final String KEY_MAC="HmacMD5";
????/**
????*?????HMAC???
????*
????*@return
????*@throws Exception
????*/
????public static String initMacKey()throws Exception{
????KeyGenerator keyGenerator=KeyGenerator.getInstance(KEY_MAC);
????SecretKey secretKey=keyGenerator.generateKey();
????return BASE64.encryptBASE64(secretKey.getEncoded());
????}
????/**
????*HMAC????????????
????*
????*@param data
????*@param key
????*@return
????*@throws Exception
????*/
????public static String encryptHMAC(byte[]data??String key)throws Exception{
????SecretKey secretKey=new SecretKeySpec(BASE64.decryptBASE64(key)??KEY_MAC);
????Mac mac=Mac.getInstance(secretKey.getAlgorithm());
????mac.init(secretKey);
????return new String(mac.doFinal(data));
????}
????public static String getResult1(String inputStr)
????{
????String path=Tools.getClassPath();
????String fileSource=path+"/file/HMAC_key.txt";
????System.out.println("=======???????????:"+inputStr);
????String result=null;
????try{
????byte[]inputData=inputStr.getBytes();
????String key=HMAC.initMacKey();/*???????*/
????System.out.println("Mac???:==="+key);
????/*?????д???*/
????Tools.WriteMyFile(fileSource??key);
????result=HMAC.encryptHMAC(inputData??key);
????System.out.println("HMAC?????:==="+result);
????}catch(Exception e){e.printStackTrace();}
????return result.toString();
????}
????public static String getResult2(String inputStr)
????{
????System.out.println("=======???????????:"+inputStr);
????String path=Tools.getClassPath();
????String fileSource=path+"/file/HMAC_key.txt";
????String key=null;;
????try{
????/*???????????ж??*/
????key=Tools.ReadMyFile(fileSource);
????System.out.println("getResult2???:==="+key);
????}catch(Exception e1){
????e1.printStackTrace();}
????String result=null;
????try{
????byte[]inputData=inputStr.getBytes();
????/*????????м???*/
????result=HMAC.encryptHMAC(inputData??key);
????System.out.println("HMAC?????:==="+result);
????}catch(Exception e){e.printStackTrace();}
????return result.toString();
????}
????public static void main(String args[])
????{
????try{
????String inputStr="??????";
????/*??????????????????м?????????μ????????????*/
????getResult1(inputStr);
????getResult2(inputStr);
????}catch(Exception e){
????e.printStackTrace();
????}
????}
????}
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Java???????????Щ???????????????Java????????????????Java?б???Map????????Java Web???????????????Java??????????????д?????Java????????7???????????????????????(java .net ?????)???Java??????????Python??????Java webdriver??λ????????′????е?????Java??д??????????????????Java???????????????JavaScript????????????Java?????????????????? Java???????10??????????????Java?м????????????????java???????ü???????????м???????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????