Class KeyAgreementSpi


  • public class KeyAgreementSpi
    extends BaseAgreementSpi
    JCA adapter for the SM9 key exchange protocol (GM/T 0044.3-2016), registered as KeyAgreement.SM9. The protocol is two-round, so it maps onto the KeyAgreement API's two-phase form:
    1. init with this party's key-exchange user key (from SM9EncMasterPrivateKey.generateExchangeKeyPair(byte[])) and an SM9KeyExchangeSpec giving the role and the agreed key length.
    2. doPhase(peerUserPublicKey, false) - names the peer and returns this party's ephemeral value R, whose Key.getEncoded() is the 64-byte x || y form to send. The ephemeral is generated here, inside the provider, under the master public key carried on this party's own user key, so it cannot be mis-bound to a different master key.
    3. doPhase(peerEphemeral, true) - the peer's R, then generateSecret().
    The peer's user public key is checked to carry the same hid and master public key as this party's own key; the peer's identity is taken from it, so the peer is named exactly once.

    The optional GM/T 0044.3 key-confirmation tags S_A / S_B have no channel in this API and are available from the lightweight SM9KeyExchange only - the same position KeyAgreement.SM2 takes for SM2's confirmation tags.

    • Constructor Detail

      • KeyAgreementSpi

        public KeyAgreementSpi()
    • Method Detail

      • doInitFromKey

        protected void doInitFromKey​(java.security.Key key,
                                     java.security.spec.AlgorithmParameterSpec parameterSpec,
                                     java.security.SecureRandom random)
                              throws java.security.InvalidKeyException,
                                     java.security.InvalidAlgorithmParameterException
        Specified by:
        doInitFromKey in class BaseAgreementSpi
        Throws:
        java.security.InvalidKeyException
        java.security.InvalidAlgorithmParameterException
      • engineDoPhase

        protected java.security.Key engineDoPhase​(java.security.Key key,
                                                  boolean lastPhase)
                                           throws java.security.InvalidKeyException,
                                                  java.lang.IllegalStateException
        Specified by:
        engineDoPhase in class javax.crypto.KeyAgreementSpi
        Throws:
        java.security.InvalidKeyException
        java.lang.IllegalStateException