<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<!--NewPage-->
<html>
<head>
<!-- Generated by javadoc on Wed Jul 28 01:21:15 GMT 1999 -->
<title>
  Class java.security.SecureRandom
</title>
</head>
<body>
<a name="_top_"></a>
<pre>
<a href="packages.html">All Packages</a>  <a href="tree.html">Class Hierarchy</a>  <a href="Package-java.security.html">This Package</a>  <a href="java.security.Provider.html#_top_">Previous</a>  <a href="java.security.Security.html#_top_">Next</a>  <a href="AllNames.html">Index</a></pre>
<hr>
<h1>
  Class java.security.SecureRandom
</h1>
<pre>
<a href="java.lang.Object.html#_top_">java.lang.Object</a>
   |
   +----<a href="java.util.Random.html#_top_">java.util.Random</a>
           |
           +----java.security.SecureRandom
</pre>
<hr>
<dl>
  <dt> public class <b>SecureRandom</b>
  <dt> extends <a href="java.util.Random.html#_top_">Random</a>
</dl>
<p>This class provides a crytpographically strong pseudo-random number
 generator based on the SHA-1 hash algorithm.
 <p>The calls inherited from Random will be implemented in terms of the
 strengthened functionality.
<p>
<dl>
    <dt> <b>See Also:</b>
    <dd> <a href="java.util.Random.html#_top_">Random</a>
</dl>
<hr>
<a name="index"></a>
<h2>
  <img src="images/constructor-index.gif" width=275 height=38 alt="Constructor Index">
</h2>
<dl>
  <dt> <img src="images/yellow-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#SecureRandom()"><b>SecureRandom</b></a>()
  <dd>  This empty constructor automatically seeds the generator.
  <dt> <img src="images/yellow-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#SecureRandom(byte[])"><b>SecureRandom</b></a>(byte[])
  <dd>  This constructor uses a user-provided seed in preference to the
 self-seeding algorithm referred to in the empty constructor
 description.
</dl>
<h2>
  <img src="images/method-index.gif" width=207 height=38 alt="Method Index">
</h2>
<dl>
  <dt> <img src="images/green-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#getSeed(int)"><b>getSeed</b></a>(int)
  <dd>  Returns the given number of seed bytes, computed using the seed
 generation algorithm that this class uses to seed itself.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#next(int)"><b>next</b></a>(int)
  <dd>  Generates an integer containing the user-specified number of
 pseudo-random bits (right justified, with leading zeros).
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#nextBytes(byte[])"><b>nextBytes</b></a>(byte[])
  <dd>  Generates a user-specified number of random bytes.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#setSeed(byte[])"><b>setSeed</b></a>(byte[])
  <dd>  Reseeds this random object.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#setSeed(long)"><b>setSeed</b></a>(long)
  <dd>  Reseeds this random object, using the eight bytes contained
 in the given <code>long seed</code>.
</dl>
<a name="constructors"></a>
<h2>
  <img src="images/constructors.gif" width=231 height=38 alt="Constructors">
</h2>
<a name="SecureRandom"></a>
<a name="SecureRandom()"><img src="images/yellow-ball.gif" width=12 height=12 alt=" o "></a>
<b>SecureRandom</b>
<pre>
 public SecureRandom()
</pre>
<dl>
  <dd> This empty constructor automatically seeds the generator.  We attempt
 to provide sufficient seed bytes to completely randomize the internal
 state of the generator (20 bytes).  Note, however, that our seed
 generation algorithm has not been thoroughly studied or widely deployed.
 <p>The first time this constructor is called in a given Virtual Machine,
 it may take several seconds of CPU time to seed the generator, depending
 on the underlying hardware.  Successive calls run quickly because they
 rely on the same (internal) pseudo-random number generator for their
 seed bits.
 <p>The seeding procedure implemented by this constructor ensures that
 the sequence of pseudo-random bytes produced by each SecureRandom
 instance yields no useful information about the byte-sequence produced
 by any other instance.  If however, the user wishes to produce multiple
 instances with truly unrelated seeds, the following code yields
 the desired result (at substantial CPU cost per instance!):<p>
 <pre>
 SecureRandom rnd = new SecureRandom(SecureRandom.getSeed(20));
 </pre>
<p>
</dl>
<a name="SecureRandom(byte[])"><img src="images/yellow-ball.gif" width=12 height=12 alt=" o "></a>
<b>SecureRandom</b>
<pre>
 public SecureRandom(byte seed[])
