GalaxyPilot —— D.S


                  生命不熄,戰斗不止
          數據加載中……

          有關數字簽名的東東

          import java.io.*;
          import java.security.*;

          /**
          ?* <p>Title: 數字簽名工具類</p>
          ?* <p>Description: 使用非對稱密匙的私匙對輸入信息加密</p>
          ?* <p>Copyright: Copyright (c) 2003</p>
          ?* <p>Company: </p>
          ?* @author not galaxyp
          ?* @version 1.0
          ?*/

          public class DSAUtil {
          ? public DSAUtil() {
          ? }
          ? /*
          ?? * 根據傳入的密匙文件路徑加密信息,并保存到指定的目錄下
          ?? * @param pOrgiInfo 要加密的信息
          ?? * @param pPrikeyPath 加密的私匙路徑和文件名
          ?? * @param pInfoPath 保存密文的路徑
          ?? */
          ? private void encryptInfo(String pOrgiInfo,String pPrikeyPath,String pInfoPath)throws Exception{
          ??? ObjectInputStream in=new ObjectInputStream(new FileInputStream(pPrikeyPath));
          ??? PrivateKey myprikey=(PrivateKey)in.readObject();
          ??? Signature signet=Signature.getInstance("DSA");
          ??? signet.initSign(myprikey);
          ??? signet.update(pOrgiInfo.getBytes());
          ??? byte[] signed=signet.sign();
          ??? ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream(pInfoPath+"\\out.dat"));
          ??? out.writeObject(pOrgiInfo);
          ??? out.writeObject(signed);
          ??? out.close();
          ? }
          ? public static void main(String[] args) {
          ??? DSAUtil DSAUtil1 = new DSAUtil();
          ??? if(args == null || args.length != 3){
          ????? System.out.println("沒有輸入必要的信息");
          ????? System.out.println("\t參數一:要加密的信息");
          ????? System.out.println("\t參數二:私匙文件完整路徑和文件名");
          ????? System.out.println("\t參數三:保存密文的路徑,文件名為out.dat");
          ????? return;
          ??? }
          ??? String info = args[0];
          ??? String pPrikeyPath = args[1];
          ??? String pInfoPath = args[2];
          ??? try{
          ????? DSAUtil1.encryptInfo(info,pPrikeyPath,pInfoPath);
          ??? }catch(Exception e){
          ????? e.printStackTrace();
          ????? System.out.println("簽名失敗");
          ??? }
          ? }

          }

          posted on 2006-03-17 17:05 舵手 閱讀(1241) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 都兰县| 东乌珠穆沁旗| 镇巴县| 徐水县| 瑞丽市| 石台县| 镇原县| 海伦市| 枞阳县| 鄢陵县| 安顺市| 综艺| 古交市| 页游| 开鲁县| 中阳县| 新巴尔虎左旗| 乐清市| 松原市| 社会| 盐津县| 云霄县| 大同市| 福海县| 万宁市| 文山县| 阿城市| 永川市| 远安县| 昌吉市| 扬州市| 平昌县| 秦皇岛市| 亳州市| 景泰县| 二手房| 石台县| 宁德市| 仙居县| 牙克石市| 余姚市|