blob: 00f541420f754ffe587d97f30de8fe9092dbcee9 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc (build 1.6.0_65) on Tue Feb 25 18:15:47 EST 2014 -->
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>
RandomNumberGenerator (Apache Shiro 1.2.3 API)
</TITLE>
<META NAME="date" CONTENT="2014-02-25">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style">
<SCRIPT type="text/javascript">
function windowTitle()
{
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="RandomNumberGenerator (Apache Shiro 1.2.3 API)";
}
}
</SCRIPT>
<NOSCRIPT>
</NOSCRIPT>
</HEAD>
<BODY BGCOLOR="white" onload="windowTitle();">
<HR>
<!-- ========= START OF TOP NAVBAR ======= -->
<A NAME="navbar_top"><!-- --></A>
<A HREF="#skip-navbar_top" title="Skip navigation links"></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/RandomNumberGenerator.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../../../org/apache/shiro/crypto/PaddingScheme.html" title="enum in org.apache.shiro.crypto"><B>PREV CLASS</B></A>&nbsp;
&nbsp;<A HREF="../../../../org/apache/shiro/crypto/SecureRandomNumberGenerator.html" title="class in org.apache.shiro.crypto"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../../index.html?org/apache/shiro/crypto/RandomNumberGenerator.html" target="_top"><B>FRAMES</B></A> &nbsp;
&nbsp;<A HREF="RandomNumberGenerator.html" target="_top"><B>NO FRAMES</B></A> &nbsp;
&nbsp;<SCRIPT type="text/javascript">
<!--
if(window==top) {
document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>');
}
//-->
</SCRIPT>
<NOSCRIPT>
<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL:&nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_top"></A>
<!-- ========= END OF TOP NAVBAR ========= -->
<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
<FONT SIZE="-1">
org.apache.shiro.crypto</FONT>
<BR>
Interface RandomNumberGenerator</H2>
<DL>
<DT><B>All Known Implementing Classes:</B> <DD><A HREF="../../../../org/apache/shiro/crypto/SecureRandomNumberGenerator.html" title="class in org.apache.shiro.crypto">SecureRandomNumberGenerator</A></DD>
</DL>
<HR>
<DL>
<DT><PRE>public interface <A HREF="../../../../src-html/org/apache/shiro/crypto/RandomNumberGenerator.html#line.49"><B>RandomNumberGenerator</B></A></DL>
</PRE>
<P>
A component that can generate random number/byte values as needed. Useful in cryptography or security scenarios
where random byte arrays are needed, such as for password salts, nonces, initialization vectors and other seeds.
<p/>
This is essentially the same as a <A HREF="http://java.sun.com/javase/6/docs/api/java/security/SecureRandom.html?is-external=true" title="class or interface in java.security"><CODE>SecureRandom</CODE></A>, and indeed implementations
of this interface will probably all use <A HREF="http://java.sun.com/javase/6/docs/api/java/security/SecureRandom.html?is-external=true" title="class or interface in java.security"><CODE>SecureRandom</CODE></A> instances, but this
interface provides a few additional benefits to end-users:
<ul>
<li>It is an interface rather than the JDK's <code>SecureRandom</code> concrete implementation. Implementation details
can be customized as necessary based on the application's needs</li>
<li>Default per-instance behavior can be customized on implementations, typically via JavaBeans mutators.</li>
<li>Perhaps most important for Shiro end-users, tt can more easily be used as a source of cryptographic seed data,
and the data returned is already in a more convenient <A HREF="../../../../org/apache/shiro/util/ByteSource.html" title="interface in org.apache.shiro.util"><CODE>ByteSource</CODE></A> format in case that data needs
to be <A HREF="../../../../org/apache/shiro/util/ByteSource.html#toHex()"><CODE>hex</CODE></A> or
<A HREF="../../../../org/apache/shiro/util/ByteSource.html#toBase64()"><CODE>base64</CODE></A>-encoded.</li>
</ul>
For example, consider the following example generating password salts for new user accounts:
<pre>
RandomNumberGenerator saltGenerator = new <A HREF="../../../../org/apache/shiro/crypto/SecureRandomNumberGenerator.html" title="class in org.apache.shiro.crypto"><CODE>SecureRandomNumberGenerator</CODE></A>();
User user = new User();
user.setPasswordSalt(saltGenerator.nextBytes().toBase64());
userDAO.save(user);
</pre>
<P>
<P>
<DL>
<DT><B>Since:</B></DT>
<DD>1.1</DD>
</DL>
<HR>
<P>
<!-- ========== METHOD SUMMARY =========== -->
<A NAME="method_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Method Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../../../../org/apache/shiro/util/ByteSource.html" title="interface in org.apache.shiro.util">ByteSource</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../org/apache/shiro/crypto/RandomNumberGenerator.html#nextBytes()">nextBytes</A></B>()</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Generates a byte array of fixed length filled with random data, often useful for generating salts,
initialization vectors or other seed data.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../../../../org/apache/shiro/util/ByteSource.html" title="interface in org.apache.shiro.util">ByteSource</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../org/apache/shiro/crypto/RandomNumberGenerator.html#nextBytes(int)">nextBytes</A></B>(int&nbsp;numBytes)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Generates a byte array of the specified length filled with random data.</TD>
</TR>
</TABLE>
&nbsp;
<P>
<!-- ============ METHOD DETAIL ========== -->
<A NAME="method_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Method Detail</B></FONT></TH>
</TR>
</TABLE>
<A NAME="nextBytes()"><!-- --></A><H3>
nextBytes</H3>
<PRE>
<A HREF="../../../../org/apache/shiro/util/ByteSource.html" title="interface in org.apache.shiro.util">ByteSource</A> <A HREF="../../../../src-html/org/apache/shiro/crypto/RandomNumberGenerator.html#line.62"><B>nextBytes</B></A>()</PRE>
<DL>
<DD>Generates a byte array of fixed length filled with random data, often useful for generating salts,
initialization vectors or other seed data. The length is specified as a configuration
value on the underlying implementation.
<p/>
If you'd like per-invocation control the number of bytes generated, use the
<A HREF="../../../../org/apache/shiro/crypto/RandomNumberGenerator.html#nextBytes(int)"><CODE>nextBytes(int)</CODE></A> method instead.
<P>
<DD><DL>
<DT><B>Returns:</B><DD>a byte array of fixed length filled with random data.<DT><B>See Also:</B><DD><A HREF="../../../../org/apache/shiro/crypto/RandomNumberGenerator.html#nextBytes(int)"><CODE>nextBytes(int)</CODE></A></DL>
</DD>
</DL>
<HR>
<A NAME="nextBytes(int)"><!-- --></A><H3>
nextBytes</H3>
<PRE>
<A HREF="../../../../org/apache/shiro/util/ByteSource.html" title="interface in org.apache.shiro.util">ByteSource</A> <A HREF="../../../../src-html/org/apache/shiro/crypto/RandomNumberGenerator.html#line.71"><B>nextBytes</B></A>(int&nbsp;numBytes)</PRE>
<DL>
<DD>Generates a byte array of the specified length filled with random data.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>numBytes</CODE> - the number of bytes to be populated with random data.
<DT><B>Returns:</B><DD>a byte array of the specified length filled with random data.<DT><B>See Also:</B><DD><A HREF="../../../../org/apache/shiro/crypto/RandomNumberGenerator.html#nextBytes()"><CODE>nextBytes()</CODE></A></DL>
</DD>
</DL>
<!-- ========= END OF CLASS DATA ========= -->
<HR>
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<A NAME="navbar_bottom"><!-- --></A>
<A HREF="#skip-navbar_bottom" title="Skip navigation links"></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_bottom_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/RandomNumberGenerator.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../../../org/apache/shiro/crypto/PaddingScheme.html" title="enum in org.apache.shiro.crypto"><B>PREV CLASS</B></A>&nbsp;
&nbsp;<A HREF="../../../../org/apache/shiro/crypto/SecureRandomNumberGenerator.html" title="class in org.apache.shiro.crypto"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../../index.html?org/apache/shiro/crypto/RandomNumberGenerator.html" target="_top"><B>FRAMES</B></A> &nbsp;
&nbsp;<A HREF="RandomNumberGenerator.html" target="_top"><B>NO FRAMES</B></A> &nbsp;
&nbsp;<SCRIPT type="text/javascript">
<!--
if(window==top) {
document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>');
}
//-->
</SCRIPT>
<NOSCRIPT>
<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL:&nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_bottom"></A>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<HR>
Copyright &#169; 2004-2014 <a href="http://www.apache.org/">The Apache Software Foundation</a>. All Rights Reserved.
</BODY>
</HTML>