Exemple #1
0
    def set_key(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('Key must be either 16 or 24 bytes long.')
        if self.get_mode() == CBC:
            if not self.get_iv():
                # Use the first 8 bytes of the key
                self._iv = key[:self.block_size]
            if len(self.get_iv()) != self.block_size:
                raise ValueError('Invalid IV, must be 8 bytes in length')
        self.__key1 = Des1(key[:8], self._mode, self._iv,
                  self._padding, self._padmode)
        self.__key2 = Des1(key[8:16], self._mode, self._iv,
                  self._padding, self._padmode)
        if self.key_size == 16:
            self.__key3 = self.__key1
        else:
            self.__key3 = Des1(key[16:], self._mode, self._iv,
                      self._padding, self._padmode)
        DesBase.set_key(self, key)

        return
Exemple #2
0
    def set_key(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('Key must be either 16 or 24 bytes long.')
        if self.get_mode() == CBC:
            if not self.get_iv():
                # Use the first 8 bytes of the key
                self._iv = key[:self.block_size]
            if len(self.get_iv()) != self.block_size:
                raise ValueError('Invalid IV, must be 8 bytes in length')
        self.__key1 = Des1(key[:8], self._mode, self._iv, self._padding,
                           self._padmode)
        self.__key2 = Des1(key[8:16], self._mode, self._iv, self._padding,
                           self._padmode)
        if self.key_size == 16:
            self.__key3 = self.__key1
        else:
            self.__key3 = Des1(key[16:], self._mode, self._iv, self._padding,
                               self._padmode)
        DesBase.set_key(self, key)

        return
Exemple #3
0
    def set_key(self, key):
        '''
        Will set the crypting key for this object. Must be 8 bytes.
        '''

        DesBase.set_key(self, key)
        self.__create_sub_keys()
        return