| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| <!-- NewPage --> |
| <html lang="en"> |
| <head> |
| <!-- Generated by javadoc (version 1.7.0_21) on Thu May 30 15:02:18 PDT 2013 --> |
| <meta http-equiv="Content-Type" content="text/html" charset="UTF-8"> |
| <title>DefaultHashService (Apache Shiro 1.2.2 API)</title> |
| <meta name="date" content="2013-05-30"> |
| <link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style"> |
| </head> |
| <body> |
| <script type="text/javascript"><!-- |
| if (location.href.indexOf('is-external=true') == -1) { |
| parent.document.title="DefaultHashService (Apache Shiro 1.2.2 API)"; |
| } |
| //--> |
| </script> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| |
| <!-- ========= START OF TOP NAVBAR ======= --> |
| <div class="topNav"><a name="navbar_top"> |
| <!-- --> |
| </a><a href="#skip-navbar_top" title="Skip navigation links"></a><a name="navbar_top_firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../../../overview-summary.html">Overview</a></li> |
| <li><a href="package-summary.html">Package</a></li> |
| <li class="navBarCell1Rev">Class</li> |
| <li><a href="class-use/DefaultHashService.html">Use</a></li> |
| <li><a href="package-tree.html">Tree</a></li> |
| <li><a href="../../../../../deprecated-list.html">Deprecated</a></li> |
| <li><a href="../../../../../index-all.html">Index</a></li> |
| <li><a href="../../../../../help-doc.html">Help</a></li> |
| </ul> |
| </div> |
| <div class="subNav"> |
| <ul class="navList"> |
| <li><a href="../../../../../org/apache/shiro/crypto/hash/ConfigurableHashService.html" title="interface in org.apache.shiro.crypto.hash"><span class="strong">Prev Class</span></a></li> |
| <li><a href="../../../../../org/apache/shiro/crypto/hash/Hash.html" title="interface in org.apache.shiro.crypto.hash"><span class="strong">Next Class</span></a></li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="../../../../../index.html?org/apache/shiro/crypto/hash/DefaultHashService.html" target="_top">Frames</a></li> |
| <li><a href="DefaultHashService.html" target="_top">No Frames</a></li> |
| </ul> |
| <ul class="navList" id="allclasses_navbar_top"> |
| <li><a href="../../../../../allclasses-noframe.html">All Classes</a></li> |
| </ul> |
| <div> |
| <script type="text/javascript"><!-- |
| allClassesLink = document.getElementById("allclasses_navbar_top"); |
| if(window==top) { |
| allClassesLink.style.display = "block"; |
| } |
| else { |
| allClassesLink.style.display = "none"; |
| } |
| //--> |
| </script> |
| </div> |
| <div> |
| <ul class="subNavList"> |
| <li>Summary: </li> |
| <li>Nested | </li> |
| <li>Field | </li> |
| <li><a href="#constructor_summary">Constr</a> | </li> |
| <li><a href="#method_summary">Method</a></li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Field | </li> |
| <li><a href="#constructor_detail">Constr</a> | </li> |
| <li><a href="#method_detail">Method</a></li> |
| </ul> |
| </div> |
| <a name="skip-navbar_top"> |
| <!-- --> |
| </a></div> |
| <!-- ========= END OF TOP NAVBAR ========= --> |
| <!-- ======== START OF CLASS DATA ======== --> |
| <div class="header"> |
| <div class="subTitle">org.apache.shiro.crypto.hash</div> |
| <h2 title="Class DefaultHashService" class="title">Class DefaultHashService</h2> |
| </div> |
| <div class="contentContainer"> |
| <ul class="inheritance"> |
| <li><a href="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">java.lang.Object</a></li> |
| <li> |
| <ul class="inheritance"> |
| <li>org.apache.shiro.crypto.hash.DefaultHashService</li> |
| </ul> |
| </li> |
| </ul> |
| <div class="description"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <dl> |
| <dt>All Implemented Interfaces:</dt> |
| <dd><a href="../../../../../org/apache/shiro/crypto/hash/ConfigurableHashService.html" title="interface in org.apache.shiro.crypto.hash">ConfigurableHashService</a>, <a href="../../../../../org/apache/shiro/crypto/hash/HashService.html" title="interface in org.apache.shiro.crypto.hash">HashService</a></dd> |
| </dl> |
| <hr> |
| <br> |
| <pre>public class <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.69">DefaultHashService</a> |
| extends <a href="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</a> |
| implements <a href="../../../../../org/apache/shiro/crypto/hash/ConfigurableHashService.html" title="interface in org.apache.shiro.crypto.hash">ConfigurableHashService</a></pre> |
| <div class="block">Default implementation of the <a href="../../../../../org/apache/shiro/crypto/hash/HashService.html" title="interface in org.apache.shiro.crypto.hash"><code>HashService</code></a> interface, supporting a customizable hash algorithm name, |
| secure-random salt generation, multiple hash iterations and an optional internal |
| <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#setPrivateSalt(org.apache.shiro.util.ByteSource)"><code>privateSalt</code></a>. |
| <h2>Hash Algorithm</h2> |
| You may specify a hash algorithm via the <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#setHashAlgorithmName(java.lang.String)"><code>setHashAlgorithmName(String)</code></a> property. Any algorithm name |
| understood by the JDK |
| <a href="http://java.sun.com/javase/6/docs/api/java/security/MessageDigest.html?is-external=true#getInstance(java.lang.String)" title="class or interface in java.security"><code>MessageDigest.getInstance(String algorithmName)</code></a> method |
| will work. The default is <code>SHA-512</code>. |
| <h2>Random Salts</h2> |
| When a salt is not specified in a request, this implementation generates secure random salts via its |
| <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#setRandomNumberGenerator(org.apache.shiro.crypto.RandomNumberGenerator)"><code>randomNumberGenerator</code></a> property. |
| Random salts (and potentially combined with the internal <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#getPrivateSalt()"><code>privateSalt</code></a>) is a very strong |
| salting strategy, as salts should ideally never be based on known/guessable data. The default instance is a |
| <a href="../../../../../org/apache/shiro/crypto/SecureRandomNumberGenerator.html" title="class in org.apache.shiro.crypto"><code>SecureRandomNumberGenerator</code></a>. |
| <h2>Hash Iterations</h2> |
| Secure hashing strategies often employ multiple hash iterations to slow down the hashing process. This technique |
| is usually used for password hashing, since the longer it takes to compute a password hash, the longer it would |
| take for an attacker to compromise a password. This |
| <a href="http://www.katasoft.com/blog/2011/04/04/strong-password-hashing-apache-shiro">Katasoft blog article</a> |
| explains in greater detail why this is useful, as well as information on how many iterations is 'enough'. |
| <p/> |
| You may set the number of hash iterations via the <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#setHashIterations(int)"><code>setHashIterations(int)</code></a> property. The default is |
| <code>1</code>, but should be increased significantly if the <code>HashService</code> is intended to be used for password |
| hashing. See the linked blog article for more info. |
| <h2>Private Salt</h2> |
| If using this implementation as part of a password hashing strategy, it might be desirable to configure a |
| <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#setPrivateSalt(org.apache.shiro.util.ByteSource)"><code>private salt</code></a>: |
| <p/> |
| A hash and the salt used to compute it are often stored together. If an attacker is ever able to access |
| the hash (e.g. during password cracking) and it has the full salt value, the attacker has all of the input necessary |
| to try to brute-force crack the hash (source + complete salt). |
| <p/> |
| However, if part of the salt is not available to the attacker (because it is not stored with the hash), it is |
| <em>much</em> harder to crack the hash value since the attacker does not have the complete inputs necessary. |
| <p/> |
| The <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#getPrivateSalt()"><code>privateSalt</code></a> property exists to satisfy this private-and-not-shared part of the salt. |
| If you configure this attribute, you can obtain this additional very important safety feature. |
| <p/> |
| <b>*</b>By default, the <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#getPrivateSalt()"><code>privateSalt</code></a> is null, since a sensible default cannot be used that |
| isn't easily compromised (because Shiro is an open-source project and any default could be easily seen and used).</div> |
| <dl><dt><span class="strong">Since:</span></dt> |
| <dd>1.2</dd></dl> |
| </li> |
| </ul> |
| </div> |
| <div class="summary"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <!-- ======== CONSTRUCTOR SUMMARY ======== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="constructor_summary"> |
| <!-- --> |
| </a> |
| <h3>Constructor Summary</h3> |
| <table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation"> |
| <caption><span>Constructors</span><span class="tabEnd"> </span></caption> |
| <tr> |
| <th class="colOne" scope="col">Constructor and Description</th> |
| </tr> |
| <tr class="altColor"> |
| <td class="colOne"><code><strong><a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#DefaultHashService()">DefaultHashService</a></strong>()</code> |
| <div class="block">Constructs a new <code>DefaultHashService</code> instance with the following defaults: |
| |
| <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#setHashAlgorithmName(java.lang.String)"><code>hashAlgorithmName</code></a> = <code>SHA-512</code> |
| <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#setHashIterations(int)"><code>hashIterations</code></a> = <code>1</code> |
| <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#setRandomNumberGenerator(org.apache.shiro.crypto.RandomNumberGenerator)"><code>randomNumberGenerator</code></a> = |
| new <a href="../../../../../org/apache/shiro/crypto/SecureRandomNumberGenerator.html" title="class in org.apache.shiro.crypto"><code>SecureRandomNumberGenerator</code></a>() |
| <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#setGeneratePublicSalt(boolean)"><code>generatePublicSalt</code></a> = <code>false</code> |
| |
| <p/> |
| If this hashService will be used for password hashing it is recommended to set the |
| <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#setPrivateSalt(org.apache.shiro.util.ByteSource)"><code>privateSalt</code></a> and significantly increase the number of |
| <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#setHashIterations(int)"><code>hashIterations</code></a>.</div> |
| </td> |
| </tr> |
| </table> |
| </li> |
| </ul> |
| <!-- ========== METHOD SUMMARY =========== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="method_summary"> |
| <!-- --> |
| </a> |
| <h3>Method Summary</h3> |
| <table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation"> |
| <caption><span>Methods</span><span class="tabEnd"> </span></caption> |
| <tr> |
| <th class="colFirst" scope="col">Modifier and Type</th> |
| <th class="colLast" scope="col">Method and Description</th> |
| </tr> |
| <tr class="altColor"> |
| <td class="colFirst"><code>protected <a href="../../../../../org/apache/shiro/util/ByteSource.html" title="interface in org.apache.shiro.util">ByteSource</a></code></td> |
| <td class="colLast"><code><strong><a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#combine(org.apache.shiro.util.ByteSource, org.apache.shiro.util.ByteSource)">combine</a></strong>(<a href="../../../../../org/apache/shiro/util/ByteSource.html" title="interface in org.apache.shiro.util">ByteSource</a> privateSalt, |
| <a href="../../../../../org/apache/shiro/util/ByteSource.html" title="interface in org.apache.shiro.util">ByteSource</a> publicSalt)</code> |
| <div class="block">Combines the specified 'private' salt bytes with the specified additional extra bytes to use as the |
| total salt during hash computation.</div> |
| </td> |
| </tr> |
| <tr class="rowColor"> |
| <td class="colFirst"><code><a href="../../../../../org/apache/shiro/crypto/hash/Hash.html" title="interface in org.apache.shiro.crypto.hash">Hash</a></code></td> |
| <td class="colLast"><code><strong><a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#computeHash(org.apache.shiro.crypto.hash.HashRequest)">computeHash</a></strong>(<a href="../../../../../org/apache/shiro/crypto/hash/HashRequest.html" title="interface in org.apache.shiro.crypto.hash">HashRequest</a> request)</code> |
| <div class="block">Computes and responds with a hash based on the specified request.</div> |
| </td> |
| </tr> |
| <tr class="altColor"> |
| <td class="colFirst"><code>protected <a href="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a></code></td> |
| <td class="colLast"><code><strong><a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#getAlgorithmName(org.apache.shiro.crypto.hash.HashRequest)">getAlgorithmName</a></strong>(<a href="../../../../../org/apache/shiro/crypto/hash/HashRequest.html" title="interface in org.apache.shiro.crypto.hash">HashRequest</a> request)</code> </td> |
| </tr> |
| <tr class="rowColor"> |
| <td class="colFirst"><code><a href="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a></code></td> |
| <td class="colLast"><code><strong><a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#getHashAlgorithmName()">getHashAlgorithmName</a></strong>()</code> </td> |
| </tr> |
| <tr class="altColor"> |
| <td class="colFirst"><code>int</code></td> |
| <td class="colLast"><code><strong><a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#getHashIterations()">getHashIterations</a></strong>()</code> </td> |
| </tr> |
| <tr class="rowColor"> |
| <td class="colFirst"><code>protected int</code></td> |
| <td class="colLast"><code><strong><a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#getIterations(org.apache.shiro.crypto.hash.HashRequest)">getIterations</a></strong>(<a href="../../../../../org/apache/shiro/crypto/hash/HashRequest.html" title="interface in org.apache.shiro.crypto.hash">HashRequest</a> request)</code> </td> |
| </tr> |
| <tr class="altColor"> |
| <td class="colFirst"><code><a href="../../../../../org/apache/shiro/util/ByteSource.html" title="interface in org.apache.shiro.util">ByteSource</a></code></td> |
| <td class="colLast"><code><strong><a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#getPrivateSalt()">getPrivateSalt</a></strong>()</code> </td> |
| </tr> |
| <tr class="rowColor"> |
| <td class="colFirst"><code>protected <a href="../../../../../org/apache/shiro/util/ByteSource.html" title="interface in org.apache.shiro.util">ByteSource</a></code></td> |
| <td class="colLast"><code><strong><a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#getPublicSalt(org.apache.shiro.crypto.hash.HashRequest)">getPublicSalt</a></strong>(<a href="../../../../../org/apache/shiro/crypto/hash/HashRequest.html" title="interface in org.apache.shiro.crypto.hash">HashRequest</a> request)</code> |
| <div class="block">Returns the public salt that should be used to compute a hash based on the specified request or |
| <code>null</code> if no public salt should be used.</div> |
| </td> |
| </tr> |
| <tr class="altColor"> |
| <td class="colFirst"><code><a href="../../../../../org/apache/shiro/crypto/RandomNumberGenerator.html" title="interface in org.apache.shiro.crypto">RandomNumberGenerator</a></code></td> |
| <td class="colLast"><code><strong><a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#getRandomNumberGenerator()">getRandomNumberGenerator</a></strong>()</code> </td> |
| </tr> |
| <tr class="rowColor"> |
| <td class="colFirst"><code>boolean</code></td> |
| <td class="colLast"><code><strong><a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#isGeneratePublicSalt()">isGeneratePublicSalt</a></strong>()</code> |
| <div class="block">Returns <code>true</code> if a public salt should be randomly generated and used to compute a hash if a |
| <a href="../../../../../org/apache/shiro/crypto/hash/HashRequest.html" title="interface in org.apache.shiro.crypto.hash"><code>HashRequest</code></a> does not specify a salt, <code>false</code> otherwise.</div> |
| </td> |
| </tr> |
| <tr class="altColor"> |
| <td class="colFirst"><code>void</code></td> |
| <td class="colLast"><code><strong><a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#setGeneratePublicSalt(boolean)">setGeneratePublicSalt</a></strong>(boolean generatePublicSalt)</code> |
| <div class="block">Sets whether or not a public salt should be randomly generated and used to compute a hash if a |
| <a href="../../../../../org/apache/shiro/crypto/hash/HashRequest.html" title="interface in org.apache.shiro.crypto.hash"><code>HashRequest</code></a> does not specify a salt.</div> |
| </td> |
| </tr> |
| <tr class="rowColor"> |
| <td class="colFirst"><code>void</code></td> |
| <td class="colLast"><code><strong><a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#setHashAlgorithmName(java.lang.String)">setHashAlgorithmName</a></strong>(<a href="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a> name)</code> |
| <div class="block">Sets the name of the <a href="http://java.sun.com/javase/6/docs/api/java/security/MessageDigest.html?is-external=true" title="class or interface in java.security"><code>MessageDigest</code></a> algorithm that will be used to compute |
| hashes.</div> |
| </td> |
| </tr> |
| <tr class="altColor"> |
| <td class="colFirst"><code>void</code></td> |
| <td class="colLast"><code><strong><a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#setHashIterations(int)">setHashIterations</a></strong>(int count)</code> |
| <div class="block">Sets the number of hash iterations that will be performed during hash computation.</div> |
| </td> |
| </tr> |
| <tr class="rowColor"> |
| <td class="colFirst"><code>void</code></td> |
| <td class="colLast"><code><strong><a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#setPrivateSalt(org.apache.shiro.util.ByteSource)">setPrivateSalt</a></strong>(<a href="../../../../../org/apache/shiro/util/ByteSource.html" title="interface in org.apache.shiro.util">ByteSource</a> privateSalt)</code> |
| <div class="block">Sets the 'private' (internal) salt to be paired with a 'public' (random or supplied) salt during hash computation.</div> |
| </td> |
| </tr> |
| <tr class="altColor"> |
| <td class="colFirst"><code>void</code></td> |
| <td class="colLast"><code><strong><a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#setRandomNumberGenerator(org.apache.shiro.crypto.RandomNumberGenerator)">setRandomNumberGenerator</a></strong>(<a href="../../../../../org/apache/shiro/crypto/RandomNumberGenerator.html" title="interface in org.apache.shiro.crypto">RandomNumberGenerator</a> rng)</code> |
| <div class="block">Sets a source of randomness used to generate public salts that will in turn be used during hash computation.</div> |
| </td> |
| </tr> |
| </table> |
| <ul class="blockList"> |
| <li class="blockList"><a name="methods_inherited_from_class_java.lang.Object"> |
| <!-- --> |
| </a> |
| <h3>Methods inherited from class java.lang.<a href="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</a></h3> |
| <code><a href="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#clone()" title="class or interface in java.lang">clone</a>, <a href="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#equals(java.lang.Object)" title="class or interface in java.lang">equals</a>, <a href="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#finalize()" title="class or interface in java.lang">finalize</a>, <a href="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#getClass()" title="class or interface in java.lang">getClass</a>, <a href="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#hashCode()" title="class or interface in java.lang">hashCode</a>, <a href="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#notify()" title="class or interface in java.lang">notify</a>, <a href="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#notifyAll()" title="class or interface in java.lang">notifyAll</a>, <a href="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#toString()" title="class or interface in java.lang">toString</a>, <a href="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait()" title="class or interface in java.lang">wait</a>, <a href="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait(long)" title="class or interface in java.lang">wait</a>, <a href="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait(long, int)" title="class or interface in java.lang">wait</a></code></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| <div class="details"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <!-- ========= CONSTRUCTOR DETAIL ======== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="constructor_detail"> |
| <!-- --> |
| </a> |
| <h3>Constructor Detail</h3> |
| <a name="DefaultHashService()"> |
| <!-- --> |
| </a> |
| <ul class="blockListLast"> |
| <li class="blockList"> |
| <h4>DefaultHashService</h4> |
| <pre>public <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.110">DefaultHashService</a>()</pre> |
| <div class="block">Constructs a new <code>DefaultHashService</code> instance with the following defaults: |
| <ul> |
| <li><a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#setHashAlgorithmName(java.lang.String)"><code>hashAlgorithmName</code></a> = <code>SHA-512</code></li> |
| <li><a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#setHashIterations(int)"><code>hashIterations</code></a> = <code>1</code></li> |
| <li><a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#setRandomNumberGenerator(org.apache.shiro.crypto.RandomNumberGenerator)"><code>randomNumberGenerator</code></a> = |
| new <a href="../../../../../org/apache/shiro/crypto/SecureRandomNumberGenerator.html" title="class in org.apache.shiro.crypto"><code>SecureRandomNumberGenerator</code></a>()</li> |
| <li><a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#setGeneratePublicSalt(boolean)"><code>generatePublicSalt</code></a> = <code>false</code></li> |
| </ul> |
| <p/> |
| If this hashService will be used for password hashing it is recommended to set the |
| <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#setPrivateSalt(org.apache.shiro.util.ByteSource)"><code>privateSalt</code></a> and significantly increase the number of |
| <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#setHashIterations(int)"><code>hashIterations</code></a>. See the class-level JavaDoc for more information.</div> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| <!-- ============ METHOD DETAIL ========== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="method_detail"> |
| <!-- --> |
| </a> |
| <h3>Method Detail</h3> |
| <a name="computeHash(org.apache.shiro.crypto.hash.HashRequest)"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>computeHash</h4> |
| <pre>public <a href="../../../../../org/apache/shiro/crypto/hash/Hash.html" title="interface in org.apache.shiro.crypto.hash">Hash</a> <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.150">computeHash</a>(<a href="../../../../../org/apache/shiro/crypto/hash/HashRequest.html" title="interface in org.apache.shiro.crypto.hash">HashRequest</a> request)</pre> |
| <div class="block">Computes and responds with a hash based on the specified request. |
| <p/> |
| This implementation functions as follows: |
| <ul> |
| <li>If the request's <a href="../../../../../org/apache/shiro/crypto/hash/HashRequest.html#getSalt()"><code>salt</code></a> is null: |
| <p/> |
| A salt will be generated and used to compute the hash. The salt is generated as follows: |
| <ol> |
| <li>Use the <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#getRandomNumberGenerator()"><code>randomNumberGenerator</code></a> to generate a new random number.</li> |
| <li><a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#combine(org.apache.shiro.util.ByteSource, org.apache.shiro.util.ByteSource)"><code>combine</code></a> this random salt with any configured |
| <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#getPrivateSalt()"><code>privateSalt</code></a> |
| </li> |
| <li>Use the combined value as the salt used during hash computation</li> |
| </ol> |
| </li> |
| <li> |
| If the request salt is not null: |
| <p/> |
| This indicates that the hash computation is for comparison purposes (of a |
| previously computed hash). The request salt will be <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#combine(org.apache.shiro.util.ByteSource, org.apache.shiro.util.ByteSource)"><code>combined</code></a> with any |
| configured <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#getPrivateSalt()"><code>privateSalt</code></a> and used as the complete salt during hash computation. |
| </li> |
| </ul> |
| <p/> |
| The returned <code>Hash</code>'s <a href="../../../../../org/apache/shiro/crypto/hash/Hash.html#getSalt()"><code>salt</code></a> property |
| will contain <em>only</em> the 'public' part of the salt and <em>NOT</em> the privateSalt. See the class-level |
| JavaDoc explanation for more info.</div> |
| <dl> |
| <dt><strong>Specified by:</strong></dt> |
| <dd><code><a href="../../../../../org/apache/shiro/crypto/hash/HashService.html#computeHash(org.apache.shiro.crypto.hash.HashRequest)">computeHash</a></code> in interface <code><a href="../../../../../org/apache/shiro/crypto/hash/HashService.html" title="interface in org.apache.shiro.crypto.hash">HashService</a></code></dd> |
| <dt><span class="strong">Parameters:</span></dt><dd><code>request</code> - the request to process</dd> |
| <dt><span class="strong">Returns:</span></dt><dd>the response containing the result of the hash computation, as well as any hash salt used that should be |
| exposed to the caller.</dd><dt><span class="strong">See Also:</span></dt><dd><a href="../../../../../org/apache/shiro/crypto/hash/Hash.html#getSalt()"><code>Hash.getSalt()</code></a></dd></dl> |
| </li> |
| </ul> |
| <a name="getAlgorithmName(org.apache.shiro.crypto.hash.HashRequest)"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>getAlgorithmName</h4> |
| <pre>protected <a href="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a> <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.174">getAlgorithmName</a>(<a href="../../../../../org/apache/shiro/crypto/hash/HashRequest.html" title="interface in org.apache.shiro.crypto.hash">HashRequest</a> request)</pre> |
| </li> |
| </ul> |
| <a name="getIterations(org.apache.shiro.crypto.hash.HashRequest)"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>getIterations</h4> |
| <pre>protected int <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.182">getIterations</a>(<a href="../../../../../org/apache/shiro/crypto/hash/HashRequest.html" title="interface in org.apache.shiro.crypto.hash">HashRequest</a> request)</pre> |
| </li> |
| </ul> |
| <a name="getPublicSalt(org.apache.shiro.crypto.hash.HashRequest)"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>getPublicSalt</h4> |
| <pre>protected <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/hash/DefaultHashService.html#line.212">getPublicSalt</a>(<a href="../../../../../org/apache/shiro/crypto/hash/HashRequest.html" title="interface in org.apache.shiro.crypto.hash">HashRequest</a> request)</pre> |
| <div class="block">Returns the public salt that should be used to compute a hash based on the specified request or |
| <code>null</code> if no public salt should be used. |
| <p/> |
| This implementation functions as follows: |
| <ol> |
| <li>If the request salt is not null and non-empty, this will be used, return it.</li> |
| <li>If the request salt is null or empty: |
| <ol> |
| <li>If a private salt has been set <em>OR</em> <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#isGeneratePublicSalt()"><code>isGeneratePublicSalt()</code></a> is <code>true</code>, |
| auto generate a random public salt via the configured |
| <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#getRandomNumberGenerator()"><code>randomNumberGenerator</code></a>.</li> |
| <li>If a private salt has not been configured and <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#isGeneratePublicSalt()"><code>isGeneratePublicSalt()</code></a> is <code>false</code>, |
| do nothing - return <code>null</code> to indicate a salt should not be used during hash computation.</li> |
| </ol> |
| </li> |
| </ol></div> |
| <dl><dt><span class="strong">Parameters:</span></dt><dd><code>request</code> - request the request to process</dd> |
| <dt><span class="strong">Returns:</span></dt><dd>the public salt that should be used to compute a hash based on the specified request or |
| <code>null</code> if no public salt should be used.</dd></dl> |
| </li> |
| </ul> |
| <a name="combine(org.apache.shiro.util.ByteSource, org.apache.shiro.util.ByteSource)"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>combine</h4> |
| <pre>protected <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/hash/DefaultHashService.html#line.246">combine</a>(<a href="../../../../../org/apache/shiro/util/ByteSource.html" title="interface in org.apache.shiro.util">ByteSource</a> privateSalt, |
| <a href="../../../../../org/apache/shiro/util/ByteSource.html" title="interface in org.apache.shiro.util">ByteSource</a> publicSalt)</pre> |
| <div class="block">Combines the specified 'private' salt bytes with the specified additional extra bytes to use as the |
| total salt during hash computation. <code>privateSaltBytes</code> will be <code>null</code> }if no private salt has been |
| configured.</div> |
| <dl><dt><span class="strong">Parameters:</span></dt><dd><code>privateSalt</code> - the (possibly <code>null</code>) 'private' salt to combine with the specified extra bytes</dd><dd><code>publicSalt</code> - the extra bytes to use in addition to the given private salt.</dd> |
| <dt><span class="strong">Returns:</span></dt><dd>a combination of the specified private salt bytes and extra bytes that will be used as the total |
| salt during hash computation.</dd></dl> |
| </li> |
| </ul> |
| <a name="setHashAlgorithmName(java.lang.String)"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>setHashAlgorithmName</h4> |
| <pre>public void <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.275">setHashAlgorithmName</a>(<a href="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a> name)</pre> |
| <div class="block"><strong>Description copied from interface: <code><a href="../../../../../org/apache/shiro/crypto/hash/ConfigurableHashService.html#setHashAlgorithmName(java.lang.String)">ConfigurableHashService</a></code></strong></div> |
| <div class="block">Sets the name of the <a href="http://java.sun.com/javase/6/docs/api/java/security/MessageDigest.html?is-external=true" title="class or interface in java.security"><code>MessageDigest</code></a> algorithm that will be used to compute |
| hashes.</div> |
| <dl> |
| <dt><strong>Specified by:</strong></dt> |
| <dd><code><a href="../../../../../org/apache/shiro/crypto/hash/ConfigurableHashService.html#setHashAlgorithmName(java.lang.String)">setHashAlgorithmName</a></code> in interface <code><a href="../../../../../org/apache/shiro/crypto/hash/ConfigurableHashService.html" title="interface in org.apache.shiro.crypto.hash">ConfigurableHashService</a></code></dd> |
| <dt><span class="strong">Parameters:</span></dt><dd><code>name</code> - the name of the <a href="http://java.sun.com/javase/6/docs/api/java/security/MessageDigest.html?is-external=true" title="class or interface in java.security"><code>MessageDigest</code></a> algorithm that will be used to |
| compute hashes.</dd></dl> |
| </li> |
| </ul> |
| <a name="getHashAlgorithmName()"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>getHashAlgorithmName</h4> |
| <pre>public <a href="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a> <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.279">getHashAlgorithmName</a>()</pre> |
| </li> |
| </ul> |
| <a name="setPrivateSalt(org.apache.shiro.util.ByteSource)"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>setPrivateSalt</h4> |
| <pre>public void <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.283">setPrivateSalt</a>(<a href="../../../../../org/apache/shiro/util/ByteSource.html" title="interface in org.apache.shiro.util">ByteSource</a> privateSalt)</pre> |
| <div class="block"><strong>Description copied from interface: <code><a href="../../../../../org/apache/shiro/crypto/hash/ConfigurableHashService.html#setPrivateSalt(org.apache.shiro.util.ByteSource)">ConfigurableHashService</a></code></strong></div> |
| <div class="block">Sets the 'private' (internal) salt to be paired with a 'public' (random or supplied) salt during hash computation.</div> |
| <dl> |
| <dt><strong>Specified by:</strong></dt> |
| <dd><code><a href="../../../../../org/apache/shiro/crypto/hash/ConfigurableHashService.html#setPrivateSalt(org.apache.shiro.util.ByteSource)">setPrivateSalt</a></code> in interface <code><a href="../../../../../org/apache/shiro/crypto/hash/ConfigurableHashService.html" title="interface in org.apache.shiro.crypto.hash">ConfigurableHashService</a></code></dd> |
| <dt><span class="strong">Parameters:</span></dt><dd><code>privateSalt</code> - the 'private' internal salt to be paired with a 'public' (random or supplied) salt during |
| hash computation.</dd></dl> |
| </li> |
| </ul> |
| <a name="getPrivateSalt()"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>getPrivateSalt</h4> |
| <pre>public <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/hash/DefaultHashService.html#line.287">getPrivateSalt</a>()</pre> |
| </li> |
| </ul> |
| <a name="setHashIterations(int)"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>setHashIterations</h4> |
| <pre>public void <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.291">setHashIterations</a>(int count)</pre> |
| <div class="block"><strong>Description copied from interface: <code><a href="../../../../../org/apache/shiro/crypto/hash/ConfigurableHashService.html#setHashIterations(int)">ConfigurableHashService</a></code></strong></div> |
| <div class="block">Sets the number of hash iterations that will be performed during hash computation.</div> |
| <dl> |
| <dt><strong>Specified by:</strong></dt> |
| <dd><code><a href="../../../../../org/apache/shiro/crypto/hash/ConfigurableHashService.html#setHashIterations(int)">setHashIterations</a></code> in interface <code><a href="../../../../../org/apache/shiro/crypto/hash/ConfigurableHashService.html" title="interface in org.apache.shiro.crypto.hash">ConfigurableHashService</a></code></dd> |
| <dt><span class="strong">Parameters:</span></dt><dd><code>count</code> - the number of hash iterations that will be performed during hash computation.</dd></dl> |
| </li> |
| </ul> |
| <a name="getHashIterations()"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>getHashIterations</h4> |
| <pre>public int <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.295">getHashIterations</a>()</pre> |
| </li> |
| </ul> |
| <a name="setRandomNumberGenerator(org.apache.shiro.crypto.RandomNumberGenerator)"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>setRandomNumberGenerator</h4> |
| <pre>public void <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.299">setRandomNumberGenerator</a>(<a href="../../../../../org/apache/shiro/crypto/RandomNumberGenerator.html" title="interface in org.apache.shiro.crypto">RandomNumberGenerator</a> rng)</pre> |
| <div class="block"><strong>Description copied from interface: <code><a href="../../../../../org/apache/shiro/crypto/hash/ConfigurableHashService.html#setRandomNumberGenerator(org.apache.shiro.crypto.RandomNumberGenerator)">ConfigurableHashService</a></code></strong></div> |
| <div class="block">Sets a source of randomness used to generate public salts that will in turn be used during hash computation.</div> |
| <dl> |
| <dt><strong>Specified by:</strong></dt> |
| <dd><code><a href="../../../../../org/apache/shiro/crypto/hash/ConfigurableHashService.html#setRandomNumberGenerator(org.apache.shiro.crypto.RandomNumberGenerator)">setRandomNumberGenerator</a></code> in interface <code><a href="../../../../../org/apache/shiro/crypto/hash/ConfigurableHashService.html" title="interface in org.apache.shiro.crypto.hash">ConfigurableHashService</a></code></dd> |
| <dt><span class="strong">Parameters:</span></dt><dd><code>rng</code> - a source of randomness used to generate public salts that will in turn be used during hash computation.</dd></dl> |
| </li> |
| </ul> |
| <a name="getRandomNumberGenerator()"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>getRandomNumberGenerator</h4> |
| <pre>public <a href="../../../../../org/apache/shiro/crypto/RandomNumberGenerator.html" title="interface in org.apache.shiro.crypto">RandomNumberGenerator</a> <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.303">getRandomNumberGenerator</a>()</pre> |
| </li> |
| </ul> |
| <a name="isGeneratePublicSalt()"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>isGeneratePublicSalt</h4> |
| <pre>public boolean <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.322">isGeneratePublicSalt</a>()</pre> |
| <div class="block">Returns <code>true</code> if a public salt should be randomly generated and used to compute a hash if a |
| <a href="../../../../../org/apache/shiro/crypto/hash/HashRequest.html" title="interface in org.apache.shiro.crypto.hash"><code>HashRequest</code></a> does not specify a salt, <code>false</code> otherwise. |
| <p/> |
| The default value is <code>false</code> but should definitely be set to <code>true</code> if the |
| <code>HashService</code> instance is being used for password hashing. |
| <p/> |
| <b>NOTE:</b> this property only has an effect if a <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#getPrivateSalt()"><code>privateSalt</code></a> is NOT configured. If a |
| private salt has been configured and a request does not provide a salt, a random salt will always be generated |
| to protect the integrity of the private salt (without a public salt, the private salt would be exposed as-is, |
| which is undesirable).</div> |
| <dl><dt><span class="strong">Returns:</span></dt><dd><code>true</code> if a public salt should be randomly generated and used to compute a hash if a |
| <a href="../../../../../org/apache/shiro/crypto/hash/HashRequest.html" title="interface in org.apache.shiro.crypto.hash"><code>HashRequest</code></a> does not specify a salt, <code>false</code> otherwise.</dd></dl> |
| </li> |
| </ul> |
| <a name="setGeneratePublicSalt(boolean)"> |
| <!-- --> |
| </a> |
| <ul class="blockListLast"> |
| <li class="blockList"> |
| <h4>setGeneratePublicSalt</h4> |
| <pre>public void <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.341">setGeneratePublicSalt</a>(boolean generatePublicSalt)</pre> |
| <div class="block">Sets whether or not a public salt should be randomly generated and used to compute a hash if a |
| <a href="../../../../../org/apache/shiro/crypto/hash/HashRequest.html" title="interface in org.apache.shiro.crypto.hash"><code>HashRequest</code></a> does not specify a salt. |
| <p/> |
| The default value is <code>false</code> but should definitely be set to <code>true</code> if the |
| <code>HashService</code> instance is being used for password hashing. |
| <p/> |
| <b>NOTE:</b> this property only has an effect if a <a href="../../../../../org/apache/shiro/crypto/hash/DefaultHashService.html#getPrivateSalt()"><code>privateSalt</code></a> is NOT configured. If a |
| private salt has been configured and a request does not provide a salt, a random salt will always be generated |
| to protect the integrity of the private salt (without a public salt, the private salt would be exposed as-is, |
| which is undesirable).</div> |
| <dl><dt><span class="strong">Parameters:</span></dt><dd><code>generatePublicSalt</code> - whether or not a public salt should be randomly generated and used to compute a hash |
| if a <a href="../../../../../org/apache/shiro/crypto/hash/HashRequest.html" title="interface in org.apache.shiro.crypto.hash"><code>HashRequest</code></a> does not specify a salt.</dd></dl> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| </div> |
| <!-- ========= END OF CLASS DATA ========= --> |
| <!-- ======= START OF BOTTOM NAVBAR ====== --> |
| <div class="bottomNav"><a name="navbar_bottom"> |
| <!-- --> |
| </a><a href="#skip-navbar_bottom" title="Skip navigation links"></a><a name="navbar_bottom_firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../../../overview-summary.html">Overview</a></li> |
| <li><a href="package-summary.html">Package</a></li> |
| <li class="navBarCell1Rev">Class</li> |
| <li><a href="class-use/DefaultHashService.html">Use</a></li> |
| <li><a href="package-tree.html">Tree</a></li> |
| <li><a href="../../../../../deprecated-list.html">Deprecated</a></li> |
| <li><a href="../../../../../index-all.html">Index</a></li> |
| <li><a href="../../../../../help-doc.html">Help</a></li> |
| </ul> |
| </div> |
| <div class="subNav"> |
| <ul class="navList"> |
| <li><a href="../../../../../org/apache/shiro/crypto/hash/ConfigurableHashService.html" title="interface in org.apache.shiro.crypto.hash"><span class="strong">Prev Class</span></a></li> |
| <li><a href="../../../../../org/apache/shiro/crypto/hash/Hash.html" title="interface in org.apache.shiro.crypto.hash"><span class="strong">Next Class</span></a></li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="../../../../../index.html?org/apache/shiro/crypto/hash/DefaultHashService.html" target="_top">Frames</a></li> |
| <li><a href="DefaultHashService.html" target="_top">No Frames</a></li> |
| </ul> |
| <ul class="navList" id="allclasses_navbar_bottom"> |
| <li><a href="../../../../../allclasses-noframe.html">All Classes</a></li> |
| </ul> |
| <div> |
| <script type="text/javascript"><!-- |
| allClassesLink = document.getElementById("allclasses_navbar_bottom"); |
| if(window==top) { |
| allClassesLink.style.display = "block"; |
| } |
| else { |
| allClassesLink.style.display = "none"; |
| } |
| //--> |
| </script> |
| </div> |
| <div> |
| <ul class="subNavList"> |
| <li>Summary: </li> |
| <li>Nested | </li> |
| <li>Field | </li> |
| <li><a href="#constructor_summary">Constr</a> | </li> |
| <li><a href="#method_summary">Method</a></li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Field | </li> |
| <li><a href="#constructor_detail">Constr</a> | </li> |
| <li><a href="#method_detail">Method</a></li> |
| </ul> |
| </div> |
| <a name="skip-navbar_bottom"> |
| <!-- --> |
| </a></div> |
| <!-- ======== END OF BOTTOM NAVBAR ======= --> |
| <p class="legalCopy"><small>Copyright © 2004-2013 <a href="http://www.apache.org/">The Apache Software Foundation</a>. All Rights Reserved.</small></p> |
| </body> |
| </html> |
| |