public PublicKey verifyIdentity ( byte [ ] sharedSecret ) throws IOException , GeneralSecurityException { try { String serverKeyAlgorithm = readUTF ( ) ; PublicKey spk = KeyFactory . getInstance ( serverKeyAlgorithm ) . generatePublic ( readKey ( ) ) ; // verify the identity of the server Signature sig = Signature . getInstance ( "SHA1with" + serverKeyAlgorithm ) ; sig . initVerify ( spk ) ; sig . update ( spk . getEncoded ( ) ) ; sig . update ( sharedSecret ) ; sig . verify ( ( byte [ ] ) readObject ( ) ) ; return spk ; } catch ( ClassNotFoundException e ) { throw new Error ( e ) ; // impossible } }
Verifies that we are talking to a peer that actually owns the private key corresponding to the public key we get .