0
我有一個小程序,首先交換會話密鑰進行通信,並且它使用diffie-hellmann協議。 在java中第一部分被這樣完成的:如何從PublicKey得到未編碼的公共值字節
KeyPairGenerator keyPairGenerator1 = KeyPairGenerator.getInstance("DH");
keyPairGenerator1.initialize(Skip.sDHParameterSpec);
KeyPair keyPair1 = keyPairGenerator1.generateKeyPair();
byte[] localKey1 = keyPair1.getPublic().getEncoded();
KeyAgreement keyAgreement1 = KeyAgreement.getInstance("DH");
keyAgreement1.init(keyPair1.getPrivate());
// getting remote key
keyAgreement1.doPhase(theirPublicKey2, true);
byte[] sharedKey1 = keyAgreement1.generateSecret();
然後localKey是發送到遠程部件,誰發送回數據的它們部分進行計算DH共享密鑰。 問題,另一個程序期望獲得行數據(大整數),並從Java程序發送X509編碼。
那麼如何從PublicKey獲取BigInteger(DH協議的本地Y值)呢? 或者也許有另一種方法來生成必要的DH參數?
哦,不要忘了驗證參數,不要忘記DH本身有助於防止竊聽... –
我以爲我試過「keyPair.getPublic()instanceof DHPublicKey」,但顯然不是(或然後檢查別的東西)。謝謝你的回答。 – Dainius
也許http://stackoverflow.com/questions/496928/what-is-the-difference-between-instanceof-and-class-isassignablefrom有幫助嗎? –