Java 类org.bouncycastle.crypto.params.DSAKeyParameters 实例源码

项目:portecle    文件:KeyPairUtil.java   
/**
 * Get the key size of a key represented by key parameters.
 * 
 * @param keyParams The key parameters
 * @return The key size, {@link #UNKNOWN_KEY_SIZE} if not known
 */
public static int getKeyLength(AsymmetricKeyParameter keyParams)
{
    if (keyParams instanceof RSAKeyParameters)
    {
        return ((RSAKeyParameters) keyParams).getModulus().bitLength();
    }
    else if (keyParams instanceof DSAKeyParameters)
    {
        return ((DSAKeyParameters) keyParams).getParameters().getP().bitLength();
    }
    else if (keyParams instanceof DHKeyParameters)
    {
        return ((DHKeyParameters) keyParams).getParameters().getP().bitLength();
    }
    else if (keyParams instanceof ECKeyParameters)
    {
        // TODO: how to get key length from these?
        return UNKNOWN_KEY_SIZE;
    }

    LOG.warning("Don't know how to get key size from parameters " + keyParams);
    return UNKNOWN_KEY_SIZE;
}