public class KeyAgreement extends Object
参与建立一个共享的秘密密钥的密钥生成器创建(KeyPairGenerator
或KeyGenerator
),一个KeyFactory
,或由于密钥协商协议的一个中间阶段。
每个记者在密钥交换,doPhase
需要叫。例如,如果此密钥交换与另一方,doPhase
需要调用一次,将true
的lastPhase
旗。如果这个密钥交换与其他两方,doPhase
需要调用两次,第一次设置lastPhase
旗false
,第二时间设置为true
。有可能有任何数量的参与密钥交换的缔约方。
java平台的每种实现都要求支持以下标准KeyAgreement
算法:
KeyGenerator
,
SecretKey
Modifier | Constructor and Description |
---|---|
protected |
KeyAgreement(KeyAgreementSpi keyAgreeSpi, Provider provider, String algorithm)
创建一个密钥协商的对象。
|
Modifier and Type | Method and Description |
---|---|
Key |
doPhase(Key key, boolean lastPhase)
执行本密钥协议的下一阶段,该密钥协议的下一阶段是从该密钥协议中的另一方接收的给定密钥中执行的。
|
byte[] |
generateSecret()
生成共享密钥,并将其返回到一个新的缓冲区中。
|
int |
generateSecret(byte[] sharedSecret, int offset)
生成共享密钥,并将其写入缓冲区,
sharedSecret ,在
offset 包容开始。
|
SecretKey |
generateSecret(String algorithm)
创建共享的秘密,并将其作为指定的算法
SecretKey 对象。
|
String |
getAlgorithm()
返回该对象的算法名称
KeyAgreement 。
|
static KeyAgreement |
getInstance(String algorithm)
返回一个
KeyAgreement 对象实现指定的密钥协议算法。
|
static KeyAgreement |
getInstance(String algorithm, Provider provider)
返回一个
KeyAgreement 对象实现指定的密钥协议算法。
|
static KeyAgreement |
getInstance(String algorithm, String provider)
返回一个实现指定密钥协议算法
KeyAgreement 对象。
|
Provider |
getProvider()
返回该对象的
KeyAgreement 提供者。
|
void |
init(Key key)
初始化密钥协商与给定的关键,这是需要包含所有的算法参数的关键协议要求。
|
void |
init(Key key, AlgorithmParameterSpec params)
初始化密钥协商的密钥和算法参数的设置。
|
void |
init(Key key, AlgorithmParameterSpec params, SecureRandom random)
初始化密钥协商与给定的键,设置算法参数,并随机源。
|
void |
init(Key key, SecureRandom random)
初始化密钥协商的密钥和随机源。
|
protected KeyAgreement(KeyAgreementSpi keyAgreeSpi, Provider provider, String algorithm)
keyAgreeSpi
-代表
provider
-供应商
algorithm
-算法
public final String getAlgorithm()
KeyAgreement
。
这是相同的名字,是在一个KeyAgreement
创建这个对象调用指定getInstance
。
KeyAgreement
对象的算法名称。
public static final KeyAgreement getInstance(String algorithm) throws NoSuchAlgorithmException
KeyAgreement
对象。
该方法通过注册安全提供商列表,从最开始的首选供应商。一个新的密钥协商对象封装keyagreementspi实施支持指定算法的第一供应商返回。
注意,注册商的列表可以通过Security.getProviders()
检索方法。
algorithm
-请求的密钥协议算法的标准名称。看到有关标准算法名称信息在
Java Cryptography Architecture Standard Algorithm Name Documentation的密钥协商部分。
KeyAgreement
对象。
NullPointerException
-如果指定的算法是无效的。
NoSuchAlgorithmException
-如果没有提供程序支持一个指定的算法keyagreementspi实施。
Provider
public static final KeyAgreement getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException
KeyAgreement
对象实现指定的密钥协议算法。
一个新的密钥协商对象封装keyagreementspi实现从指定的提供程序返回。指定的提供程序必须在安全提供程序列表中注册。
注意,注册商的列表可以通过Security.getProviders()
检索方法。
algorithm
-请求的密钥协议算法的标准名称。看到有关标准算法名称信息在
Java Cryptography Architecture Standard Algorithm Name Documentation的密钥协商部分。
provider
-提供者的名称。
KeyAgreement
对象。
NullPointerException
-如果指定的算法是无效的。
NoSuchAlgorithmException
-如果一个指定的算法keyagreementspi执行不可从指定的供应商。
NoSuchProviderException
-如果指定的供应商不在安全提供商注册名单。
IllegalArgumentException
-如果
provider
是null或空。
Provider
public static final KeyAgreement getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException
KeyAgreement
对象。
一个新的密钥协商对象封装keyagreementspi实现从指定的提供程序对象返回。请注意,指定的提供程序对象不必在提供者列表中注册。
algorithm
-请求的密钥协议算法的标准名称。看到有关标准算法名称信息在
Java Cryptography Architecture Standard Algorithm Name Documentation的密钥协商部分。
provider
-供应商。
KeyAgreement
对象。
NullPointerException
-如果指定的算法是无效的。
NoSuchAlgorithmException
-如果一个指定的算法keyagreementspi执行不可从指定的提供程序对象。
IllegalArgumentException
-如果
provider
是空的。
Provider
public final Provider getProvider()
KeyAgreement
提供者。
KeyAgreement
对象的提供者
public final void init(Key key) throws InvalidKeyException
如果这个密钥需要任意字节,这会让他们使用SecureRandom
执行优先级最高的供应商作为随机源。(如果没有安装供应商提供的供应,实现一个系统提供的随机源将被使用。)
key
-党的私人信息。例如,在Diffie-Hellman密钥交换协议的情况下,这将是党自身的Diffie-Hellman密钥。
InvalidKeyException
-如果它的键是不适合这个关键协议,例如,是错误的类型或具有不兼容的算法类型。
public final void init(Key key, SecureRandom random) throws InvalidKeyException
如果密钥协议算法需要随机字节,它会从随机给定的源,random
。然而,如果底层算法的实现不需要任何随机字节,random
被忽略。
key
-党的私人信息。例如,在Diffie-Hellman密钥交换协议的情况下,这将是党自身的Diffie-Hellman密钥。
random
-随机源
InvalidKeyException
-如果它的键是不适合这个关键协议,例如,是错误的类型或具有不兼容的算法类型。
public final void init(Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException
如果这个密钥需要任意字节,这会让他们使用SecureRandom
执行优先级最高的供应商作为随机源。(如果没有安装供应商提供的供应,实现一个系统提供的随机源将被使用。)
key
-党的私人信息。例如,在Diffie-Hellman密钥交换协议的情况下,这将是党自身的Diffie-Hellman密钥。
params
的关键协议参数
InvalidKeyException
-如果它的键是不适合这个关键协议,例如,是错误的类型或具有不兼容的算法类型。
InvalidAlgorithmParameterException
如果给定参数的密钥协商是不合适的。
public final void init(Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException
key
-党的私人信息。例如,在Diffie-Hellman密钥交换协议的情况下,这将是党自身的Diffie-Hellman密钥。
params
的关键协议参数
random
-随机源
InvalidKeyException
-如果它的键是不适合这个关键协议,例如,是错误的类型或具有不兼容的算法类型。
InvalidAlgorithmParameterException
如果给定参数的密钥协商是不合适的。
public final Key doPhase(Key key, boolean lastPhase) throws InvalidKeyException, IllegalStateException
key
-这一阶段的关键。例如,在Diffie-Hellman之间2方的情况下,这将是另一方的Diffie-Hellman公钥。
lastPhase
国旗说明这是否是这个关键协议的最后阶段。
InvalidKeyException
-如果给定的关键是不适合这个阶段。
IllegalStateException
-如果这关键协议尚未初始化。
public final byte[] generateSecret() throws IllegalStateException
这个方式将这KeyAgreement
对象,这样可以进一步关键协议。除非这个关键协议初始化的一个init
方法相同的私人信息和算法参数将用于后续的关键协议。
IllegalStateException
-如果这关键协议尚未完成
public final int generateSecret(byte[] sharedSecret, int offset) throws IllegalStateException, ShortBufferException
sharedSecret
,在
offset
包容开始。
如果sharedSecret
缓冲太小装不下的结果,一个ShortBufferException
抛出。在这种情况下,这个调用应该重复一个较大的输出缓冲区。
这个方式将这KeyAgreement
对象,这样可以进一步关键协议。除非这个关键协议初始化的一个init
方法相同的私人信息和算法参数将用于后续的关键协议。
sharedSecret
-共享秘密的缓冲
offset
-抵消
sharedSecret
在共享的秘密将被存储
sharedSecret
字节数
IllegalStateException
-如果这关键协议尚未完成
ShortBufferException
如果给定的输出缓冲区太小,容纳的秘密
public final SecretKey generateSecret(String algorithm) throws IllegalStateException, NoSuchAlgorithmException, InvalidKeyException
SecretKey
对象。
这个方式将这KeyAgreement
对象,这样可以进一步关键协议。除非这个关键协议初始化的一个init
方法相同的私人信息和算法参数将用于后续的关键协议。
algorithm
-请求的密钥算法
IllegalStateException
-如果这关键协议尚未完成
NoSuchAlgorithmException
-如果指定的密钥算法是不可
InvalidKeyException
如果共享密钥材料不能用于生成一个密钥指定的算法(例如,关键材料太短)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.