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

项目: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;
}
项目:Aki-SSL    文件:IESCipher.java   
public int engineGetOutputSize(int inputLen)
{
    int len1, len2, len3;

    if (key == null)
    {
        throw new IllegalStateException("cipher not initialised");
    }

    len1 = engine.getMac().getMacSize();

    if (otherKeyParameter == null)
    {
        len2 = 1 + 2 * (((DHKeyParameters)key).getParameters().getP().bitLength() + 7) / 8;
    }
    else
    {
        len2 = 0;
    }

    if (engine.getCipher() == null)
    {
        len3 = inputLen;
    }
    else if (state == Cipher.ENCRYPT_MODE || state == Cipher.WRAP_MODE)
    {
        len3 = engine.getCipher().getOutputSize(inputLen);
    }
    else if (state == Cipher.DECRYPT_MODE || state == Cipher.UNWRAP_MODE)
    {
        len3 = engine.getCipher().getOutputSize(inputLen - len1 - len2);
    }
    else
    {
        throw new IllegalStateException("cipher not initialised");
    }

    if (state == Cipher.ENCRYPT_MODE || state == Cipher.WRAP_MODE)
    {
        return buffer.size() + len1 + len2 + len3;
    }
    else if (state == Cipher.DECRYPT_MODE || state == Cipher.UNWRAP_MODE)
    {
        return buffer.size() - len1 - len2 + len3;
    }
    else
    {
        throw new IllegalStateException("IESCipher not initialised");
    }

}