java.security
Class SecureRandom
- Serializable
An interface to a cryptographically secure pseudo-random number
generator (PRNG). Random (or at least unguessable) numbers are used
in all areas of security and cryptography, from the generation of
keys and initialization vectors to the generation of random padding
bytes.
byte[] | generateSeed(int numBytes) - Returns the specified number of seed bytes.
|
String | getAlgorithm() - Returns the algorithm name used or "unknown" when the algorithm
used couldn't be determined (as when constructed by the protected
2 argument constructor).
|
static SecureRandom | getInstance(String algorithm) - Returns an instance of a
SecureRandom from the first provider
that implements it.
|
static SecureRandom | getInstance(String algorithm, String provider) - Returns an instance of a
SecureRandom for the specified
algorithm from the named provider.
|
static SecureRandom | getInstance(String algorithm, Provider provider) - Returns an instance of a
SecureRandom for the specified
algorithm from the given provider.
|
Provider | getProvider() - Returns the provider being used by the current SecureRandom class.
|
static byte[] | getSeed(int numBytes) - Returns the given number of seed bytes.
|
protected int | next(int numBits) - Generates an integer containing the user specified
number of random bits.
|
void | nextBytes(byte[] bytes) - Generates a user specified number of bytes.
|
void | setSeed(byte[] seed) - Seeds the SecureRandom.
|
void | setSeed(long seed) - Seeds the SecureRandom.
|
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
SecureRandom
public SecureRandom()
Default constructor for SecureRandom. It constructs a
new SecureRandom by instantating the first SecureRandom
algorithm in the default security provier.
It is not seeded and should be seeded using setSeed or else
on the first call to getnextBytes it will force a seed.
It is maintained for backwards compatibility and programs
should use
getInstance(String)
.
SecureRandom
public SecureRandom(byte[] seed)
A constructor for SecureRandom. It constructs a new
SecureRandom by instantating the first SecureRandom algorithm
in the default security provier.
It is seeded with the passed function and is useful if the user
has access to hardware random device (like a radiation detector).
It is maintained for backwards compatibility and programs
should use getInstance.
seed
- Seed bytes for class
SecureRandom
protected SecureRandom(SecureRandomSpi secureRandomSpi,
Provider provider)
A constructor for SecureRandom. It constructs a new
SecureRandom using the specified SecureRandomSpi from
the specified security provier.
secureRandomSpi
- A SecureRandomSpi classprovider
- A Provider class
generateSeed
public byte[] generateSeed(int numBytes)
Returns the specified number of seed bytes.
numBytes
- number of seed bytes to get
- an array containing the seed bytes
getAlgorithm
public String getAlgorithm()
Returns the algorithm name used or "unknown" when the algorithm
used couldn't be determined (as when constructed by the protected
2 argument constructor).
getInstance
public static SecureRandom getInstance(String algorithm)
throws NoSuchAlgorithmException
Returns an instance of a SecureRandom
from the first provider
that implements it.
algorithm
- The algorithm name.
- A new
SecureRandom
implementing the given algorithm.
getProvider
public final Provider getProvider()
Returns the provider being used by the current SecureRandom class.
- The provider from which this SecureRandom was attained
getSeed
public static byte[] getSeed(int numBytes)
Returns the given number of seed bytes. This method is
maintained only for backwards capability.
numBytes
- number of seed bytes to get
- an array containing the seed bytes
next
protected final int next(int numBits)
Generates an integer containing the user specified
number of random bits. It is right justified and padded
with zeros.
- next in interface Random
numBits
- number of random bits to get, 0 <= numBits <= 32;
nextBytes
public void nextBytes(byte[] bytes)
Generates a user specified number of bytes. This function
is the basis for all the random functions.
- nextBytes in interface Random
bytes
- array to store generated bytes in
setSeed
public void setSeed(byte[] seed)
Seeds the SecureRandom. The class is re-seeded for each call and
each seed builds on the previous seed so as not to weaken security.
seed
- seed bytes to seed with
setSeed
public void setSeed(long seed)
Seeds the SecureRandom. The class is re-seeded for each call and
each seed builds on the previous seed so as not to weaken security.
- setSeed in interface Random
seed
- 8 seed bytes to seed with
SecureRandom.java --- Secure Random class implementation
Copyright (C) 1999, 2001, 2002, 2003, 2005, 2006
Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.