Java Doc for SecureRandom.java in  » 6.0-JDK-Modules » j2me » java » security » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » java.security 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.util.Random
      java.security.SecureRandom

SecureRandom
public class SecureRandom extends java.util.Random (Code)

This class provides a cryptographically strong pseudo-random number generator (PRNG). A cryptographically strong pseudo-random number minimally complies with the statistical random number generator tests specified in FIPS 140-2, Security Requirements for Cryptographic Modules, section 4.9.1. Additionally, SecureRandom must produce non-deterministic output and therefore it is required that the seed material be unpredictable and that output of SecureRandom be cryptographically strong sequences as described in RFC 1750: Randomness Recommendations for Security.

Like other algorithm-based classes in Java Security, SecureRandom provides implementation-independent algorithms, whereby a caller (application code) requests a particular PRNG algorithm and is handed back a SecureRandom object for that algorithm. It is also possible, if desired, to request a particular algorithm from a particular provider. See the getInstance methods.

Thus, there are two ways to request a SecureRandom object: by specifying either just an algorithm name, or both an algorithm name and a package provider.

  • If just an algorithm name is specified, as in:
     SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
     
    the system will determine if there is an implementation of the algorithm requested available in the environment, and if there is more than one, if there is a preferred one.

  • If both an algorithm name and a package provider are specified, as in:
     SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN");
     
    the system will determine if there is an implementation of the algorithm in the package requested, and throw an exception if there is not.

The SecureRandom implementation attempts to completely randomize the internal state of the generator itself unless the caller follows the call to a getInstance method with a call to the setSeed method:

 SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
 random.setSeed(seed);
 

After the caller obtains the SecureRandom object from the getInstance call, it can call nextBytes to generate random bytes:

 byte bytes[] = new byte[20];
 random.nextBytes(bytes);
 

The caller may also invoke the generateSeed method to generate a given number of seed bytes (to seed other random number generators, for example):

 byte seed[] = random.generateSeed(20);
 

See Also:   java.security.SecureRandomSpi
See Also:   java.util.Random
version:
   1.36, 02/02/00
author:
   Benjamin Renaud
author:
   Josh Bloch


Field Summary
final static  longserialVersionUID
    

Constructor Summary
public  SecureRandom()
    

By using this constructor, the caller obtains a SecureRandom object containing the implementation from the highest-priority installed provider that has a SecureRandom implementation.

Note that this instance of SecureRandom has not been seeded. A call to the setSeed method will seed the SecureRandom object.

public  SecureRandom(byte seed)
    

By using this constructor, the caller obtains a SecureRandom object containing the implementation from the highest-priority installed provider that has a SecureRandom implementation.

protected  SecureRandom(SecureRandomSpi secureRandomSpi, Provider provider)
     Creates a SecureRandom object.

Method Summary
public  byte[]generateSeed(int numBytes)
     Returns the given number of seed bytes, computed using the seed generation algorithm that this class uses to seed itself.
public static  SecureRandomgetInstance(String algorithm)
     Generates a SecureRandom object that implements the specified Pseudo Random Number Generator (PRNG) algorithm.
public static  SecureRandomgetInstance(String algorithm, String provider)
     Generates a SecureRandom object for the specified PRNG algorithm, as supplied from the specified provider, if such a PRNG implementation is available from the provider.

Note that the returned instance of SecureRandom has not been seeded. A call to the setSeed method will seed the SecureRandom object.

public static  SecureRandomgetInstance(String algorithm, Provider provider)
     Generates a SecureRandom object for the specified PRNG algorithm, as supplied from the specified provider, if such a PRNG implementation is available from the provider. Note: the provider doesn't have to be registered.
final public  ProvidergetProvider()
     Returns the provider of this SecureRandom object.
 SecureRandomSpigetSecureRandomSpi()
     Returns the SecureRandomSpi of this SecureRandom object.
public static  byte[]getSeed(int numBytes)
     Returns the given number of seed bytes, computed using the seed generation algorithm that this class uses to seed itself.
final protected  intnext(int numBits)
     Generates an integer containing the user-specified number of pseudo-random bits (right justified, with leading zeros).
public synchronized  voidnextBytes(byte[] bytes)
     Generates a user-specified number of random bytes.
public synchronized  voidsetSeed(byte[] seed)
     Reseeds this random object.
public  voidsetSeed(long seed)
     Reseeds this random object, using the eight bytes contained in the given long seed.

Field Detail
serialVersionUID
final static long serialVersionUID(Code)




Constructor Detail
SecureRandom
public SecureRandom()(Code)

By using this constructor, the caller obtains a SecureRandom object containing the implementation from the highest-priority installed provider that has a SecureRandom implementation.

Note that this instance of SecureRandom has not been seeded. A call to the setSeed method will seed the SecureRandom object. If a call is not made to setSeed, the first call to the nextBytes method will force the SecureRandom object to seed itself.

This constructor is provided for backwards compatibility. The caller is encouraged to use one of the alternative getInstance methods to obtain a SecureRandom object.




SecureRandom
public SecureRandom(byte seed)(Code)

By using this constructor, the caller obtains a SecureRandom object containing the implementation from the highest-priority installed provider that has a SecureRandom implementation. 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).

This constructor is provided for backwards compatibility. The caller is encouraged to use one of the alternative getInstance methods to obtain a SecureRandom object, and then to call the setSeed method to seed it.
Parameters:
  seed - the seed.




