Code example for BigInteger

Methods: equals

0
            throw new NullPointerException("modulus == null");
        } else if (params[2] == null && !key.isEngineBased()) {
            throw new NullPointerException("privateExponent == null");
        } 
 
        modulus = new BigInteger(params[0]);
 
        // ENGINE-based keys are not guaranteed to have a private exponent. 
        if (params[2] != null) {
            privateExponent = new BigInteger(params[2]);
        } 
    } 
 
    @Override 
    public final BigInteger getPrivateExponent() {
        ensureReadParams(); 
        return privateExponent;
    } 
 
    @Override 
    public final BigInteger getModulus() {
        ensureReadParams(); 
        return modulus;
    } 
 
    @Override 
    public final byte[] getEncoded() { 
        /* 
         * If we're using an OpenSSL ENGINE, there's no guarantee we can export 
         * the key. Returning {@code null} tells the caller that there's no 
         * encoded format. 
         */ 
        if (key.isEngineBased()) {
            return null; 
        } 
 
        return NativeCrypto.i2d_PKCS8_PRIV_KEY_INFO(key.getPkeyContext());
    } 
 
    public final String getFormat() {
        /* 
         * If we're using an OpenSSL ENGINE, there's no guarantee we can export 
         * the key. Returning {@code null} tells the caller that there's no 
         * encoded format. 
         */ 
        if (key.isEngineBased()) {
            return null; 
        } 
 
        return "PKCS#8"; 
    } 
 
    @Override 
    public final String getAlgorithm() {
        return "RSA"; 
    } 
 
    public int getPkeyContext() { 
        return key.getPkeyContext();
    } 
 
    public String getPkeyAlias() {
        return key.getAlias();
    } 
 
    @Override 
    public boolean equals(Object o) {
        if (o == this) {
            return true; 
        } 
 
        if (o instanceof OpenSSLRSAPrivateKey) {
            OpenSSLRSAPrivateKey other = (OpenSSLRSAPrivateKey) o;
 
            /* 
             * We can shortcut the true case, but it still may be equivalent but 
             * different copies. 
             */ 
            if (key.equals(other.getOpenSSLKey())) {
                return true; 
            } 
 
            /* 
             * If this key is ENGINE-based, it could be equivalent to another 
             * ENGINE-based key. The modulus may be equal, but that occurrence 
             * should be so improbably low as to never happen. 
             */ 
            if (key.isEngineBased() || other.getOpenSSLKey().isEngineBased()) {
                return modulus.equals(other.getModulus());
            } 
        } 
 
        if (o instanceof RSAPrivateKey) {
            ensureReadParams(); 
            RSAPrivateKey other = (RSAPrivateKey) o;
 
            return modulus.equals(other.getModulus())
                    && privateExponent.equals(other.getPrivateExponent());
        } 
 
        return false; 
    }