public abstract class KeyAgreementSpi extends Object
KeyAgreement类。 
       该类中的所有抽象方法必须由希望提供特定密钥协商算法的实现的每个加密服务提供商来实现。 
        密钥生成器( KeyPairGenerator或KeyGenerator ), KeyFactory中的一个或由密钥协商协议( engineDoPhase )的中间阶段的结果创建共享秘密所涉及的密钥。 
 对于密钥交换中的engineDoPhase需要调用engineDoPhase 。 例如,如果与另一方进行密钥交换, engineDoPhase需要被调用一次,其中lastPhase标志设置为true 。 如果密钥交换是与另外两方, engineDoPhase需要被叫两次,首次将lastPhase标志设置为false ,第二次设置为true 。 密钥交换中可能存在任何数量的参与方。 
KeyGenerator , SecretKey 
       | Constructor and Description | 
|---|
| KeyAgreementSpi() | 
| Modifier and Type | Method and Description | 
|---|---|
| protected abstract Key | engineDoPhase(Key key, boolean lastPhase)
              执行该关键协议的下一阶段,其中包含从本协议涉及的其中一方收到的给定密钥。 
             | 
| protected abstract byte[] | engineGenerateSecret()
              生成共享密钥并将其返回到新的缓冲区。 
             | 
| protected abstract int | engineGenerateSecret(byte[] sharedSecret, int offset)
              生成共享密钥,并将其放入缓冲区 
              sharedSecret,从offset开始。 | 
| protected abstract SecretKey | engineGenerateSecret(String algorithm)
              创建共享密钥,并将其作为请求的算法类型的秘密密钥对象返回。 
             | 
| protected abstract void | engineInit(Key key, AlgorithmParameterSpec params, SecureRandom random)
              使用给定的密钥,算法参数集合和随机源初始化此密钥协议。 
             | 
| protected abstract void | engineInit(Key key, SecureRandom random)
              用给定的密钥和随机源初始化这个密钥协商。 
             | 
protected abstract void engineInit(Key key, SecureRandom random) throws InvalidKeyException
 如果密钥协商算法需要随机字节,它得到他们的随机性,给定源random 。 但是,如果底层算法实现不需要任何随机字节,则忽略random 。 
key - 党的私人信息。 
            例如,在Diffie-Hellman密钥协议的情况下,这将是该方自己的Diffie-Hellman私钥。 
           random - 
            random的来源 
           InvalidKeyException - 如果给定的密钥对于该密钥协议是不合适的,例如,是错误的类型或具有不兼容的算法类型。 
           protected abstract void engineInit(Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException
key - 党的私人信息。 
            例如,在Diffie-Hellman密钥协议的情况下,这将是该方自己的Diffie-Hellman私钥。 
           params - 关键协议参数 
           random - 
            random的来源 
           InvalidKeyException - 如果给定的密钥对于该密钥协议是不合适的,例如,是错误的类型或具有不兼容的算法类型。 
           InvalidAlgorithmParameterException - 如果给定的参数不适合此密钥协议。 
           protected abstract Key engineDoPhase(Key key, boolean lastPhase) throws InvalidKeyException, IllegalStateException
key - 这个阶段的关键。 
            例如,在双方之间的Diffie-Hellman的情况下,这将是对方的Diffie-Hellman公钥。 
           lastPhase - 表示这是否是此密钥协议的最后一个阶段的标志。 
           InvalidKeyException - 如果给定的关键字不适合此阶段。 
           IllegalStateException - 如果此密钥协议尚未初始化。 
           protected abstract byte[] engineGenerateSecret()
                                        throws IllegalStateException 
           此方法重置此KeyAgreementSpi对象,以便可以重新用于进一步的关键协议。 除非使用engineInit方法重新初始化该密钥协议,否则相同的私有信息和算法参数将用于后续密钥协议。 
IllegalStateException - 如果此关键协议尚未完成 
           protected abstract int engineGenerateSecret(byte[] sharedSecret,
                                            int offset)
                                     throws IllegalStateException,
                                            ShortBufferException 
          sharedSecret (从offset开始)。 
            如果sharedSecret缓冲区太小而不能保存结果,则抛出ShortBufferException 。 在这种情况下,应该使用较大的输出缓冲区来重复此调用。 
 此方法重置此KeyAgreementSpi对象,以便可以重新用于进一步的关键协议。 除非使用engineInit方法之一重新初始化该密钥协议,否则相同的私有信息和算法参数将用于后续密钥协议。 
sharedSecret - 共享密码的缓冲区 
           offset - 
            sharedSecret中的共享密码将被存储的偏移量 
           sharedSecret的字节数 
           IllegalStateException - 如果此关键协议尚未完成 
           ShortBufferException - 如果给定的输出缓冲区太小,不能容纳秘密 
           protected abstract SecretKey engineGenerateSecret(String algorithm) throws IllegalStateException, NoSuchAlgorithmException, InvalidKeyException
 此方法重置此KeyAgreementSpi对象,以便可以重新用于进一步的关键协议。 除非使用engineInit方法之一重新初始化该密钥协议,否则相同的私有信息和算法参数将用于后续密钥协议。 
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.