All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.util.test.TestRandomBigInteger Maven / Gradle / Ivy

Go to download

The FIPS 140-3 Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms certified to FIPS 140-3 level 1. This jar contains JCE provider and low-level API for the BC-FJA version 2.0.0, FIPS Certificate #4743. Please see certificate for certified platform details.

There is a newer version: 2.0.0
Show newest version
package org.bouncycastle.util.test;

import org.bouncycastle.util.BigIntegers;

/**
 * A fixed secure random designed to return data for someone needing to create a single BigInteger.
 */
public class TestRandomBigInteger
    extends FixedSecureRandom
{
    /**
     * Constructor from a base 10 represention of a BigInteger.
     *
     * @param encoding a base 10 represention of a BigInteger.
     */
    public TestRandomBigInteger(String encoding)
    {
        this(encoding, 10);
    }

    /**
     * Constructor from a base radix represention of a BigInteger.
     *
     * @param encoding a String BigInteger of base radix.
     * @param radix the radix to use.
     */
    public TestRandomBigInteger(String encoding, int radix)
    {
        super(new FixedSecureRandom.BigInteger(BigIntegers.asUnsignedByteArray(new java.math.BigInteger(encoding, radix))));
    }

    /**
     * Constructor based on a byte array.
     *
     * @param encoding a 2's complement representation of the BigInteger.
     */
    public TestRandomBigInteger(byte[] encoding)
    {
        super(new FixedSecureRandom.BigInteger(encoding));
    }

    /**
     * Constructor which ensures encoding will produce a BigInteger from a request from the passed in bitLength.
     *
     * @param bitLength bit length for the BigInteger data request.
     * @param encoding bytes making up the encoding.
     */
    public TestRandomBigInteger(int bitLength, byte[] encoding)
    {
        super(new FixedSecureRandom.BigInteger(bitLength, encoding));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy