uTools-Manuals/docs/java/javax/crypto/KeyAgreement.html

670 lines
36 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<div class="header">
<div class="subTitle">
javax.crypto
</div>
<h2 class="title" title="Class KeyAgreement">Class KeyAgreement</h2>
</div><div class="contentContainer">
<ul class="inheritance">
<li><a href="../../java/lang/Object.html" title="class in java.lang">java.lang.Object</a></li>
<li>
<ul class="inheritance">
<li>javax.crypto.KeyAgreement</li>
</ul> </li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr/> <br/> <pre>public class <span class="typeNameLabel">KeyAgreement</span>
extends <a href="../../java/lang/Object.html" title="class in java.lang">Object</a></pre>
<div class="block">
<span>该类提供了密钥协议(或密钥交换)协议的功能。</span>
<p> <span>涉及建立共享秘密的密钥由密钥发生器( <code>KeyPairGenerator</code><code>KeyGenerator</code> )之一, <code>KeyFactory</code>或由密钥协商协议的中间阶段的结果创建。</span> </p>
<p> <span>对于密钥交换中的<code>doPhase</code>需要调用<code>doPhase</code></span> <span>例如,如果这个密钥交换是与另一方进行的, <code>doPhase</code>需要被调用一次,其中<code>lastPhase</code>标志设置为<code>true</code></span> <span>如果这个密钥交换是与另外两个方, <code>doPhase</code>需要被叫两次,首次将<code>lastPhase</code>标志设置为<code>false</code> ,第二次设置为<code>true</code></span> <span>密钥交换中可能存在任何数量的参与方。</span> </p>
<p> <span>Java平台的每个实现都需要支持以下标准<code>KeyAgreement</code>算法:</span> </p>
<ul>
<li> <span><tt>DiffieHellman</tt></span> </li>
</ul>
<span>该算法在描述<a href="../../../technotes/guides/security/StandardNames.html#KeyAgreement">KeyAgreement section</a> Java加密体系结构标准算法名称的文档。</span>
<span>请参阅发行说明文件以了解是否支持其他算法。</span>
</div>
<dl>
<dt>
<span class="simpleTagLabel">从以下版本开始:</span>
</dt>
<dd>
1.4
</dd>
<dt>
<span class="seeLabel">另请参见:</span>
</dt>
<dd>
<span><a href="../../javax/crypto/KeyGenerator.html" title="javax.crypto中的类"><code>KeyGenerator</code></a> <a href="../../javax/crypto/SecretKey.html" title="javax.crypto中的接口"><code>SecretKey</code></a></span>
</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>构造方法摘要</h3>
<table border="0" cellpadding="3" cellspacing="0" class="memberSummary" summary="Constructor Summary table, listing constructors, and an explanation">
<caption>
<span>构造方法</span>
<span class="tabEnd"> </span>
</caption>
<tbody>
<tr>
<th class="colFirst" scope="col">Modifier</th>
<th class="colLast" scope="col">Constructor and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>protected </code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../javax/crypto/KeyAgreement.html#KeyAgreement-javax.crypto.KeyAgreementSpi-java.security.Provider-java.lang.String-">KeyAgreement</a></span>(<a href="../../javax/crypto/KeyAgreementSpi.html" title="class in javax.crypto">KeyAgreementSpi</a> keyAgreeSpi, <a href="../../java/security/Provider.html" title="class in java.security">Provider</a> provider, <a href="../../java/lang/String.html" title="class in java.lang">String</a> algorithm)</code>
<div class="block">
创建一个KeyAgreement对象。
</div> </td>
</tr>
</tbody>
</table> </li>
</ul>
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method.summary">
<!-- --> </a> <h3>方法摘要</h3>
<table border="0" cellpadding="3" cellspacing="0" class="memberSummary" summary="Method Summary table, listing methods, and an explanation">
<caption>
<span class="activeTableTab" id="t0"><span>所有方法</span><span class="tabEnd"> </span></span>
<span class="tableTab" id="t1"><span><a href="javascript:show(1);">静态方法</a></span><span class="tabEnd"> </span></span>
<span class="tableTab" id="t2"><span><a href="javascript:show(2);">接口方法</a></span><span class="tabEnd"> </span></span>
<span class="tableTab" id="t4"><span><a href="javascript:show(8);">具体的方法</a></span><span class="tabEnd"> </span></span>
</caption>
<tbody>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr class="altColor" id="i0">
<td class="colFirst"><code><a href="../../java/security/Key.html" title="interface in java.security">Key</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../javax/crypto/KeyAgreement.html#doPhase-java.security.Key-boolean-">doPhase</a></span>(<a href="../../java/security/Key.html" title="interface in java.security">Key</a> key, boolean lastPhase)</code>
<div class="block">
执行该关键协议的下一阶段,其中包含从本协议涉及的其中一方收到的给定密钥。
</div> </td>
</tr>
<tr class="rowColor" id="i1">
<td class="colFirst"><code>byte[]</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../javax/crypto/KeyAgreement.html#generateSecret--">generateSecret</a></span>()</code>
<div class="block">
生成共享密钥并将其返回到新的缓冲区。
</div> </td>
</tr>
<tr class="altColor" id="i2">
<td class="colFirst"><code>int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../javax/crypto/KeyAgreement.html#generateSecret-byte:A-int-">generateSecret</a></span>(byte[] sharedSecret, int offset)</code>
<div class="block">
生成共享密钥,并将其放入缓冲区
<code>sharedSecret</code> ,从
<code>offset</code>开始。
</div> </td>
</tr>
<tr class="rowColor" id="i3">
<td class="colFirst"><code><a href="../../javax/crypto/SecretKey.html" title="interface in javax.crypto">SecretKey</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../javax/crypto/KeyAgreement.html#generateSecret-java.lang.String-">generateSecret</a></span>(<a href="../../java/lang/String.html" title="class in java.lang">String</a> algorithm)</code>
<div class="block">
创建共享密钥,并将其作为指定
<code>SecretKey</code>对象返回。
</div> </td>
</tr>
<tr class="altColor" id="i4">
<td class="colFirst"><code><a href="../../java/lang/String.html" title="class in java.lang">String</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../javax/crypto/KeyAgreement.html#getAlgorithm--">getAlgorithm</a></span>()</code>
<div class="block">
返回此
<code>KeyAgreement</code>对象的算法名称。
</div> </td>
</tr>
<tr class="rowColor" id="i5">
<td class="colFirst"><code>static <a href="../../javax/crypto/KeyAgreement.html" title="class in javax.crypto">KeyAgreement</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../javax/crypto/KeyAgreement.html#getInstance-java.lang.String-">getInstance</a></span>(<a href="../../java/lang/String.html" title="class in java.lang">String</a> algorithm)</code>
<div class="block">
返回实现指定的密钥协商算法的
<code>KeyAgreement</code>对象。
</div> </td>
</tr>
<tr class="altColor" id="i6">
<td class="colFirst"><code>static <a href="../../javax/crypto/KeyAgreement.html" title="class in javax.crypto">KeyAgreement</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../javax/crypto/KeyAgreement.html#getInstance-java.lang.String-java.security.Provider-">getInstance</a></span>(<a href="../../java/lang/String.html" title="class in java.lang">String</a> algorithm, <a href="../../java/security/Provider.html" title="class in java.security">Provider</a> provider)</code>
<div class="block">
返回实现指定的密钥协商算法的
<code>KeyAgreement</code>对象。
</div> </td>
</tr>
<tr class="rowColor" id="i7">
<td class="colFirst"><code>static <a href="../../javax/crypto/KeyAgreement.html" title="class in javax.crypto">KeyAgreement</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../javax/crypto/KeyAgreement.html#getInstance-java.lang.String-java.lang.String-">getInstance</a></span>(<a href="../../java/lang/String.html" title="class in java.lang">String</a> algorithm, <a href="../../java/lang/String.html" title="class in java.lang">String</a> provider)</code>
<div class="block">
返回实现指定密钥协商算法的
<code>KeyAgreement</code>对象。
</div> </td>
</tr>
<tr class="altColor" id="i8">
<td class="colFirst"><code><a href="../../java/security/Provider.html" title="class in java.security">Provider</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../javax/crypto/KeyAgreement.html#getProvider--">getProvider</a></span>()</code>
<div class="block">
返回此
<code>KeyAgreement</code>对象的提供者。
</div> </td>
</tr>
<tr class="rowColor" id="i9">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../javax/crypto/KeyAgreement.html#init-java.security.Key-">init</a></span>(<a href="../../java/security/Key.html" title="interface in java.security">Key</a> key)</code>
<div class="block">
使用给定的密钥初始化此密钥协议,该密钥需要包含此密钥协议所需的所有算法参数。
</div> </td>
</tr>
<tr class="altColor" id="i10">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../javax/crypto/KeyAgreement.html#init-java.security.Key-java.security.spec.AlgorithmParameterSpec-">init</a></span>(<a href="../../java/security/Key.html" title="interface in java.security">Key</a> key, <a href="../../java/security/spec/AlgorithmParameterSpec.html" title="interface in java.security.spec">AlgorithmParameterSpec</a> params)</code>
<div class="block">
使用给定的密钥和算法参数集初始化此密钥协议。
</div> </td>
</tr>
<tr class="rowColor" id="i11">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../javax/crypto/KeyAgreement.html#init-java.security.Key-java.security.spec.AlgorithmParameterSpec-java.security.SecureRandom-">init</a></span>(<a href="../../java/security/Key.html" title="interface in java.security">Key</a> key, <a href="../../java/security/spec/AlgorithmParameterSpec.html" title="interface in java.security.spec">AlgorithmParameterSpec</a> params, <a href="../../java/security/SecureRandom.html" title="class in java.security">SecureRandom</a> random)</code>
<div class="block">
使用给定的密钥,算法参数集合和随机源初始化此密钥协议。
</div> </td>
</tr>
<tr class="altColor" id="i12">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../javax/crypto/KeyAgreement.html#init-java.security.Key-java.security.SecureRandom-">init</a></span>(<a href="../../java/security/Key.html" title="interface in java.security">Key</a> key, <a href="../../java/security/SecureRandom.html" title="class in java.security">SecureRandom</a> random)</code>
<div class="block">
用给定的密钥和随机源初始化这个密钥协商。
</div> </td>
</tr>
</tbody>
</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="../../java/lang/Object.html" title="class in java.lang">Object</a></h3> <code><a href="../../java/lang/Object.html#clone--">clone</a>, <a href="../../java/lang/Object.html#equals-java.lang.Object-">equals</a>, <a href="../../java/lang/Object.html#finalize--">finalize</a>, <a href="../../java/lang/Object.html#getClass--">getClass</a>, <a href="../../java/lang/Object.html#hashCode--">hashCode</a>, <a href="../../java/lang/Object.html#notify--">notify</a>, <a href="../../java/lang/Object.html#notifyAll--">notifyAll</a>, <a href="../../java/lang/Object.html#toString--">toString</a>, <a href="../../java/lang/Object.html#wait--">wait</a>, <a href="../../java/lang/Object.html#wait-long-">wait</a>, <a href="../../java/lang/Object.html#wait-long-int-">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>构造方法详细信息</h3> <a name="KeyAgreement-javax.crypto.KeyAgreementSpi-java.security.Provider-java.lang.String-">
<!-- --> </a>
<ul class="blockListLast">
<li class="blockList"> <h4>KeyAgreement</h4> <pre>protected KeyAgreement(<a href="../../javax/crypto/KeyAgreementSpi.html" title="class in javax.crypto">KeyAgreementSpi</a> keyAgreeSpi,
<a href="../../java/security/Provider.html" title="class in java.security">Provider</a> provider,
<a href="../../java/lang/String.html" title="class in java.lang">String</a> algorithm)</pre>
<div class="block">
创建一个KeyAgreement对象。
</div>
<dl>
<dt>
<span class="paramLabel">参数</span>
</dt>
<dd>
<code>keyAgreeSpi</code> - 代表
</dd>
<dd>
<code>provider</code> - 提供商
</dd>
<dd>
<code>algorithm</code> - 算法
</dd>
</dl> </li>
</ul> </li>
</ul>
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method.detail">
<!-- --> </a> <h3>方法详细信息</h3> <a name="getAlgorithm--">
<!-- --> </a>
<ul class="blockList">
<li class="blockList"> <h4>getAlgorithm</h4> <pre>public final <a href="../../java/lang/String.html" title="class in java.lang">String</a> getAlgorithm()</pre>
<div class="block">
<span>返回此<code>KeyAgreement</code>对象的算法名称。</span>
<p> <span>这是在创建此<code>KeyAgreement</code>对象的<code>getInstance</code>呼叫之一中指定的<code>getInstance</code></span> </p>
</div>
<dl>
<dt>
<span class="returnLabel">结果</span>
</dt>
<dd>
这个
<code>KeyAgreement</code>对象的算法名称。
</dd>
</dl> </li>
</ul> <a name="getInstance-java.lang.String-">
<!-- --> </a>
<ul class="blockList">
<li class="blockList"> <h4>getInstance</h4> <pre>public static final <a href="../../javax/crypto/KeyAgreement.html" title="class in javax.crypto">KeyAgreement</a> getInstance(<a href="../../java/lang/String.html" title="class in java.lang">String</a> algorithm)
throws <a href="../../java/security/NoSuchAlgorithmException.html" title="class in java.security">NoSuchAlgorithmException</a></pre>
<div class="block">
<span>返回实现指定的密钥协商算法的<code>KeyAgreement</code>对象。</span>
<p> <span>此方法遍历已注册的安全提供程序列表,从最优选的提供程序开始。</span> <span>返回从支持指定算法的第一个Provider中封装KeyAgreementSpi实现的新KeyAgreement对象。</span> </p>
<p> <span>请注意,可以通过<a href="../../java/security/Security.html#getProviders--"><code>Security.getProviders()</code></a>方法检索已注册提供商的列表。</span> </p>
</div>
<dl>
<dt>
<span class="paramLabel">参数</span>
</dt>
<dd>
<span><code>algorithm</code> - 所请求的密钥协商算法的标准名称。</span>
<span>看到该协议密钥部分<a href="../../../technotes/guides/security/StandardNames.html#KeyAgreement">Java Cryptography Architecture Standard Algorithm Name Documentation</a>有关标准算法名称的信息。</span>
</dd>
<dt>
<span class="returnLabel">结果</span>
</dt>
<dd>
新的
<code>KeyAgreement</code>对象。
</dd>
<dt>
<span class="throwsLabel">异常</span>
</dt>
<dd>
<code><a href="../../java/lang/NullPointerException.html" title="class in java.lang">NullPointerException</a></code> - 如果指定的算法为空。
</dd>
<dd>
<code><a href="../../java/security/NoSuchAlgorithmException.html" title="class in java.security">NoSuchAlgorithmException</a></code> - 如果没有提供者支持指定算法的KeyAgreementSpi实现。
</dd>
<dt>
<span class="seeLabel">另请参见:</span>
</dt>
<dd>
<span><a href="../../java/security/Provider.html" title="java.security中的类"><code>Provider</code></a></span>
</dd>
</dl> </li>
</ul> <a name="getInstance-java.lang.String-java.lang.String-">
<!-- --> </a>
<ul class="blockList">
<li class="blockList"> <h4>getInstance</h4> <pre>public static final <a href="../../javax/crypto/KeyAgreement.html" title="class in javax.crypto">KeyAgreement</a> getInstance(<a href="../../java/lang/String.html" title="class in java.lang">String</a> algorithm,
<a href="../../java/lang/String.html" title="class in java.lang">String</a> provider)
throws <a href="../../java/security/NoSuchAlgorithmException.html" title="class in java.security">NoSuchAlgorithmException</a>,
<a href="../../java/security/NoSuchProviderException.html" title="class in java.security">NoSuchProviderException</a></pre>
<div class="block">
<span>返回实现指定的密钥协商算法的<code>KeyAgreement</code>对象。</span>
<p> <span>返回从指定提供程序封装KeyAgreementSpi实现的新KeyAgreement对象。</span> <span>指定的提供者必须在安全提供程序列表中注册。</span> </p>
<p> <span>请注意,可以通过<a href="../../java/security/Security.html#getProviders--"><code>Security.getProviders()</code></a>方法检索注册提供商的列表。</span> </p>
</div>
<dl>
<dt>
<span class="paramLabel">参数</span>
</dt>
<dd>
<span><code>algorithm</code> - 请求的密钥协商算法的标准名称。</span>
<span>看到该协议密钥部分<a href="../../../technotes/guides/security/StandardNames.html#KeyAgreement">Java Cryptography Architecture Standard Algorithm Name Documentation</a>有关标准算法名称的信息。</span>
</dd>
<dd>
<code>provider</code> - 提供商的名称。
</dd>
<dt>
<span class="returnLabel">结果</span>
</dt>
<dd>
新的
<code>KeyAgreement</code>对象。
</dd>
<dt>
<span class="throwsLabel">异常</span>
</dt>
<dd>
<code><a href="../../java/lang/NullPointerException.html" title="class in java.lang">NullPointerException</a></code> - 如果指定的算法为空。
</dd>
<dd>
<code><a href="../../java/security/NoSuchAlgorithmException.html" title="class in java.security">NoSuchAlgorithmException</a></code> - 如果指定算法的KeyAgreementSpi实现不能从指定的提供者获得。
</dd>
<dd>
<code><a href="../../java/security/NoSuchProviderException.html" title="class in java.security">NoSuchProviderException</a></code> - 如果指定的提供程序未在安全提供程序列表中注册。
</dd>
<dd>
<code><a href="../../java/lang/IllegalArgumentException.html" title="class in java.lang">IllegalArgumentException</a></code> - 如果
<code>provider</code>为空或为空。
</dd>
<dt>
<span class="seeLabel">另请参见:</span>
</dt>
<dd>
<span><a href="../../java/security/Provider.html" title="java.security中的类"><code>Provider</code></a></span>
</dd>
</dl> </li>
</ul> <a name="getInstance-java.lang.String-java.security.Provider-">
<!-- --> </a>
<ul class="blockList">
<li class="blockList"> <h4>getInstance</h4> <pre>public static final <a href="../../javax/crypto/KeyAgreement.html" title="class in javax.crypto">KeyAgreement</a> getInstance(<a href="../../java/lang/String.html" title="class in java.lang">String</a> algorithm,
<a href="../../java/security/Provider.html" title="class in java.security">Provider</a> provider)
throws <a href="../../java/security/NoSuchAlgorithmException.html" title="class in java.security">NoSuchAlgorithmException</a></pre>
<div class="block">
<span>返回实现指定的密钥协商算法的<code>KeyAgreement</code>对象。</span>
<p> <span>返回从指定的Provider对象封装KeyAgreementSpi实现的新KeyAgreement对象。</span> <span>请注意指定的Provider对象不必在提供者列表中注册。</span> </p>
</div>
<dl>
<dt>
<span class="paramLabel">参数</span>
</dt>
<dd>
<span><code>algorithm</code> - 请求密钥协议算法的标准名称。</span>
<span>看到该协议密钥部分<a href="../../../technotes/guides/security/StandardNames.html#KeyAgreement">Java Cryptography Architecture Standard Algorithm Name Documentation</a>有关标准算法名称的信息。</span>
</dd>
<dd>
<code>provider</code> - 提供商。
</dd>
<dt>
<span class="returnLabel">结果</span>
</dt>
<dd>
新的
<code>KeyAgreement</code>对象。
</dd>
<dt>
<span class="throwsLabel">异常</span>
</dt>
<dd>
<code><a href="../../java/lang/NullPointerException.html" title="class in java.lang">NullPointerException</a></code> - 如果指定的算法为空。
</dd>
<dd>
<code><a href="../../java/security/NoSuchAlgorithmException.html" title="class in java.security">NoSuchAlgorithmException</a></code> - 如果指定的算法的KeyAgreementSpi实现从指定的Provider对象不可用。
</dd>
<dd>
<code><a href="../../java/lang/IllegalArgumentException.html" title="class in java.lang">IllegalArgumentException</a></code> - 如果
<code>provider</code>为空。
</dd>
<dt>
<span class="seeLabel">另请参见:</span>
</dt>
<dd>
<span><a href="../../java/security/Provider.html" title="java.security中的类"><code>Provider</code></a></span>
</dd>
</dl> </li>
</ul> <a name="getProvider--">
<!-- --> </a>
<ul class="blockList">
<li class="blockList"> <h4>getProvider</h4> <pre>public final <a href="../../java/security/Provider.html" title="class in java.security">Provider</a> getProvider()</pre>
<div class="block">
返回此
<code>KeyAgreement</code>对象的提供者。
</div>
<dl>
<dt>
<span class="returnLabel">结果</span>
</dt>
<dd>
这个
<code>KeyAgreement</code>对象的提供者
</dd>
</dl> </li>
</ul> <a name="init-java.security.Key-">
<!-- --> </a>
<ul class="blockList">
<li class="blockList"> <h4>init</h4> <pre>public final void init(<a href="../../java/security/Key.html" title="interface in java.security">Key</a> key)
throws <a href="../../java/security/InvalidKeyException.html" title="class in java.security">InvalidKeyException</a></pre>
<div class="block">
<span>使用给定的密钥初始化此密钥协议,该密钥需要包含此密钥协议所需的所有算法参数。</span>
<p> <span>如果此项协议需要随机字节,它会使用让他们<a href="../../java/security/SecureRandom.html" title="java.security中的类"><code>SecureRandom</code></a>实现的最高优先级安装的提供作为随机源。</span> <span>如果没有一个已安装的提供商提供SecureRandom的实现将会使用系统提供的随机源。</span> </p>
</div>
<dl>
<dt>
<span class="paramLabel">参数</span>
</dt>
<dd>
<span><code>key</code> - 党的私人信息。</span>
<span>例如在Diffie-Hellman密钥协议的情况下这将是该方自己的Diffie-Hellman私钥。</span>
</dd>
<dt>
<span class="throwsLabel">异常</span>
</dt>
<dd>
<code><a href="../../java/security/InvalidKeyException.html" title="class in java.security">InvalidKeyException</a></code> - 如果给定的密钥对于该密钥协议是不合适的,例如,是错误的类型或具有不兼容的算法类型。
</dd>
</dl> </li>
</ul> <a name="init-java.security.Key-java.security.SecureRandom-">
<!-- --> </a>
<ul class="blockList">
<li class="blockList"> <h4>init</h4> <pre>public final void init(<a href="../../java/security/Key.html" title="interface in java.security">Key</a> key,
<a href="../../java/security/SecureRandom.html" title="class in java.security">SecureRandom</a> random)
throws <a href="../../java/security/InvalidKeyException.html" title="class in java.security">InvalidKeyException</a></pre>
<div class="block">
<span>用给定的密钥和随机源初始化这个密钥协商。</span>
<span>给定密钥需要包含此密钥协议所需的所有算法参数。</span>
<p> <span>如果密钥协商算法需要随机字节,则从给定的随机源获得它们, <code>random</code></span> <span>但是,如果底层算法实现不需要任何随机字节,则忽略<code>random</code></span> </p>
</div>
<dl>
<dt>
<span class="paramLabel">参数</span>
</dt>
<dd>
<span><code>key</code> - 党的私人信息。</span>
<span>例如在Diffie-Hellman密钥协议的情况下这将是该方自己的Diffie-Hellman私钥。</span>
</dd>
<dd>
<code>random</code> -
<code>random</code>的来源
</dd>
<dt>
<span class="throwsLabel">异常</span>
</dt>
<dd>
<code><a href="../../java/security/InvalidKeyException.html" title="class in java.security">InvalidKeyException</a></code> - 如果给定的密钥对于该密钥协议是不合适的,例如,是错误的类型或具有不兼容的算法类型。
</dd>
</dl> </li>
</ul> <a name="init-java.security.Key-java.security.spec.AlgorithmParameterSpec-">
<!-- --> </a>
<ul class="blockList">
<li class="blockList"> <h4>init</h4> <pre>public final void init(<a href="../../java/security/Key.html" title="interface in java.security">Key</a> key,
<a href="../../java/security/spec/AlgorithmParameterSpec.html" title="interface in java.security.spec">AlgorithmParameterSpec</a> params)
throws <a href="../../java/security/InvalidKeyException.html" title="class in java.security">InvalidKeyException</a>,
<a href="../../java/security/InvalidAlgorithmParameterException.html" title="class in java.security">InvalidAlgorithmParameterException</a></pre>
<div class="block">
<span>使用给定的密钥和算法参数集初始化此密钥协议。</span>
<p> <span>如果此项协议需要随机字节,它会使用让他们<a href="../../java/security/SecureRandom.html" title="java.security中的类"><code>SecureRandom</code></a>实现的最高优先级安装的提供作为随机源。</span> <span>如果没有一个已安装的提供商提供SecureRandom的实现将会使用系统提供的随机源。</span> </p>
</div>
<dl>
<dt>
<span class="paramLabel">参数</span>
</dt>
<dd>
<span><code>key</code> - 党的私人信息。</span>
<span>例如在Diffie-Hellman密钥协议的情况下这将是该方自己的Diffie-Hellman私钥。</span>
</dd>
<dd>
<code>params</code> - 关键协议参数
</dd>
<dt>
<span class="throwsLabel">异常</span>
</dt>
<dd>
<code><a href="../../java/security/InvalidKeyException.html" title="class in java.security">InvalidKeyException</a></code> - 如果给定的密钥对于该密钥协议是不合适的,例如,是错误的类型或具有不兼容的算法类型。
</dd>
<dd>
<code><a href="../../java/security/InvalidAlgorithmParameterException.html" title="class in java.security">InvalidAlgorithmParameterException</a></code> - 如果给定的参数不适合此密钥协议。
</dd>
</dl> </li>
</ul> <a name="init-java.security.Key-java.security.spec.AlgorithmParameterSpec-java.security.SecureRandom-">
<!-- --> </a>
<ul class="blockList">
<li class="blockList"> <h4>init</h4> <pre>public final void init(<a href="../../java/security/Key.html" title="interface in java.security">Key</a> key,
<a href="../../java/security/spec/AlgorithmParameterSpec.html" title="interface in java.security.spec">AlgorithmParameterSpec</a> params,
<a href="../../java/security/SecureRandom.html" title="class in java.security">SecureRandom</a> random)
throws <a href="../../java/security/InvalidKeyException.html" title="class in java.security">InvalidKeyException</a>,
<a href="../../java/security/InvalidAlgorithmParameterException.html" title="class in java.security">InvalidAlgorithmParameterException</a></pre>
<div class="block">
使用给定的密钥,算法参数集合和随机源初始化此密钥协议。
</div>
<dl>
<dt>
<span class="paramLabel">参数</span>
</dt>
<dd>
<span><code>key</code> - 党的私人信息。</span>
<span>例如在Diffie-Hellman密钥协议的情况下这将是该方自己的Diffie-Hellman私钥。</span>
</dd>
<dd>
<code>params</code> - 密钥协商参数
</dd>
<dd>
<code>random</code> -
<code>random</code>的来源
</dd>
<dt>
<span class="throwsLabel">异常</span>
</dt>
<dd>
<code><a href="../../java/security/InvalidKeyException.html" title="class in java.security">InvalidKeyException</a></code> - 如果给定的密钥对于该密钥协议是不合适的,例如,是错误的类型或具有不兼容的算法类型。
</dd>
<dd>
<code><a href="../../java/security/InvalidAlgorithmParameterException.html" title="class in java.security">InvalidAlgorithmParameterException</a></code> - 如果给定的参数不适用于此密钥协议。
</dd>
</dl> </li>
</ul> <a name="doPhase-java.security.Key-boolean-">
<!-- --> </a>
<ul class="blockList">
<li class="blockList"> <h4>doPhase</h4> <pre>public final <a href="../../java/security/Key.html" title="interface in java.security">Key</a> doPhase(<a href="../../java/security/Key.html" title="interface in java.security">Key</a> key,
boolean lastPhase)
throws <a href="../../java/security/InvalidKeyException.html" title="class in java.security">InvalidKeyException</a>,
<a href="../../java/lang/IllegalStateException.html" title="class in java.lang">IllegalStateException</a></pre>
<div class="block">
执行该关键协议的下一阶段,其中包含从本协议涉及的其中一方收到的给定密钥。
</div>
<dl>
<dt>
<span class="paramLabel">参数</span>
</dt>
<dd>
<span><code>key</code> - 这个阶段的关键。</span>
<span>例如在双方之间的Diffie-Hellman的情况下这将是对方的Diffie-Hellman公钥。</span>
</dd>
<dd>
<code>lastPhase</code> - 表示这是否是该密钥协议的最后一个阶段的标志。
</dd>
<dt>
<span class="returnLabel">结果</span>
</dt>
<dd>
由此阶段产生的中间密钥如果此阶段不产生密钥则为null
</dd>
<dt>
<span class="throwsLabel">异常</span>
</dt>
<dd>
<code><a href="../../java/security/InvalidKeyException.html" title="class in java.security">InvalidKeyException</a></code> - 如果给定的键不适合此阶段。
</dd>
<dd>
<code><a href="../../java/lang/IllegalStateException.html" title="class in java.lang">IllegalStateException</a></code> - 如果此密钥协议尚未初始化。
</dd>
</dl> </li>
</ul> <a name="generateSecret--">
<!-- --> </a>
<ul class="blockList">
<li class="blockList"> <h4>generateSecret</h4> <pre>public final byte[] generateSecret()
throws <a href="../../java/lang/IllegalStateException.html" title="class in java.lang">IllegalStateException</a></pre>
<div class="block">
<span>生成共享密钥并将其返回到新的缓冲区。</span>
<p> <span>此方法重置此<code>KeyAgreement</code>对象,以便可以重新用于进一步的关键协议。</span> <span>除非使用<code>init</code>方法重新初始化该密钥协议,否则相同的私有信息和算法参数将用于后续密钥协议。</span> </p>
</div>
<dl>
<dt>
<span class="returnLabel">结果</span>
</dt>
<dd>
新的缓冲区与共享的秘密
</dd>
<dt>
<span class="throwsLabel">异常</span>
</dt>
<dd>
<code><a href="../../java/lang/IllegalStateException.html" title="class in java.lang">IllegalStateException</a></code> - 如果此关键协议尚未完成
</dd>
</dl> </li>
</ul> <a name="generateSecret-byte:A-int-">
<!-- --> </a>
<ul class="blockList">
<li class="blockList"> <h4>generateSecret</h4> <pre>public final int generateSecret(byte[] sharedSecret,
int offset)
throws <a href="../../java/lang/IllegalStateException.html" title="class in java.lang">IllegalStateException</a>,
<a href="../../javax/crypto/ShortBufferException.html" title="class in javax.crypto">ShortBufferException</a></pre>
<div class="block">
<span>生成共享密钥,并将其放入缓冲区<code>sharedSecret</code> ,从<code>offset</code>开始。</span>
<p> <span>如果<code>sharedSecret</code>缓冲区太小而不能保存结果,则抛出<code>ShortBufferException</code></span> <span>在这种情况下,应该使用较大的输出缓冲区来重复此调用。</span> </p>
<p> <span>此方法重置此<code>KeyAgreement</code>对象,以便可以重新用于进一步的关键协议。</span> <span>除非使用<code>init</code>方法重新初始化此密钥协议,否则相同的私有信息和算法参数将用于后续密钥协议。</span> </p>
</div>
<dl>
<dt>
<span class="paramLabel">参数</span>
</dt>
<dd>
<code>sharedSecret</code> - 共享密码的缓冲区
</dd>
<dd>
<code>offset</code> -
<code>sharedSecret</code>中的共享密钥将被存储的偏移量
</dd>
<dt>
<span class="returnLabel">结果</span>
</dt>
<dd>
放入
<code>sharedSecret</code>的字节数
</dd>
<dt>
<span class="throwsLabel">异常</span>
</dt>
<dd>
<code><a href="../../java/lang/IllegalStateException.html" title="class in java.lang">IllegalStateException</a></code> - 如果此关键协议尚未完成
</dd>
<dd>
<code><a href="../../javax/crypto/ShortBufferException.html" title="class in javax.crypto">ShortBufferException</a></code> - 如果给定的输出缓冲区太小,不能容纳秘密
</dd>
</dl> </li>
</ul> <a name="generateSecret-java.lang.String-">
<!-- --> </a>
<ul class="blockListLast">
<li class="blockList"> <h4>generateSecret</h4> <pre>public final <a href="../../javax/crypto/SecretKey.html" title="interface in javax.crypto">SecretKey</a> generateSecret(<a href="../../java/lang/String.html" title="class in java.lang">String</a> algorithm)
throws <a href="../../java/lang/IllegalStateException.html" title="class in java.lang">IllegalStateException</a>,
<a href="../../java/security/NoSuchAlgorithmException.html" title="class in java.security">NoSuchAlgorithmException</a>,
<a href="../../java/security/InvalidKeyException.html" title="class in java.security">InvalidKeyException</a></pre>
<div class="block">
<span>创建共享密钥,并将其作为指定<code>SecretKey</code>对象返回。</span>
<p> <span>此方法重置此<code>KeyAgreement</code>对象,以便可以重新用于进一步的关键协议。</span> <span>除非使用<code>init</code>方法重新初始化该密钥协议,否则相同的私有信息和算法参数将用于后续密钥协议。</span> </p>
</div>
<dl>
<dt>
<span class="paramLabel">参数</span>
</dt>
<dd>
<code>algorithm</code> - 所请求的秘密密钥算法
</dd>
<dt>
<span class="returnLabel">结果</span>
</dt>
<dd>
共享密钥
</dd>
<dt>
<span class="throwsLabel">异常</span>
</dt>
<dd>
<code><a href="../../java/lang/IllegalStateException.html" title="class in java.lang">IllegalStateException</a></code> - 如果此关键协议尚未完成
</dd>
<dd>
<code><a href="../../java/security/NoSuchAlgorithmException.html" title="class in java.security">NoSuchAlgorithmException</a></code> - 如果指定的秘密密钥算法不可用
</dd>
<dd>
<code><a href="../../java/security/InvalidKeyException.html" title="class in java.security">InvalidKeyException</a></code> - 如果共享的密钥材料不能用于生成指定算法的密钥(例如,密钥材料太短)
</dd>
</dl> </li>
</ul> </li>
</ul> </li>
</ul>
</div>
</div>