| <!DOCTYPE HTML> |
| <!-- NewPage --> |
| <html lang="en"> |
| <head> |
| <!-- Generated by javadoc --> |
| <title>DefaultHashService (Apache Shiro :: Cryptography :: Hashing 1.10.1 API)</title> |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| <link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style"> |
| <link rel="stylesheet" type="text/css" href="../../../../../jquery/jquery-ui.min.css" title="Style"> |
| <link rel="stylesheet" type="text/css" href="../../../../../jquery-ui.overrides.css" title="Style"> |
| <script type="text/javascript" src="../../../../../script.js"></script> |
| <script type="text/javascript" src="../../../../../jquery/jszip/dist/jszip.min.js"></script> |
| <script type="text/javascript" src="../../../../../jquery/jszip-utils/dist/jszip-utils.min.js"></script> |
| <!--[if IE]> |
| <script type="text/javascript" src="../../../../../jquery/jszip-utils/dist/jszip-utils-ie.min.js"></script> |
| <![endif]--> |
| <script type="text/javascript" src="../../../../../jquery/jquery-3.6.0.min.js"></script> |
| <script type="text/javascript" src="../../../../../jquery/jquery-ui.min.js"></script> |
| </head> |
| <body> |
| <script type="text/javascript"><!-- |
| try { |
| if (location.href.indexOf('is-external=true') == -1) { |
| parent.document.title="DefaultHashService (Apache Shiro :: Cryptography :: Hashing 1.10.1 API)"; |
| } |
| } |
| catch(err) { |
| } |
| //--> |
| var data = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10,"i9":10,"i10":10,"i11":10,"i12":10,"i13":10,"i14":10}; |
| var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]}; |
| var altColor = "altColor"; |
| var rowColor = "rowColor"; |
| var tableTab = "tableTab"; |
| var activeTableTab = "activeTableTab"; |
| var pathtoroot = "../../../../../"; |
| var useModuleDirectories = true; |
| loadScripts(document, 'script');</script> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| <header role="banner"> |
| <nav role="navigation"> |
| <div class="fixedNav"><!-- Matomo --> <script> var _paq = window._paq = window._paq || []; /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ /* We explicitly disable cookie tracking to avoid privacy issues */ _paq.push(['disableCookies']); _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { var u="//matomo.privacy.apache.org/"; _paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setSiteId', '2']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); })(); </script> <!-- End Matomo Code --> |
| <!-- ========= START OF TOP NAVBAR ======= --> |
| <div class="topNav"><a id="navbar.top"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div> |
| <a id="navbar.top.firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../../../index.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" id="allclasses_navbar_top"> |
| <li><a href="../../../../../allclasses.html">All Classes</a></li> |
| </ul> |
| <ul class="navListSearch"> |
| <li><label for="search">SEARCH:</label> |
| <input type="text" id="search" value="search" disabled="disabled"> |
| <input type="reset" id="reset" value="reset" disabled="disabled"> |
| </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> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| </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 id="skip.navbar.top"> |
| <!-- --> |
| </a></div> |
| <!-- ========= END OF TOP NAVBAR ========= --> |
| </div> |
| <div class="navPadding"> </div> |
| <script type="text/javascript"><!-- |
| $('.navPadding').css('padding-top', $('.fixedNav').css("height")); |
| //--> |
| </script> |
| </nav> |
| </header> |
| <!-- ======== START OF CLASS DATA ======== --> |
| <main role="main"> |
| <div class="header"> |
| <div class="subTitle"><span class="packageLabelInType">Package</span> <a href="package-summary.html">org.apache.shiro.crypto.hash</a></div> |
| <h2 title="Class DefaultHashService" class="title">Class DefaultHashService</h2> |
| </div> |
| <div class="contentContainer"> |
| <ul class="inheritance"> |
| <li><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang" class="externalLink">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><code><a href="ConfigurableHashService.html" title="interface in org.apache.shiro.crypto.hash">ConfigurableHashService</a></code>, <code><a href="HashService.html" title="interface in org.apache.shiro.crypto.hash">HashService</a></code></dd> |
| </dl> |
| <hr> |
| <pre>public class <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.69">DefaultHashService</a> |
| extends <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang" class="externalLink">Object</a> |
| implements <a href="ConfigurableHashService.html" title="interface in org.apache.shiro.crypto.hash">ConfigurableHashService</a></pre> |
| <div class="block">Default implementation of the <a href="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="#setPrivateSalt(org.apache.shiro.util.ByteSource)"><code>privateSalt</code></a>. |
| <h2>Hash Algorithm</h2> |
| You may specify a hash algorithm via the <a href="#setHashAlgorithmName(java.lang.String)"><code>setHashAlgorithmName(String)</code></a> property. Any algorithm name |
| understood by the JDK |
| <a href="https://docs.oracle.com/javase/8/docs/api/java/security/MessageDigest.html?is-external=true#getInstance(java.lang.String)" title="class or interface in java.security" class="externalLink"><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="#setRandomNumberGenerator(org.apache.shiro.crypto.RandomNumberGenerator)"><code>randomNumberGenerator</code></a> property. |
| Random salts (and potentially combined with the internal <a href="#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 |
| <code>SecureRandomNumberGenerator</code>. |
| <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.stormpath.com/blog/strong-password-hashing-apache-shiro">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="#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="#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="#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="#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="simpleTagLabel">Since:</span></dt> |
| <dd>1.2</dd> |
| </dl> |
| </li> |
| </ul> |
| </div> |
| <div class="summary"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <!-- ======== CONSTRUCTOR SUMMARY ======== --> |
| <section> |
| <ul class="blockList"> |
| <li class="blockList"><a id="constructor.summary"> |
| <!-- --> |
| </a> |
| <h3>Constructor Summary</h3> |
| <table class="memberSummary"> |
| <caption><span>Constructors</span><span class="tabEnd"> </span></caption> |
| <tr> |
| <th class="colFirst" scope="col">Constructor</th> |
| <th class="colLast" scope="col">Description</th> |
| </tr> |
| <tr class="altColor"> |
| <th class="colConstructorName" scope="row"><code><span class="memberNameLink"><a href="#%3Cinit%3E()">DefaultHashService</a></span>()</code></th> |
| <td class="colLast"> |
| <div class="block">Constructs a new <code>DefaultHashService</code> instance with the following defaults: |
| |
| <a href="#setHashAlgorithmName(java.lang.String)"><code>hashAlgorithmName</code></a> = <code>SHA-512</code> |
| <a href="#setHashIterations(int)"><code>hashIterations</code></a> = <code>1</code> |
| <a href="#setRandomNumberGenerator(org.apache.shiro.crypto.RandomNumberGenerator)"><code>randomNumberGenerator</code></a> = |
| new <code>SecureRandomNumberGenerator</code>() |
| <a href="#setGeneratePublicSalt(boolean)"><code>generatePublicSalt</code></a> = <code>false</code> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </li> |
| </ul> |
| </section> |
| <!-- ========== METHOD SUMMARY =========== --> |
| <section> |
| <ul class="blockList"> |
| <li class="blockList"><a id="method.summary"> |
| <!-- --> |
| </a> |
| <h3>Method Summary</h3> |
| <table class="memberSummary"> |
| <caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd"> </span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd"> </span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd"> </span></span></caption> |
| <tr> |
| <th class="colFirst" scope="col">Modifier and Type</th> |
| <th class="colSecond" scope="col">Method</th> |
| <th class="colLast" scope="col">Description</th> |
| </tr> |
| <tr id="i0" class="altColor"> |
| <td class="colFirst"><code>protected org.apache.shiro.util.ByteSource</code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#combine(org.apache.shiro.util.ByteSource,org.apache.shiro.util.ByteSource)">combine</a></span>​(org.apache.shiro.util.ByteSource privateSalt, |
| org.apache.shiro.util.ByteSource publicSalt)</code></th> |
| <td class="colLast"> |
| <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 id="i1" class="rowColor"> |
| <td class="colFirst"><code><a href="Hash.html" title="interface in org.apache.shiro.crypto.hash">Hash</a></code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#computeHash(org.apache.shiro.crypto.hash.HashRequest)">computeHash</a></span>​(<a href="HashRequest.html" title="interface in org.apache.shiro.crypto.hash">HashRequest</a> request)</code></th> |
| <td class="colLast"> |
| <div class="block">Computes and responds with a hash based on the specified request.</div> |
| </td> |
| </tr> |
| <tr id="i2" class="altColor"> |
| <td class="colFirst"><code>protected <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang" class="externalLink">String</a></code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#getAlgorithmName(org.apache.shiro.crypto.hash.HashRequest)">getAlgorithmName</a></span>​(<a href="HashRequest.html" title="interface in org.apache.shiro.crypto.hash">HashRequest</a> request)</code></th> |
| <td class="colLast"> </td> |
| </tr> |
| <tr id="i3" class="rowColor"> |
| <td class="colFirst"><code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang" class="externalLink">String</a></code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#getHashAlgorithmName()">getHashAlgorithmName</a></span>()</code></th> |
| <td class="colLast"> </td> |
| </tr> |
| <tr id="i4" class="altColor"> |
| <td class="colFirst"><code>int</code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#getHashIterations()">getHashIterations</a></span>()</code></th> |
| <td class="colLast"> </td> |
| </tr> |
| <tr id="i5" class="rowColor"> |
| <td class="colFirst"><code>protected int</code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#getIterations(org.apache.shiro.crypto.hash.HashRequest)">getIterations</a></span>​(<a href="HashRequest.html" title="interface in org.apache.shiro.crypto.hash">HashRequest</a> request)</code></th> |
| <td class="colLast"> </td> |
| </tr> |
| <tr id="i6" class="altColor"> |
| <td class="colFirst"><code>org.apache.shiro.util.ByteSource</code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#getPrivateSalt()">getPrivateSalt</a></span>()</code></th> |
| <td class="colLast"> </td> |
| </tr> |
| <tr id="i7" class="rowColor"> |
| <td class="colFirst"><code>protected org.apache.shiro.util.ByteSource</code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#getPublicSalt(org.apache.shiro.crypto.hash.HashRequest)">getPublicSalt</a></span>​(<a href="HashRequest.html" title="interface in org.apache.shiro.crypto.hash">HashRequest</a> request)</code></th> |
| <td class="colLast"> |
| <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 id="i8" class="altColor"> |
| <td class="colFirst"><code>org.apache.shiro.crypto.RandomNumberGenerator</code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#getRandomNumberGenerator()">getRandomNumberGenerator</a></span>()</code></th> |
| <td class="colLast"> </td> |
| </tr> |
| <tr id="i9" class="rowColor"> |
| <td class="colFirst"><code>boolean</code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#isGeneratePublicSalt()">isGeneratePublicSalt</a></span>()</code></th> |
| <td class="colLast"> |
| <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="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 id="i10" class="altColor"> |
| <td class="colFirst"><code>void</code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#setGeneratePublicSalt(boolean)">setGeneratePublicSalt</a></span>​(boolean generatePublicSalt)</code></th> |
| <td class="colLast"> |
| <div class="block">Sets whether or not a public salt should be randomly generated and used to compute a hash if a |
| <a href="HashRequest.html" title="interface in org.apache.shiro.crypto.hash"><code>HashRequest</code></a> does not specify a salt.</div> |
| </td> |
| </tr> |
| <tr id="i11" class="rowColor"> |
| <td class="colFirst"><code>void</code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#setHashAlgorithmName(java.lang.String)">setHashAlgorithmName</a></span>​(<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang" class="externalLink">String</a> name)</code></th> |
| <td class="colLast"> |
| <div class="block">Sets the name of the <a href="https://docs.oracle.com/javase/8/docs/api/java/security/MessageDigest.html?is-external=true" title="class or interface in java.security" class="externalLink"><code>MessageDigest</code></a> algorithm that will be used to compute |
| hashes.</div> |
| </td> |
| </tr> |
| <tr id="i12" class="altColor"> |
| <td class="colFirst"><code>void</code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#setHashIterations(int)">setHashIterations</a></span>​(int count)</code></th> |
| <td class="colLast"> |
| <div class="block">Sets the number of hash iterations that will be performed during hash computation.</div> |
| </td> |
| </tr> |
| <tr id="i13" class="rowColor"> |
| <td class="colFirst"><code>void</code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#setPrivateSalt(org.apache.shiro.util.ByteSource)">setPrivateSalt</a></span>​(org.apache.shiro.util.ByteSource privateSalt)</code></th> |
| <td class="colLast"> |
| <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 id="i14" class="altColor"> |
| <td class="colFirst"><code>void</code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#setRandomNumberGenerator(org.apache.shiro.crypto.RandomNumberGenerator)">setRandomNumberGenerator</a></span>​(org.apache.shiro.crypto.RandomNumberGenerator rng)</code></th> |
| <td class="colLast"> |
| <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 id="methods.inherited.from.class.java.lang.Object"> |
| <!-- --> |
| </a> |
| <h3>Methods inherited from class java.lang.<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang" class="externalLink">Object</a></h3> |
| <code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#clone()" title="class or interface in java.lang" class="externalLink">clone</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#equals(java.lang.Object)" title="class or interface in java.lang" class="externalLink">equals</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#finalize()" title="class or interface in java.lang" class="externalLink">finalize</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#getClass()" title="class or interface in java.lang" class="externalLink">getClass</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#hashCode()" title="class or interface in java.lang" class="externalLink">hashCode</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#notify()" title="class or interface in java.lang" class="externalLink">notify</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#notifyAll()" title="class or interface in java.lang" class="externalLink">notifyAll</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#toString()" title="class or interface in java.lang" class="externalLink">toString</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#wait()" title="class or interface in java.lang" class="externalLink">wait</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#wait(long)" title="class or interface in java.lang" class="externalLink">wait</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#wait(long,int)" title="class or interface in java.lang" class="externalLink">wait</a></code></li> |
| </ul> |
| </li> |
| </ul> |
| </section> |
| </li> |
| </ul> |
| </div> |
| <div class="details"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <!-- ========= CONSTRUCTOR DETAIL ======== --> |
| <section> |
| <ul class="blockList"> |
| <li class="blockList"><a id="constructor.detail"> |
| <!-- --> |
| </a> |
| <h3>Constructor Detail</h3> |
| <a id="<init>()"> |
| <!-- --> |
| </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="#setHashAlgorithmName(java.lang.String)"><code>hashAlgorithmName</code></a> = <code>SHA-512</code></li> |
| <li><a href="#setHashIterations(int)"><code>hashIterations</code></a> = <code>1</code></li> |
| <li><a href="#setRandomNumberGenerator(org.apache.shiro.crypto.RandomNumberGenerator)"><code>randomNumberGenerator</code></a> = |
| new <code>SecureRandomNumberGenerator</code>()</li> |
| <li><a href="#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="#setPrivateSalt(org.apache.shiro.util.ByteSource)"><code>privateSalt</code></a> and significantly increase the number of |
| <a href="#setHashIterations(int)"><code>hashIterations</code></a>. See the class-level JavaDoc for more information.</div> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </section> |
| <!-- ============ METHOD DETAIL ========== --> |
| <section> |
| <ul class="blockList"> |
| <li class="blockList"><a id="method.detail"> |
| <!-- --> |
| </a> |
| <h3>Method Detail</h3> |
| <a id="computeHash(org.apache.shiro.crypto.hash.HashRequest)"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>computeHash</h4> |
| <pre class="methodSignature">public <a href="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="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="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="#getRandomNumberGenerator()"><code>randomNumberGenerator</code></a> to generate a new random number.</li> |
| <li><a href="#combine(org.apache.shiro.util.ByteSource,org.apache.shiro.util.ByteSource)"><code>combine</code></a> this random salt with any configured |
| <a href="#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="#combine(org.apache.shiro.util.ByteSource,org.apache.shiro.util.ByteSource)"><code>combined</code></a> with any |
| configured <a href="#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="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><span class="overrideSpecifyLabel">Specified by:</span></dt> |
| <dd><code><a href="HashService.html#computeHash(org.apache.shiro.crypto.hash.HashRequest)">computeHash</a></code> in interface <code><a href="HashService.html" title="interface in org.apache.shiro.crypto.hash">HashService</a></code></dd> |
| <dt><span class="paramLabel">Parameters:</span></dt> |
| <dd><code>request</code> - the request to process</dd> |
| <dt><span class="returnLabel">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="seeLabel">See Also:</span></dt> |
| <dd><a href="Hash.html#getSalt()"><code>Hash.getSalt()</code></a></dd> |
| </dl> |
| </li> |
| </ul> |
| <a id="getAlgorithmName(org.apache.shiro.crypto.hash.HashRequest)"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>getAlgorithmName</h4> |
| <pre class="methodSignature">protected <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang" class="externalLink">String</a> <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.174">getAlgorithmName</a>​(<a href="HashRequest.html" title="interface in org.apache.shiro.crypto.hash">HashRequest</a> request)</pre> |
| </li> |
| </ul> |
| <a id="getIterations(org.apache.shiro.crypto.hash.HashRequest)"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>getIterations</h4> |
| <pre class="methodSignature">protected int <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.182">getIterations</a>​(<a href="HashRequest.html" title="interface in org.apache.shiro.crypto.hash">HashRequest</a> request)</pre> |
| </li> |
| </ul> |
| <a id="getPublicSalt(org.apache.shiro.crypto.hash.HashRequest)"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>getPublicSalt</h4> |
| <pre class="methodSignature">protected org.apache.shiro.util.ByteSource <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.212">getPublicSalt</a>​(<a href="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="#isGeneratePublicSalt()"><code>isGeneratePublicSalt()</code></a> is <code>true</code>, |
| auto generate a random public salt via the configured |
| <a href="#getRandomNumberGenerator()"><code>randomNumberGenerator</code></a>.</li> |
| <li>If a private salt has not been configured and <a href="#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="paramLabel">Parameters:</span></dt> |
| <dd><code>request</code> - request the request to process</dd> |
| <dt><span class="returnLabel">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 id="combine(org.apache.shiro.util.ByteSource,org.apache.shiro.util.ByteSource)"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>combine</h4> |
| <pre class="methodSignature">protected org.apache.shiro.util.ByteSource <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.246">combine</a>​(org.apache.shiro.util.ByteSource privateSalt, |
| org.apache.shiro.util.ByteSource 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="paramLabel">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="returnLabel">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 id="setHashAlgorithmName(java.lang.String)"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>setHashAlgorithmName</h4> |
| <pre class="methodSignature">public void <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.275">setHashAlgorithmName</a>​(<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang" class="externalLink">String</a> name)</pre> |
| <div class="block"><span class="descfrmTypeLabel">Description copied from interface: <code><a href="ConfigurableHashService.html#setHashAlgorithmName(java.lang.String)">ConfigurableHashService</a></code></span></div> |
| <div class="block">Sets the name of the <a href="https://docs.oracle.com/javase/8/docs/api/java/security/MessageDigest.html?is-external=true" title="class or interface in java.security" class="externalLink"><code>MessageDigest</code></a> algorithm that will be used to compute |
| hashes.</div> |
| <dl> |
| <dt><span class="overrideSpecifyLabel">Specified by:</span></dt> |
| <dd><code><a href="ConfigurableHashService.html#setHashAlgorithmName(java.lang.String)">setHashAlgorithmName</a></code> in interface <code><a href="ConfigurableHashService.html" title="interface in org.apache.shiro.crypto.hash">ConfigurableHashService</a></code></dd> |
| <dt><span class="paramLabel">Parameters:</span></dt> |
| <dd><code>name</code> - the name of the <a href="https://docs.oracle.com/javase/8/docs/api/java/security/MessageDigest.html?is-external=true" title="class or interface in java.security" class="externalLink"><code>MessageDigest</code></a> algorithm that will be used to |
| compute hashes.</dd> |
| </dl> |
| </li> |
| </ul> |
| <a id="getHashAlgorithmName()"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>getHashAlgorithmName</h4> |
| <pre class="methodSignature">public <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang" class="externalLink">String</a> <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.279">getHashAlgorithmName</a>()</pre> |
| </li> |
| </ul> |
| <a id="setPrivateSalt(org.apache.shiro.util.ByteSource)"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>setPrivateSalt</h4> |
| <pre class="methodSignature">public void <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.283">setPrivateSalt</a>​(org.apache.shiro.util.ByteSource privateSalt)</pre> |
| <div class="block"><span class="descfrmTypeLabel">Description copied from interface: <code><a href="ConfigurableHashService.html#setPrivateSalt(org.apache.shiro.util.ByteSource)">ConfigurableHashService</a></code></span></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><span class="overrideSpecifyLabel">Specified by:</span></dt> |
| <dd><code><a href="ConfigurableHashService.html#setPrivateSalt(org.apache.shiro.util.ByteSource)">setPrivateSalt</a></code> in interface <code><a href="ConfigurableHashService.html" title="interface in org.apache.shiro.crypto.hash">ConfigurableHashService</a></code></dd> |
| <dt><span class="paramLabel">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 id="getPrivateSalt()"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>getPrivateSalt</h4> |
| <pre class="methodSignature">public org.apache.shiro.util.ByteSource <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.287">getPrivateSalt</a>()</pre> |
| </li> |
| </ul> |
| <a id="setHashIterations(int)"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>setHashIterations</h4> |
| <pre class="methodSignature">public void <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.291">setHashIterations</a>​(int count)</pre> |
| <div class="block"><span class="descfrmTypeLabel">Description copied from interface: <code><a href="ConfigurableHashService.html#setHashIterations(int)">ConfigurableHashService</a></code></span></div> |
| <div class="block">Sets the number of hash iterations that will be performed during hash computation.</div> |
| <dl> |
| <dt><span class="overrideSpecifyLabel">Specified by:</span></dt> |
| <dd><code><a href="ConfigurableHashService.html#setHashIterations(int)">setHashIterations</a></code> in interface <code><a href="ConfigurableHashService.html" title="interface in org.apache.shiro.crypto.hash">ConfigurableHashService</a></code></dd> |
| <dt><span class="paramLabel">Parameters:</span></dt> |
| <dd><code>count</code> - the number of hash iterations that will be performed during hash computation.</dd> |
| </dl> |
| </li> |
| </ul> |
| <a id="getHashIterations()"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>getHashIterations</h4> |
| <pre class="methodSignature">public int <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.295">getHashIterations</a>()</pre> |
| </li> |
| </ul> |
| <a id="setRandomNumberGenerator(org.apache.shiro.crypto.RandomNumberGenerator)"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>setRandomNumberGenerator</h4> |
| <pre class="methodSignature">public void <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.299">setRandomNumberGenerator</a>​(org.apache.shiro.crypto.RandomNumberGenerator rng)</pre> |
| <div class="block"><span class="descfrmTypeLabel">Description copied from interface: <code><a href="ConfigurableHashService.html#setRandomNumberGenerator(org.apache.shiro.crypto.RandomNumberGenerator)">ConfigurableHashService</a></code></span></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><span class="overrideSpecifyLabel">Specified by:</span></dt> |
| <dd><code><a href="ConfigurableHashService.html#setRandomNumberGenerator(org.apache.shiro.crypto.RandomNumberGenerator)">setRandomNumberGenerator</a></code> in interface <code><a href="ConfigurableHashService.html" title="interface in org.apache.shiro.crypto.hash">ConfigurableHashService</a></code></dd> |
| <dt><span class="paramLabel">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 id="getRandomNumberGenerator()"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>getRandomNumberGenerator</h4> |
| <pre class="methodSignature">public org.apache.shiro.crypto.RandomNumberGenerator <a href="../../../../../src-html/org/apache/shiro/crypto/hash/DefaultHashService.html#line.303">getRandomNumberGenerator</a>()</pre> |
| </li> |
| </ul> |
| <a id="isGeneratePublicSalt()"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>isGeneratePublicSalt</h4> |
| <pre class="methodSignature">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="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="#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="returnLabel">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="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 id="setGeneratePublicSalt(boolean)"> |
| <!-- --> |
| </a> |
| <ul class="blockListLast"> |
| <li class="blockList"> |
| <h4>setGeneratePublicSalt</h4> |
| <pre class="methodSignature">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="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="#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="paramLabel">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="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> |
| </section> |
| </li> |
| </ul> |
| </div> |
| </div> |
| </main> |
| <!-- ========= END OF CLASS DATA ========= --> |
| <footer role="contentinfo"> |
| <nav role="navigation"> |
| <!-- ======= START OF BOTTOM NAVBAR ====== --> |
| <div class="bottomNav"><a id="navbar.bottom"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div> |
| <a id="navbar.bottom.firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../../../index.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" id="allclasses_navbar_bottom"> |
| <li><a href="../../../../../allclasses.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> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| </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 id="skip.navbar.bottom"> |
| <!-- --> |
| </a></div> |
| <!-- ======== END OF BOTTOM NAVBAR ======= --> |
| </nav> |
| <p class="legalCopy"><small>Copyright © 2004–2022 <a href="https://www.apache.org/">The Apache Software Foundation</a>. All rights reserved.</small></p> |
| </footer> |
| </body> |
| </html> |