@Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }

        if (o instanceof OpenSSLRSAPrivateKey) {
            OpenSSLRSAPrivateKey other = (OpenSSLRSAPrivateKey) o;
            return getOpenSSLKey().equals(other.getOpenSSLKey());
        }

        if (o instanceof RSAPrivateCrtKey) {
            ensureReadParams();
            RSAPrivateCrtKey other = (RSAPrivateCrtKey) o;

            if (getOpenSSLKey().isHardwareBacked()) {
                return getModulus().equals(other.getModulus())
                        && publicExponent.equals(other.getPublicExponent());
            } else {
                return getModulus().equals(other.getModulus())
                        && publicExponent.equals(other.getPublicExponent())
                        && getPrivateExponent().equals(other.getPrivateExponent())
                        && primeP.equals(other.getPrimeP()) && primeQ.equals(other.getPrimeQ())
                        && primeExponentP.equals(other.getPrimeExponentP())
                        && primeExponentQ.equals(other.getPrimeExponentQ())
                        && crtCoefficient.equals(other.getCrtCoefficient());
            }
        } else if (o instanceof RSAPrivateKey) {
            ensureReadParams();
            RSAPrivateKey other = (RSAPrivateKey) o;

            if (getOpenSSLKey().isHardwareBacked()) {
                return getModulus().equals(other.getModulus());
            } else {
                return getModulus().equals(other.getModulus())
                        && getPrivateExponent().equals(other.getPrivateExponent());
            }
        }

        return false;
    }
An implementation of {@link java.security.PrivateKey} for RSA keys which uses BoringSSL to
perform all the operations.
common/src/main/java/org/conscrypt/OpenSSLRSAPrivateCrtKey.java