Example usage for javax.crypto.spec RC5ParameterSpec RC5ParameterSpec

List of usage examples for javax.crypto.spec RC5ParameterSpec RC5ParameterSpec

Introduction

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

Prototype

public RC5ParameterSpec(int version, int rounds, int wordSize, byte[] iv) 

Source Link

Document

Constructs a parameter set for RC5 from the given version, number of rounds, word size (in bits), and IV.

Usage

From source file:it.scoppelletti.programmerpower.security.spi.RC5ParameterSpecFactory.java

public AlgorithmParameterSpec newInstance(Properties props, String prefix) {
    int rounds, version, wordSize;
    String name, value;/*from  w w w .jav a 2  s  .  co  m*/
    byte[] iv;
    AlgorithmParameterSpec param;

    name = Strings.concat(prefix, RC5ParameterSpecFactory.PROP_VERSION);
    value = props.getProperty(name);
    if (Strings.isNullOrEmpty(value)) {
        throw new ArgumentNullException(name);
    }

    version = Integer.parseInt(value);

    name = Strings.concat(prefix, RC5ParameterSpecFactory.PROP_ROUNDS);
    value = props.getProperty(name);
    if (Strings.isNullOrEmpty(value)) {
        throw new ArgumentNullException(name);
    }

    rounds = Integer.parseInt(value);

    name = Strings.concat(prefix, RC5ParameterSpecFactory.PROP_WORDSIZE);
    value = props.getProperty(name);
    if (Strings.isNullOrEmpty(value)) {
        throw new ArgumentNullException(name);
    }

    wordSize = Integer.parseInt(value);

    name = Strings.concat(prefix, RC5ParameterSpecFactory.PROP_IV);
    value = props.getProperty(name);
    if (Strings.isNullOrEmpty(value)) {
        iv = null;
    } else {
        try {
            iv = Hex.decodeHex(value.toCharArray());
        } catch (DecoderException ex) {
            throw SecurityUtils.toSecurityException(ex);
        }
    }

    if (iv != null) {
        param = new RC5ParameterSpec(version, rounds, wordSize, iv);
    } else {
        param = new RC5ParameterSpec(version, rounds, wordSize);
    }

    return param;
}