// 
// Decompiled by Procyon v0.6.0
// 

package com.nimbusds.jose.crypto.impl;

import java.security.interfaces.RSAPrivateKey;
import com.nimbusds.jose.JOSEException;
import java.security.PrivateKey;
import com.nimbusds.jose.jwk.RSAKey;

public class RSAKeyUtils
{
    public static PrivateKey toRSAPrivateKey(final RSAKey rsaJWK) throws JOSEException {
        if (!rsaJWK.isPrivate()) {
            throw new JOSEException("The RSA JWK doesn't contain a private part");
        }
        return rsaJWK.toPrivateKey();
    }
    
    public static int keyBitLength(final PrivateKey privateKey) {
        if (!(privateKey instanceof RSAPrivateKey)) {
            return -1;
        }
        final RSAPrivateKey rsaPrivateKey = (RSAPrivateKey)privateKey;
        try {
            return rsaPrivateKey.getModulus().bitLength();
        }
        catch (final Exception e) {
            return -1;
        }
    }
}
