PrivateKeyFile: Add validateKeyPairs()

Router: Validate router key pairs read in from file
This commit is contained in:
zzz
2014-08-25 16:55:16 +00:00
parent f83007e038
commit c5c158e983
3 changed files with 41 additions and 1 deletions

View File

@ -53,7 +53,7 @@ public class PrivateKeyFile {
protected final File file;
private final I2PClient client;
private Destination dest;
protected Destination dest;
protected PrivateKey privKey;
protected SigningPrivateKey signingPrivKey;
@ -455,6 +455,23 @@ public class PrivateKeyFile {
}
}
/**
* Verify that the PublicKey matches the PrivateKey, and
* the SigningPublicKey matches the SigningPrivateKey.
*
* @return success
* @since 0.9.16
*/
public boolean validateKeyPairs() {
try {
if (!dest.getPublicKey().equals(KeyGenerator.getPublicKey(privKey)))
return false;
return dest.getSigningPublicKey().equals(KeyGenerator.getSigningPublicKey(signingPrivKey));
} catch (IllegalArgumentException iae) {
return false;
}
}
@Override
public String toString() {
StringBuilder s = new StringBuilder(128);