SecureRandom
protected SecureRandom(SecureRandomSpi secureRandomSpi, Provider provider)(Code)
Creates a SecureRandom object.
Parameters:
  secureRandomSpi - the SecureRandom implementation.
Parameters:
  provider - the provider.




Method Detail
generateSeed
public byte[] generateSeed(int numBytes)(Code)
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.
Parameters:
  numBytes - the number of seed bytes to generate. the seed bytes.



getInstance
public static SecureRandom getInstance(String algorithm) throws NoSuchAlgorithmException(Code)
Generates a SecureRandom object that implements the specified Pseudo Random Number Generator (PRNG) algorithm. If the default provider package provides an implementation of the requested PRNG, an instance of SecureRandom containing that implementation is returned. If the PRNG is not available in the default package, other packages are searched.

Note that the returned instance of SecureRandom has not been seeded. A call to the setSeed method will seed the SecureRandom object. If a call is not made to setSeed, the first call to the nextBytes method will force the SecureRandom object to seed itself.
Parameters:
  algorithm - the name of the PRNG algorithm.See Appendix A in the Java Cryptography Architecture API Specification & Reference for information about standard PRNG algorithm names. the new SecureRandom object.
exception:
  NoSuchAlgorithmException - if the PRNG algorithm isnot available in the caller's environment.
since:
   1.2




getInstance
public static SecureRandom getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException(Code)
Generates a SecureRandom object for the specified PRNG algorithm, as supplied from the specified provider, if such a PRNG implementation is available from the provider.

Note that the returned instance of SecureRandom has not been seeded. A call to the setSeed method will seed the SecureRandom object. If a call is not made to setSeed, the first call to the nextBytes method will force the SecureRandom object to seed itself.
Parameters:
  algorithm - the name of the PRNG algorithm.See Appendix A in the Java Cryptography Architecture API Specification & Reference for information about standard PRNG algorithm names.
Parameters:
  provider - the name of the provider. the new SecureRandom object.
exception:
  NoSuchAlgorithmException - if the requested PRNGimplementation is not available from the provider.
exception:
  NoSuchProviderException - if the provider has not beenconfigured.
exception:
  IllegalArgumentException - if the provider name is nullor empty.
See Also:   Provider
since:
   1.2




getInstance
public static SecureRandom getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException(Code)
Generates a SecureRandom object for the specified PRNG algorithm, as supplied from the specified provider, if such a PRNG implementation is available from the provider. Note: the provider doesn't have to be registered.

Note that the returned instance of SecureRandom has not been seeded. A call to the setSeed method will seed the SecureRandom object. If a call is not made to setSeed, the first call to the nextBytes method will force the SecureRandom object to seed itself.
Parameters:
  algorithm - the name of the PRNG algorithm.See Appendix A in the Java Cryptography Architecture API Specification & Reference for information about standard PRNG algorithm names.
Parameters:
  provider - the provider. the new SecureRandom object.
exception:
  NoSuchAlgorithmException - if the requested PRNGimplementation is not available from the provider.
exception:
  IllegalArgumentException - if the provider isnull.
See Also:   Provider
since:
   1.4




getProvider
final public Provider getProvider()(Code)
Returns the provider of this SecureRandom object. the provider of this SecureRandom object.



getSecureRandomSpi
SecureRandomSpi getSecureRandomSpi()(Code)
Returns the SecureRandomSpi of this SecureRandom object.



getSeed
public static byte[] getSeed(int numBytes)(Code)
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.

This method is only included for backwards compatibility. The caller is encouraged to use one of the alternative getInstance methods to obtain a SecureRandom object, and then call the generateSeed method to obtain seed bytes from that object.
Parameters:
  numBytes - the number of seed bytes to generate. the seed bytes.
See Also:   SecureRandom.setSeed




next
final protected int next(int numBits)(Code)
Generates an integer containing the user-specified number of pseudo-random bits (right justified, with leading zeros). This method overrides a java.util.Random method, and serves to provide a source of random bits to all of the methods inherited from that class (for example, nextInt, nextLong, and nextFloat).
Parameters:
  numBits - number of pseudo-random bits to be generated, where0 <= numBits <= 32. an int containing the user-specified numberof pseudo-random bits (right justified, with leading zeros).



nextBytes
public synchronized void nextBytes(byte[] bytes)(Code)
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).
Parameters:
  bytes - the array to be filled in with random bytes.



setSeed
public synchronized void setSeed(byte[] seed)(Code)
Reseeds this random object. The given seed supplements, rather than replaces, the existing seed. Thus, repeated calls are guaranteed never to reduce randomness.
Parameters:
  seed - the seed.
See Also:   SecureRandom.getSeed



setSeed
public void setSeed(long seed)(Code)
Reseeds this random object, using the eight bytes contained in the given long seed. The given seed supplements, rather than replaces, the existing seed. Thus, repeated calls are guaranteed never to reduce randomness.

This method is defined for compatibility with java.util.Random.
Parameters:
  seed - the seed.
See Also:   SecureRandom.getSeed




Methods inherited from java.util.Random
protected synchronized int next(int bits)(Code)(Java Doc)
public double nextDouble()(Code)(Java Doc)
public float nextFloat()(Code)(Java Doc)
public int nextInt()(Code)(Java Doc)
public int nextInt(int n)(Code)(Java Doc)
public long nextLong()(Code)(Java Doc)
public synchronized void setSeed(long seed)(Code)(Java Doc)

Methods inherited from java.lang.Object
public boolean equals(Object obj)(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.