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

org.bouncycastle.crypto.test.JournalingSecureRandomTest Maven / Gradle / Ivy

Go to download

The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 and up.

There is a newer version: 1.70
Show newest version
package org.bouncycastle.crypto.test;

import java.security.SecureRandom;

import org.bouncycastle.crypto.util.JournalingSecureRandom;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.test.SimpleTest;

public class JournalingSecureRandomTest
    extends SimpleTest
{
    public String getName()
    {
        return "JournalingSecureRandom";
    }

    public void performTest()
        throws Exception
    {
        SecureRandom rand = new SecureRandom();

        JournalingSecureRandom jRandom1 = new JournalingSecureRandom(rand);

        byte[] base = new byte[1024];

        jRandom1.nextBytes(base);

        byte[] transcript = jRandom1.getTranscript();

        byte[] block = new byte[512];

        JournalingSecureRandom jRandom2 = new JournalingSecureRandom(transcript, rand);

        jRandom2.nextBytes(block);

        areEqual(Arrays.copyOfRange(base, 0, 512), block);

        jRandom2.nextBytes(block);

        areEqual(Arrays.copyOfRange(base, 512, 1024), block);

        jRandom2.nextBytes(block);

        isTrue(!Arrays.areEqual(Arrays.copyOfRange(base, 0, 512), block));

    }

    public static void main(
        String[] args)
    {
        runTest(new JournalingSecureRandomTest());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy