Class CipherSpi


  • public class CipherSpi
    extends javax.crypto.CipherSpi
    JCA Cipher for SM9 public-key encryption (GM/T 0044.4).

    Encrypt with the recipient's public key, formed from the published master public key and the recipient's identity via SM9EncMasterPublicKey.getUserPublicKey(byte[]) (the same recipient key the SM9-KEM encapsulates to); decrypt with the recipient's private key. The ciphertext is a DER SM9Cipher whose enType records the data-encapsulation mode, so decryption selects the mode automatically. The default encryption mode is SM4/ECB/PKCS#7 (enType = 1); call setMode("XOR") for the KDF stream mode.

    The ciphertext is the GM/T 0080-2020 SM9Cipher structure (see SM9Cipher).

    • Constructor Summary

      Constructors 
      Constructor Description
      CipherSpi()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected byte[] engineDoFinal​(byte[] input, int inputOffset, int inputLen)  
      protected int engineDoFinal​(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)  
      protected int engineGetBlockSize()  
      protected byte[] engineGetIV()  
      protected int engineGetOutputSize​(int inputLen)  
      protected java.security.AlgorithmParameters engineGetParameters()  
      protected void engineInit​(int opmode, java.security.Key key, java.security.AlgorithmParameters params, java.security.SecureRandom random)  
      protected void engineInit​(int opmode, java.security.Key key, java.security.SecureRandom random)  
      protected void engineInit​(int opmode, java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random)  
      protected void engineSetMode​(java.lang.String modeName)  
      protected void engineSetPadding​(java.lang.String padding)  
      protected byte[] engineUpdate​(byte[] input, int inputOffset, int inputLen)  
      protected int engineUpdate​(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)  
      • Methods inherited from class javax.crypto.CipherSpi

        engineDoFinal, engineGetKeySize, engineUnwrap, engineUpdate, engineUpdateAAD, engineUpdateAAD, engineWrap
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CipherSpi

        public CipherSpi()
    • Method Detail

      • engineSetMode

        protected void engineSetMode​(java.lang.String modeName)
                              throws java.security.NoSuchAlgorithmException
        Specified by:
        engineSetMode in class javax.crypto.CipherSpi
        Throws:
        java.security.NoSuchAlgorithmException
      • engineSetPadding

        protected void engineSetPadding​(java.lang.String padding)
                                 throws javax.crypto.NoSuchPaddingException
        Specified by:
        engineSetPadding in class javax.crypto.CipherSpi
        Throws:
        javax.crypto.NoSuchPaddingException
      • engineGetBlockSize

        protected int engineGetBlockSize()
        Specified by:
        engineGetBlockSize in class javax.crypto.CipherSpi
      • engineGetOutputSize

        protected int engineGetOutputSize​(int inputLen)
        Specified by:
        engineGetOutputSize in class javax.crypto.CipherSpi
      • engineGetIV

        protected byte[] engineGetIV()
        Specified by:
        engineGetIV in class javax.crypto.CipherSpi
      • engineGetParameters

        protected java.security.AlgorithmParameters engineGetParameters()
        Specified by:
        engineGetParameters in class javax.crypto.CipherSpi
      • engineInit

        protected void engineInit​(int opmode,
                                  java.security.Key key,
                                  java.security.SecureRandom random)
                           throws java.security.InvalidKeyException
        Specified by:
        engineInit in class javax.crypto.CipherSpi
        Throws:
        java.security.InvalidKeyException
      • engineInit

        protected void engineInit​(int opmode,
                                  java.security.Key key,
                                  java.security.spec.AlgorithmParameterSpec params,
                                  java.security.SecureRandom random)
                           throws java.security.InvalidKeyException,
                                  java.security.InvalidAlgorithmParameterException
        Specified by:
        engineInit in class javax.crypto.CipherSpi
        Throws:
        java.security.InvalidKeyException
        java.security.InvalidAlgorithmParameterException
      • engineInit

        protected void engineInit​(int opmode,
                                  java.security.Key key,
                                  java.security.AlgorithmParameters params,
                                  java.security.SecureRandom random)
                           throws java.security.InvalidKeyException,
                                  java.security.InvalidAlgorithmParameterException
        Specified by:
        engineInit in class javax.crypto.CipherSpi
        Throws:
        java.security.InvalidKeyException
        java.security.InvalidAlgorithmParameterException
      • engineUpdate

        protected byte[] engineUpdate​(byte[] input,
                                      int inputOffset,
                                      int inputLen)
        Specified by:
        engineUpdate in class javax.crypto.CipherSpi
      • engineUpdate

        protected int engineUpdate​(byte[] input,
                                   int inputOffset,
                                   int inputLen,
                                   byte[] output,
                                   int outputOffset)
        Specified by:
        engineUpdate in class javax.crypto.CipherSpi
      • engineDoFinal

        protected byte[] engineDoFinal​(byte[] input,
                                       int inputOffset,
                                       int inputLen)
                                throws javax.crypto.IllegalBlockSizeException,
                                       javax.crypto.BadPaddingException
        Specified by:
        engineDoFinal in class javax.crypto.CipherSpi
        Throws:
        javax.crypto.IllegalBlockSizeException
        javax.crypto.BadPaddingException
      • engineDoFinal

        protected int engineDoFinal​(byte[] input,
                                    int inputOffset,
                                    int inputLen,
                                    byte[] output,
                                    int outputOffset)
                             throws javax.crypto.ShortBufferException,
                                    javax.crypto.IllegalBlockSizeException,
                                    javax.crypto.BadPaddingException
        Specified by:
        engineDoFinal in class javax.crypto.CipherSpi
        Throws:
        javax.crypto.ShortBufferException
        javax.crypto.IllegalBlockSizeException
        javax.crypto.BadPaddingException