I'm trying to find a way to validate that two SSH2 keys, one private and one public, belong to the same key pair. I have used JSch for loading and parsing the private key.
Update: A snippet that could show how to regenerate the public key from the private key (SSH2 RSA) would solve the problem.
You could do this with the BouncyCastle lightweight API.
For example:
InputStream in = new FileInputStream("path/to/private/key");
AsymmetricKeyParameter privateKey = PrivateKeyFactory.createKey(in);
RSAPrivateCrtKeyParameters rsaPrivateKey = (RSAPrivateCrtKeyParameters)privateKey;
BigInteger modulus = rsaPrivateKey.getModulus();
BigInteger publicExponent = rsaPrivateKey.getPublicExponent();
RSAKeyParameters publicKeyParams = new RSAKeyParameters(false, modulus, publicExponent);
The RSAKeyParameters
class represents the actual key.
Hope that helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With