Example usage for javax.crypto.spec RC2ParameterSpec getEffectiveKeyBits

List of usage examples for javax.crypto.spec RC2ParameterSpec getEffectiveKeyBits

Introduction

In this page you can find the example usage for javax.crypto.spec RC2ParameterSpec getEffectiveKeyBits.

Prototype

public int getEffectiveKeyBits() 

Source Link

Document

Returns the effective key size in bits.

Usage

From source file:mitm.common.security.smime.SMIMEEncryptionAlgorithm.java

/**
 * Returns the effective key size (in bits) of the given algorithm. Returns -1 if the key size
 * cannot be determined.  /*from  ww  w. ja va 2  s.  c om*/
 * @param algorithm
 * @param parameters
 * @return
 */
public static int getKeySize(SMIMEEncryptionAlgorithm algorithm, AlgorithmParameters parameters) {
    int strength = -1;

    if (algorithm == null) {
        return strength;
    }

    if (algorithm.fixedSize) {
        strength = algorithm.defaultKeySize();
    } else {
        if (parameters != null) {
            if (algorithm == RC2_CBC) {
                try {
                    RC2ParameterSpec rc2Params = parameters.getParameterSpec(RC2ParameterSpec.class);

                    strength = rc2Params.getEffectiveKeyBits();
                } catch (InvalidParameterSpecException e) {
                    logger.error("RC2ParameterSpec is invalid.", e);
                }
            }
            // TODO: add CAST5_CBC support
        }
    }

    return strength;
}