IAIK PKCS#11 Provider Micro Edition
version 1.0

iaik.pkcs.pkcs11.me
Class SecureRandom

java.lang.Object
  extended byiaik.pkcs.pkcs11.me.SecureRandom

public class SecureRandom
extends java.lang.Object

An object of this class generates random bytes using the associated token. The random bytes come directly from the token. There is no intermediate pseudo random generator.
The application can also feed in seed bytes into the token's random generator (if the token supports this feature). Note that feeding in some seed bytes can never reduce the quality of the generated random bytes, even if all seed bytes are constant or zero. In most cases, it may not be required to feed in some seed to get good random data. Please refer to your token documentation for details.

A typical piece of code using this class may look like this.

  Token token = ...
  if (!token.supportsSecureRandom()) {
    ... // token does not have a random generator
  }
  SecureRandom tokenRandom = token.getSecureRandom();
 
  // optionally feed in some seed
  byte[] seed = ... // get some seed bytes
  tokenRandom.setSeed(seed);
 
  // get random bytes
  byte[] randomData = new byte[1024];
  tokenRandom.nextBytes(randomData);
 
The variable randomData will hold the random data.

This class is not thread safe.

See Also:
Token, Token.getSecureRandom(), Token.supportsSecureRandom()

Method Summary
 void nextBytes(byte[] buffer)
          Get random bytes from the token's random generator.
 void setSeed(byte[] seed)
          Feed some seed into the random generator of the token.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setSeed

public void setSeed(byte[] seed)
             throws PKCS11RuntimeException
Feed some seed into the random generator of the token. Note that feeding in some seed bytes can never reduce the quality of the generated random bytes, even if all seed bytes are constant or zero. In most cases, it may not be required to feed in some seed to get good random data. Please refer to your token documentation for details.

Parameters:
seed - The seed bytes.
Throws:
PKCS11RuntimeException - If feeding the seeds into the token's random generator fails; e.g. if the token does not support this feature.

nextBytes

public void nextBytes(byte[] buffer)
               throws PKCS11RuntimeException
Get random bytes from the token's random generator. The number of bytes generated equals the size of the given input buffer. The generated bytes will be copied into this buffer,

Parameters:
buffer - The buffer to receive the random data.
Throws:
PKCS11RuntimeException - If generating random data fails; e.g. if the token does not support this feature.

IAIK PKCS#11 Provider Micro Edition
version 1.0

IAIK JavaSecurity Website http://jce.iaik.tugraz.at/

IAIK at Graz University of Technology, Austria, Europe
Copyright 2001-2005, IAIK, Graz University of Technology, Inffeldgasse 16a, 8010 Graz, Austria. All Rights Reserved.
version 1.0