public static int getKeyLength(final PrivateKey privateKey)
	{
		int length = -1;
		if (privateKey == null)
		{
			return length;
		}
		if (privateKey instanceof RSAPrivateKey)
		{
			length = ((RSAPrivateKey)privateKey).getModulus().bitLength();
		}
		if (privateKey instanceof DSAPrivateKey)
		{
			length = ((DSAPrivateKey)privateKey).getParams().getQ().bitLength();
		}
		if (privateKey instanceof ECPrivateKey)
		{
			length = ((ECPrivateKey)privateKey).getParams().getCurve().getField().getFieldSize();
		}
		return length;
	}
public static int getKeyLength ( final PrivateKey privateKey ) { int length = - 1 ; if ( privateKey == null ) { return length ; } if ( privateKey instanceof RSAPrivateKey ) { length = ( ( RSAPrivateKey ) privateKey ) . getModulus ( ) . bitLength ( ) ; } if ( privateKey instanceof DSAPrivateKey ) { length = ( ( DSAPrivateKey ) privateKey ) . getParams ( ) . getQ ( ) . bitLength ( ) ; } if ( privateKey instanceof ECPrivateKey ) { length = ( ( ECPrivateKey ) privateKey ) . getParams ( ) . getCurve ( ) . getField ( ) . getFieldSize ( ) ; } return length ; }
Gets the key length of the given {@link PrivateKey}.

@param privateKey
the private key
@return the key length