Class CipherCore


  • public class CipherCore
    extends java.lang.Object
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  CipherCore.CipherType  
    • Constructor Summary

      Constructors 
      Constructor Description
      CipherCore​(com.fortanix.sdkms.v1.model.ObjectType alg, int blkSize, CipherCore.CipherType cipherType)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] doFinal​(byte[] input, int inputOffset, int inputLen)  
      int doFinal​(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)  
      int getBlockSize()  
      com.fortanix.sdkms.v1.model.CryptMode getCryptMode()  
      byte[] getIv()  
      SdkmsCipherKey getKey()  
      java.lang.String getOperation()  
      int getOutputSize​(int inputLen)
      The actual encrypted/decrypted data size can be smaller then the length return by this method
      java.lang.String getPadding()  
      void init​(int opmode, java.security.Key key)  
      void init​(int opmode, java.security.Key key, java.security.AlgorithmParameters params)  
      void init​(int opmode, java.security.Key key, java.security.spec.AlgorithmParameterSpec params)  
      void initMultiCore()  
      protected boolean isPaddingRequired()  
      protected void prepareDoFinal()  
      protected void resetFields()  
      void setBlockSize​(int blockSize)  
      void setCryptMode​(com.fortanix.sdkms.v1.model.CryptMode cryptMode)  
      void setPadding​(java.lang.String padding)  
      void setState​(byte[] state)  
      protected void switchCryptMode()  
      java.security.Key unwrap​(byte[] wrappedKey, java.lang.String wrappedKeyAlgorithm, int wrappedKeyType)
      Decrypt the wrapped key and return JCE key object
      byte[] update​(byte[] input, int inputOffset, int inputLen)
      return encrypted / plain bytes depend upon cipher mode
      int update​(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)
      This method doesn't perform any encryption.
      void updateAAD​(byte[] src, int offset, int len)  
      protected void validateParameters()  
      byte[] wrap​(java.security.Key key)
      Encrypt input key
      • Methods inherited from class java.lang.Object

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

      • CipherCore

        public CipherCore​(com.fortanix.sdkms.v1.model.ObjectType alg,
                          int blkSize,
                          CipherCore.CipherType cipherType)
    • Method Detail

      • init

        public void init​(int opmode,
                         java.security.Key key,
                         java.security.spec.AlgorithmParameterSpec params)
                  throws java.security.InvalidKeyException,
                         java.security.InvalidAlgorithmParameterException
        Parameters:
        opmode -
        key -
        params -
        Throws:
        java.security.InvalidKeyException
        java.security.InvalidAlgorithmParameterException
      • init

        public void init​(int opmode,
                         java.security.Key key)
                  throws java.security.InvalidKeyException
        Parameters:
        opmode - operation mode of this cipher. Possible values are ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE
        key - the secret key
        Throws:
        java.security.InvalidAlgorithmParameterException
        java.security.InvalidKeyException
      • init

        public void init​(int opmode,
                         java.security.Key key,
                         java.security.AlgorithmParameters params)
                  throws java.security.InvalidKeyException,
                         java.security.InvalidAlgorithmParameterException
        Throws:
        java.security.InvalidKeyException
        java.security.InvalidAlgorithmParameterException
      • initMultiCore

        public void initMultiCore()
      • update

        public byte[] update​(byte[] input,
                             int inputOffset,
                             int inputLen)
        return encrypted / plain bytes depend upon cipher mode
      • update

        public int update​(byte[] input,
                          int inputOffset,
                          int inputLen,
                          byte[] output,
                          int outputOffset)
                   throws javax.crypto.ShortBufferException
        This method doesn't perform any encryption. Call doFinal for encryption/decryption operation
        Parameters:
        input -
        inputOffset -
        inputLen -
        output -
        outputOffset -
        Returns:
        zero. As nothing is copied into output
        Throws:
        javax.crypto.ShortBufferException
      • doFinal

        public byte[] doFinal​(byte[] input,
                              int inputOffset,
                              int inputLen)
        Parameters:
        input -
        inputOffset -
        inputLen -
        Returns:
        encrypted/decrypted content
      • doFinal

        public int doFinal​(byte[] input,
                           int inputOffset,
                           int inputLen,
                           byte[] output,
                           int outputOffset)
                    throws javax.crypto.ShortBufferException
        Parameters:
        input -
        inputOffset -
        inputLen -
        output - , cipher/plain text as per operation mode
        outputOffset -
        Returns:
        Throws:
        javax.crypto.ShortBufferException
      • prepareDoFinal

        protected void prepareDoFinal()
      • setCryptMode

        public void setCryptMode​(com.fortanix.sdkms.v1.model.CryptMode cryptMode)
      • setPadding

        public void setPadding​(java.lang.String padding)
      • getOutputSize

        public int getOutputSize​(int inputLen)
        The actual encrypted/decrypted data size can be smaller then the length return by this method
        Parameters:
        inputLen -
        Returns:
        required output buffer size in bytes
      • updateAAD

        public void updateAAD​(byte[] src,
                              int offset,
                              int len)
      • wrap

        public byte[] wrap​(java.security.Key key)
                    throws java.security.InvalidKeyException
        Encrypt input key
        Parameters:
        key - to be wrapped
        Returns:
        wrapped key
        Throws:
        java.security.InvalidKeyException
      • unwrap

        public java.security.Key unwrap​(byte[] wrappedKey,
                                        java.lang.String wrappedKeyAlgorithm,
                                        int wrappedKeyType)
                                 throws java.security.InvalidKeyException
        Decrypt the wrapped key and return JCE key object
        Parameters:
        wrappedKey -
        wrappedKeyAlgorithm -
        wrappedKeyType -
        Returns:
        Key object
        Throws:
        java.security.InvalidKeyException
      • getIv

        public byte[] getIv()
      • getPadding

        public java.lang.String getPadding()
      • getOperation

        public java.lang.String getOperation()
      • getCryptMode

        public com.fortanix.sdkms.v1.model.CryptMode getCryptMode()
      • getBlockSize

        public int getBlockSize()
      • setBlockSize

        public void setBlockSize​(int blockSize)
      • validateParameters

        protected void validateParameters()
      • switchCryptMode

        protected void switchCryptMode()
      • isPaddingRequired

        protected boolean isPaddingRequired()
      • setState

        public void setState​(byte[] state)
      • resetFields

        protected void resetFields()