...
This compliant solution uses the equals() method as a first test and then compares the encoded version of the keys to facilitate provider-independent behavior. In this example, we check It checks whether an RSAPrivateKey and an RSAPrivateCrtKey represent equivalent private keys [Sun 2006].
...