(self, key)
Will set the crypting key for this object. Either 16 or 24 bytes long.
Will set the crypting key for this object. Either 16 or 24 bytes long.
Will set the crypting key for this object . Either 16 or 24 bytes long .
def setKey(self, key):
        """Will set the crypting key for this object. Either 16 or 24 bytes long."""
        self.key_size = 24  # Use DES-EDE3 mode
        if len(key) != self.key_size:
            if len(key) == 16: # Use DES-EDE2 mode
                self.key_size = 16
            else:
                raise ValueError("Invalid triple DES key size. Key must be either 16 or 24 bytes long")
        if self.getMode() == CBC:
            if not self.getIV():
                # Use the first 8 bytes of the key
                self._iv = key[:self.block_size]
            if len(self.getIV()) != self.block_size:
                raise ValueError("Invalid IV, must be 8 bytes in length")
        self.__key1 = des(key[:8], self._mode, self._iv,
                  self._padding, self._padmode)
        self.__key2 = des(key[8:16], self._mode, self._iv,
                  self._padding, self._padmode)
        if self.key_size == 16:
            self.__key3 = self.__key1
        else:
            self.__key3 = des(key[16:], self._mode, self._iv,
                      self._padding, self._padmode)
        _baseDes.setKey(self, key)
def setKey ( self , key ) : self . key_size = 24 # Use DES-EDE3 mode if len ( key ) != self . key_size : if len ( key ) == 16 : # Use DES-EDE2 mode self . key_size = 16 else : raise ValueError ( "Invalid triple DES key size. Key must be either 16 or 24 bytes long" ) if self . getMode ( ) == CBC : if not self . getIV ( ) : # Use the first 8 bytes of the key self . _iv = key [ : self . block_size ] if len ( self . getIV ( ) ) != self . block_size : raise ValueError ( "Invalid IV, must be 8 bytes in length" ) self . __key1 = des ( key [ : 8 ] , self . _mode , self . _iv , self . _padding , self . _padmode ) self . __key2 = des ( key [ 8 : 16 ] , self . _mode , self . _iv , self . _padding , self . _padmode ) if self . key_size == 16 : self . __key3 = self . __key1 else : self . __key3 = des ( key [ 16 : ] , self . _mode , self . _iv , self . _padding , self . _padmode ) _baseDes . setKey ( self , key )