@@ -649,6 +649,142 @@ def destroy(self, uid=None):
649649            message  =  result .result_message .value 
650650            raise  exceptions .KmipOperationFailure (status , reason , message )
651651
652+     def  encrypt (self , data , uid = None , cryptographic_parameters = None ,
653+                 iv_counter_nonce = None ):
654+         """ 
655+         Encrypt data using the specified encryption key and parameters. 
656+ 
657+         Args: 
658+             data (bytes): The bytes to encrypt. Required. 
659+             uid (string): The unique ID of the encryption key to use. 
660+                 Optional, defaults to None. 
661+             cryptographic_parameters (dict): A dictionary containing various 
662+                 cryptographic settings to be used for the encryption. 
663+                 Optional, defaults to None. 
664+             iv_counter_nonce (bytes): The bytes to use for the IV/counter/ 
665+                 nonce, if needed by the encryption algorithm and/or cipher 
666+                 mode. Optional, defaults to None. 
667+ 
668+         Returns: 
669+             bytes: The encrypted data. 
670+             bytes: The IV/counter/nonce used with the encryption algorithm, 
671+                 only if it was autogenerated by the server. 
672+ 
673+         Raises: 
674+             ClientConnectionNotOpen: if the client connection is unusable 
675+             KmipOperationFailure: if the operation result is a failure 
676+             TypeError: if the input arguments are invalid 
677+ 
678+         Notes: 
679+             The cryptographic_parameters argument is a dictionary that can 
680+             contain the following key/value pairs: 
681+ 
682+             Keys                          | Value 
683+             ------------------------------|----------------------------------- 
684+             'block_cipher_mode'           | A BlockCipherMode enumeration 
685+                                           | indicating the cipher mode to use 
686+                                           | with the encryption algorithm. 
687+             'padding_method'              | A PaddingMethod enumeration 
688+                                           | indicating which padding method to 
689+                                           | use with the encryption algorithm. 
690+             'hashing_algorithm'           | A HashingAlgorithm enumeration 
691+                                           | indicating which hashing algorithm 
692+                                           | to use. 
693+             'key_role_type'               | A KeyRoleType enumeration 
694+                                           | indicating the intended use of the 
695+                                           | associated cryptographic key. 
696+             'digital_signature_algorithm' | A DigitalSignatureAlgorithm 
697+                                           | enumeration indicating which 
698+                                           | digital signature algorithm to 
699+                                           | use. 
700+             'cryptographic_algorithm'     | A CryptographicAlgorithm 
701+                                           | enumeration indicating which 
702+                                           | encryption algorithm to use. 
703+             'random_iv'                   | A boolean indicating whether the 
704+                                           | server should autogenerate an IV. 
705+             'iv_length'                   | An integer representing the length 
706+                                           | of the initialization vector (IV) 
707+                                           | in bits. 
708+             'tag_length'                  | An integer representing the length 
709+                                           | of the authenticator tag in bytes. 
710+             'fixed_field_length'          | An integer representing the length 
711+                                           | of the fixed field portion of the 
712+                                           | IV in bits. 
713+             'invocation_field_length'     | An integer representing the length 
714+                                           | of the invocation field portion of 
715+                                           | the IV in bits. 
716+             'counter_length'              | An integer representing the length 
717+                                           | of the coutner portion of the IV 
718+                                           | in bits. 
719+             'initial_counter_value'       | An integer representing the 
720+                                           | starting counter value for CTR 
721+                                           | mode (typically 1). 
722+         """ 
723+         # Check input 
724+         if  not  isinstance (data , six .binary_type ):
725+             raise  TypeError ("data must be bytes" )
726+         if  uid  is  not   None :
727+             if  not  isinstance (uid , six .string_types ):
728+                 raise  TypeError ("uid must be a string" )
729+         if  cryptographic_parameters  is  not   None :
730+             if  not  isinstance (cryptographic_parameters , dict ):
731+                 raise  TypeError ("cryptographic_parameters must be a dict" )
732+         if  iv_counter_nonce  is  not   None :
733+             if  not  isinstance (iv_counter_nonce , six .binary_type ):
734+                 raise  TypeError ("iv_counter_nonce must be bytes" )
735+ 
736+         # Verify that operations can be given at this time 
737+         if  not  self ._is_open :
738+             raise  exceptions .ClientConnectionNotOpen ()
739+ 
740+         cryptographic_parameters  =  CryptographicParameters (
741+             block_cipher_mode = cryptographic_parameters .get (
742+                 'block_cipher_mode' 
743+             ),
744+             padding_method = cryptographic_parameters .get ('padding_method' ),
745+             hashing_algorithm = cryptographic_parameters .get (
746+                 'hashing_algorithm' 
747+             ),
748+             key_role_type = cryptographic_parameters .get ('key_role_type' ),
749+             digital_signature_algorithm = cryptographic_parameters .get (
750+                 'digital_signature_algorithm' 
751+             ),
752+             cryptographic_algorithm = cryptographic_parameters .get (
753+                 'cryptographic_algorithm' 
754+             ),
755+             random_iv = cryptographic_parameters .get ('random_iv' ),
756+             iv_length = cryptographic_parameters .get ('iv_length' ),
757+             tag_length = cryptographic_parameters .get ('tag_length' ),
758+             fixed_field_length = cryptographic_parameters .get (
759+                 'fixed_field_length' 
760+             ),
761+             invocation_field_length = cryptographic_parameters .get (
762+                 'invocation_field_length' 
763+             ),
764+             counter_length = cryptographic_parameters .get ('counter_length' ),
765+             initial_counter_value = cryptographic_parameters .get (
766+                 'initial_counter_value' 
767+             )
768+         )
769+ 
770+         # Encrypt the provided data and handle the results 
771+         result  =  self .proxy .encrypt (
772+             data ,
773+             uid ,
774+             cryptographic_parameters ,
775+             iv_counter_nonce 
776+         )
777+ 
778+         status  =  result .get ('result_status' )
779+         if  status  ==  enums .ResultStatus .SUCCESS :
780+             return  result .get ('data' ), result .get ('iv_counter_nonce' )
781+         else :
782+             raise  exceptions .KmipOperationFailure (
783+                 status ,
784+                 result .get ('result_reason' ),
785+                 result .get ('result_message' )
786+             )
787+ 
652788    def  mac (self , data , uid = None , algorithm = None ):
653789        """ 
654790        Get the message authentication code for data. 
0 commit comments