</pre>
<dl>
  <dd> This constructor uses a user-provided seed in preference to the
 self-seeding algorithm referred to in the empty constructor
 description. It may be preferable to the empty constructor if the
 caller has access to high-quality random bytes from some physical
 device (for example, a radiation detector or a noisy diode).
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> seed - the seed.
  </dl></dd>
</dl>
<a name="methods"></a>
<h2>
  <img src="images/methods.gif" width=151 height=38 alt="Methods">
</h2>
<a name="setSeed(byte[])"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="setSeed"><b>setSeed</b></a>
<pre>
 public synchronized void setSeed(byte seed[])
</pre>
<dl>
  <dd> Reseeds this random object. The given seed supplements, rather than
 replaces, the existing seed. Thus, repeated calls are guaranteed
 never to reduce randomness.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> seed - the seed.
  </dl></dd>
</dl>
<a name="setSeed(long)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="setSeed"><b>setSeed</b></a>
<pre>
 public void setSeed(long seed)
</pre>
<dl>
  <dd> Reseeds this random object, using the eight bytes contained
 in the given <code>long seed</code>. The given seed supplements,
 rather than replaces, the existing seed. Thus, repeated calls
 are guaranteed never to reduce randomness.
 <p>This method is defined for compatibility with
 <code>java.util.Random</code>.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> seed - the seed.
    <dt> <b>Overrides:</b>
    <dd> <a href="java.util.Random.html#setSeed(long)">setSeed</a> in class <a href="java.util.Random.html#_top_">Random</a>
  </dl></dd>
</dl>
<a name="nextBytes(byte[])"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="nextBytes"><b>nextBytes</b></a>
<pre>
 public synchronized void nextBytes(byte result[])
</pre>
<dl>
  <dd> Generates a user-specified number of random bytes.  This method is
 used as the basis of all random entities returned by this class
 (except seed bytes).  Thus, it may be overridden to change the
 behavior of the class.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> bytes - the array to be filled in with random bytes.
    <dt> <b>Overrides:</b>
    <dd> <a href="java.util.Random.html#nextBytes(byte[])">nextBytes</a> in class <a href="java.util.Random.html#_top_">Random</a>
  </dl></dd>
</dl>
<a name="next(int)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="next"><b>next</b></a>
<pre>
 protected final int next(int numBits)
</pre>
<dl>
  <dd> Generates an integer containing the user-specified number of
 pseudo-random bits (right justified, with leading zeros).  This
 method overrides a <code>java.util.Random</code> method, and serves
 to provide a source of random bits to all of the methods inherited
 from that class (for example, <code>nextInt</code>,
 <code>nextLong</code>, and <code>nextFloat</code>).
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> numBits - number of pseudo-random bits to be generated, where
 0 <= <code>numBits</code> <= 32.
    <dt> <b>Overrides:</b>
    <dd> <a href="java.util.Random.html#next(int)">next</a> in class <a href="java.util.Random.html#_top_">Random</a>
  </dl></dd>
</dl>
<a name="getSeed(int)"><img src="images/green-ball.gif" width=12 height=12 alt=" o "></a>
<a name="getSeed"><b>getSeed</b></a>
<pre>
 public static byte[] getSeed(int numBytes)
</pre>
<dl>
  <dd> Returns the given number of seed bytes, computed using the seed
 generation algorithm that this class uses to seed itself.  This
 call may be used to seed other random number generators.  While
 we attempt to return a "truly random" sequence of bytes, we do not
 know exactly how random the bytes returned by this call are.  (See
 the empty constructor <a href = "#SecureRandom">SecureRandom</a>
 for a brief description of the underlying algorithm.)
 The prudent user will err on the side of caution and get extra
 seed bytes, although it should be noted that seed generation is
 somewhat costly.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> numBytes - the number of seed bytes to generate.
    <dt> <b>Returns:</b>
    <dd> the seed bytes.
  </dl></dd>
</dl>
<hr>
<pre>
<a href="packages.html">All Packages</a>  <a href="tree.html">Class Hierarchy</a>  <a href="Package-java.security.html">This Package</a>  <a href="java.security.Provider.html#_top_">Previous</a>  <a href="java.security.Security.html#_top_">Next</a>  <a href="AllNames.html">Index</a></pre>
</body>
</html>
