資源簡介
Diffle-Human密鑰交換 java平臺實現 DH加密原理 生成的密鑰存于文件 實習總結

代碼片段和文件信息
import?java.io.FileInputStream;
import?java.io.objectInputStream;
import?java.security.PrivateKey;
import?java.security.PublicKey;
import?javax.crypto.KeyAgreement;
import?javax.crypto.spec.SecretKeySpec;
public?class?KeyAgree?{
/**
?*?@param?args
?*?@throws?Exception?
?*/
public?static?void?main(String[]?args)?throws?Exception?{
//?TODO?Auto-generated?method?stub
//讀取DH私鑰和對方公鑰
FileInputStream?f1?=?new?FileInputStream(“Skey_DH_pbk.dat“);
objectInputStream?b1?=?new?objectInputStream(f1);
PublicKey?pbk?=?(PublicKey)b1.readobject();
FileInputStream?f2?=?new?FileInputStream(“Skey_DH_prk.dat“);
objectInputStream?b2?=?new?objectInputStream(f2);
PrivateKey?prk?=?(PrivateKey)b2.readobject();
//創建私鑰協定對象
KeyAgreement?ka?=?KeyAgreement.getInstance(“DH“);
//用自己的私鑰初始化密鑰協定對象
ka.init(prk);?
/*執行私鑰協定對象的doPhase()方法,其在第一個參數中傳入對方公鑰*/
ka.doPhase(pbk?true);
//生成共享信息
?byte[]?sb?=?ka.generateSecret();??//生成共享秘密并在新的緩沖區中返回它
?for(int?i?=?0?;?i? ?System.out.print(sb[i]+““);
?}
?//創建密鑰
@SuppressWarnings(“unused“)
SecretKeySpec?k?=?new?SecretKeySpec(sb“DESede“);
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????232??2010-12-23?16:06??Diffle-Human\Diffle-Human\.classpath
?????文件????????388??2010-12-23?16:06??Diffle-Human\Diffle-Human\.project
?????文件???????1963??2010-12-25?23:09??Diffle-Human\Diffle-Human\bin\KeyAgree.class
?????文件???????2848??2010-12-25?23:09??Diffle-Human\Diffle-Human\bin\Key_DH.class
?????文件????????551??2010-12-23?17:02??Diffle-Human\Diffle-Human\Skey_DH_pbk.dat
?????文件????????489??2010-12-23?17:02??Diffle-Human\Diffle-Human\Skey_DH_prk.dat
?????文件???????1266??2010-12-23?17:40??Diffle-Human\Diffle-Human\src\KeyAgree.java
?????文件???????3167??2010-12-23?17:02??Diffle-Human\Diffle-Human\src\Key_DH.java
?????文件??????46592??2011-01-02?22:54??Diffle-Human\實習4—Diffle-Human.doc
?????目錄??????????0??2010-12-25?23:09??Diffle-Human\Diffle-Human\bin
?????目錄??????????0??2010-12-25?23:03??Diffle-Human\Diffle-Human\src
?????目錄??????????0??2010-12-25?23:03??Diffle-Human\Diffle-Human
?????目錄??????????0??2011-01-22?18:45??Diffle-Human
-----------?---------??----------?-----??----
????????????????57496????????????????????13
評論
共有 條評論