📄 securerandom.html
字号:
<!-- ========= CONSTRUCTOR DETAIL ======== --><A NAME="constructor_detail"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=1><FONT SIZE="+2"><B>Constructor Detail</B></FONT></TD></TR></TABLE><A NAME="SecureRandom()"><!-- --></A><H3>SecureRandom</H3><PRE>public <B>SecureRandom</B>()</PRE><DL><DD><p>By using this constructor, the caller obtains a SecureRandom object containing the implementation from the highest-priority installed provider that has a SecureRandom implementation. <p>Note that this instance of SecureRandom has not been seeded. A call to the <code>setSeed</code> method will seed the SecureRandom object. If a call is not made to <code>setSeed</code>, the first call to the <code>nextBytes</code> method will force the SecureRandom object to seed itself. <p>This constructor is provided for backwards compatibility. The caller is encouraged to use one of the alternative <code>getInstance</code> methods to obtain a SecureRandom object.</DL><HR><A NAME="SecureRandom(byte[])"><!-- --></A><H3>SecureRandom</H3><PRE>public <B>SecureRandom</B>(byte[] seed)</PRE><DL><DD><p>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). <p>This constructor is provided for backwards compatibility. The caller is encouraged to use one of the alternative <code>getInstance</code> methods to obtain a SecureRandom object, and then to call the <code>setSeed</code> method to seed it.<DD><DL><DT><B>Parameters:</B><DD><CODE>seed</CODE> - the seed.</DL></DD></DL><HR><A NAME="SecureRandom(java.security.SecureRandomSpi, java.security.Provider)"><!-- --></A><H3>SecureRandom</H3><PRE>protected <B>SecureRandom</B>(<A HREF="../../java/security/SecureRandomSpi.html">SecureRandomSpi</A> secureRandomSpi, <A HREF="../../java/security/Provider.html">Provider</A> provider)</PRE><DL><DD>Creates a SecureRandom object.<DD><DL><DT><B>Parameters:</B><DD><CODE>secureRandomSpi</CODE> - the SecureRandom implementation.<DD><CODE>provider</CODE> - the provider.</DL></DD></DL><!-- ============ METHOD DETAIL ========== --><A NAME="method_detail"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=1><FONT SIZE="+2"><B>Method Detail</B></FONT></TD></TR></TABLE><A NAME="getInstance(java.lang.String)"><!-- --></A><H3>getInstance</H3><PRE>public static <A HREF="../../java/security/SecureRandom.html">SecureRandom</A> <B>getInstance</B>(<A HREF="../../java/lang/String.html">String</A> algorithm) throws <A HREF="../../java/security/NoSuchAlgorithmException.html">NoSuchAlgorithmException</A></PRE><DL><DD>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. <p>Note that the returned instance of SecureRandom has not been seeded. A call to the <code>setSeed</code> method will seed the SecureRandom object. If a call is not made to <code>setSeed</code>, the first call to the <code>nextBytes</code> method will force the SecureRandom object to seed itself.<DD><DL><DT><B>Parameters:</B><DD><CODE>algorithm</CODE> - the name of the PRNG algorithm. See Appendix A in the <a href= "../../../guide/security/CryptoSpec.html#AppA"> Java Cryptography Architecture API Specification & Reference </a> for information about standard PRNG algorithm names.<DT><B>Returns:</B><DD>the new SecureRandom object.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/security/NoSuchAlgorithmException.html">NoSuchAlgorithmException</A></CODE> - if the PRNG algorithm is not available in the caller's environment.<DT><B>Since: </B><DD>1.2</DD></DL></DD></DL><HR><A NAME="getInstance(java.lang.String, java.lang.String)"><!-- --></A><H3>getInstance</H3><PRE>public static <A HREF="../../java/security/SecureRandom.html">SecureRandom</A> <B>getInstance</B>(<A HREF="../../java/lang/String.html">String</A> algorithm, <A HREF="../../java/lang/String.html">String</A> provider) throws <A HREF="../../java/security/NoSuchAlgorithmException.html">NoSuchAlgorithmException</A>, <A HREF="../../java/security/NoSuchProviderException.html">NoSuchProviderException</A></PRE><DL><DD>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. <p>Note that the returned instance of SecureRandom has not been seeded. A call to the <code>setSeed</code> method will seed the SecureRandom object. If a call is not made to <code>setSeed</code>, the first call to the <code>nextBytes</code> method will force the SecureRandom object to seed itself.<DD><DL><DT><B>Parameters:</B><DD><CODE>algorithm</CODE> - the name of the PRNG algorithm. See Appendix A in the <a href= "../../../guide/security/CryptoSpec.html#AppA"> Java Cryptography Architecture API Specification & Reference </a> for information about standard PRNG algorithm names.<DD><CODE>provider</CODE> - the name of the provider.<DT><B>Returns:</B><DD>the new SecureRandom object.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/security/NoSuchAlgorithmException.html">NoSuchAlgorithmException</A></CODE> - if the requested PRNG implementation is not available from the provider.<DD><CODE><A HREF="../../java/security/NoSuchProviderException.html">NoSuchProviderException</A></CODE> - if the provider has not been configured.<DT><B>Since: </B><DD>1.2</DD><DT><B>See Also: </B><DD><A HREF="../../java/security/Provider.html"><CODE>Provider</CODE></A></DL></DD></DL><HR><A NAME="getProvider()"><!-- --></A><H3>getProvider</H3><PRE>public final <A HREF="../../java/security/Provider.html">Provider</A> <B>getProvider</B>()</PRE><DL><DD>Returns the provider of this SecureRandom object.<DD><DL><DT><B>Returns:</B><DD>the provider of this SecureRandom object.</DL></DD></DL><HR><A NAME="setSeed(byte[])"><!-- --></A><H3>setSeed</H3><PRE>public void <B>setSeed</B>(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.<DD><DL><DT><B>Parameters:</B><DD><CODE>seed</CODE> - the seed.</DL></DD></DL><HR><A NAME="setSeed(long)"><!-- --></A><H3>setSeed</H3><PRE>public void <B>setSeed</B>(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>.<DD><DL><DT><B>Overrides:</B><DD><CODE><A HREF="../../java/util/Random.html#setSeed(long)">setSeed</A></CODE> in class <CODE><A HREF="../../java/util/Random.html">Random</A></CODE></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>seed</CODE> - the seed.</DL></DD></DL><HR><A NAME="nextBytes(byte[])"><!-- --></A><H3>nextBytes</H3><PRE>public void <B>nextBytes</B>(byte[] bytes)</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).<DD><DL><DT><B>Overrides:</B><DD><CODE><A HREF="../../java/util/Random.html#nextBytes(byte[])">nextBytes</A></CODE> in class <CODE><A HREF="../../java/util/Random.html">Random</A></CODE></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>bytes</CODE> - the array to be filled in with random bytes.</DL></DD></DL><HR><A NAME="next(int)"><!-- --></A><H3>next</H3><PRE>protected final int <B>next</B>(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>).<DD><DL><DT><B>Overrides:</B><DD><CODE><A HREF="../../java/util/Random.html#next(int)">next</A></CODE> in class <CODE><A HREF="../../java/util/Random.html">Random</A></CODE></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>numBits</CODE> - number of pseudo-random bits to be generated, where 0 <= <code>numBits</code> <= 32.<DT><B>Returns:</B><DD>an <code>int</code> containing the user-specified number of pseudo-random bits (right justified, with leading zeros).</DL></DD></DL><HR><A NAME="getSeed(int)"><!-- --></A><H3>getSeed</H3><PRE>public static byte[] <B>getSeed</B>(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. <p>This method is only included for backwards compatibility. The caller is encouraged to use one of the alternative <code>getInstance</code> methods to obtain a SecureRandom object, and then call the <code>generateSeed</code> method to obtain seed bytes from that object.<DD><DL><DT><B>Parameters:</B><DD><CODE>numBytes</CODE> - the number of seed bytes to generate.<DT><B>Returns:</B><DD>the seed bytes.</DL></DD></DL><HR><A NAME="generateSeed(int)"><!-- --></A><H3>generateSeed</H3><PRE>public byte[] <B>generateSeed</B>(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.<DD><DL><DT><B>Parameters:</B><DD><CODE>numBytes</CODE> - the number of seed bytes to generate.<DT><B>Returns:</B><DD>the seed bytes.</DL></DD></DL><!-- ========= END OF CLASS DATA ========= --><HR><!-- ========== START OF NAVBAR ========== --><A NAME="navbar_bottom"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0"><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_bottom_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3"> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/SecureRandom.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><b>Java<sup><font size=-2>TM</font></sup> 2 Platform<br>Std. Ed. v1.3</b></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../java/security/SecureClassLoader.html"><B>PREV CLASS</B></A> <A HREF="../../java/security/SecureRandomSpi.html"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../index.html" TARGET="_top"><B>FRAMES</B></A> <A HREF="SecureRandom.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: INNER | FIELD | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><!-- =========== END OF NAVBAR =========== --><HR><font size="-1"><a href="http://java.sun.com/cgi-bin/bugreport.cgi">Submit a bug or feature</a><br>For further API reference and developer documentation, see <a href="http://java.sun.com/products/jdk/1.3/devdocs-vs-specs.html">Java 2 SDK SE Developer Documentation</a>. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. <p>Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.<br>Copyright 1993-2000 Sun Microsystems, Inc. 901 San Antonio Road<br>Palo Alto, California, 94303, U.S.A. All Rights Reserved.</font></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -