Exemplo n.º 1
0
def test_padding():
    for size in range(8, 17):
        for str_len in range(0, 12):
            s = ''.join(
                [random.choice(string.printable) for _ in range(str_len)])
            padded = pad(s, size=size)
            assert len(padded) % size == 0
            unpadded = unpad(padded)
            assert unpadded == s
Exemplo n.º 2
0
 def _decrypt(self, stream):
     super(KDB3File, self)._decrypt(stream)
     
     data = aes_cbc_decrypt(stream.read(), self.master_key, 
         self.header.EncryptionIV)
     data = unpad(data)
     
     if self.header.ContentHash == sha256(data):
         # put data in bytes io
         self.in_buffer = io.BytesIO(data)
         # set successful decryption flag
         self.opened = True
     else:
         raise IOError('Master key invalid.')
Exemplo n.º 3
0
    def _decrypt(self, stream):
        super(KDB3File, self)._decrypt(stream)

        data = aes_cbc_decrypt(stream.read(), self.master_key,
                               self.header.EncryptionIV)
        data = unpad(data)

        if self.header.ContentHash == sha256(data):
            # put data in bytes io
            self.in_buffer = io.BytesIO(data)
            # set successful decryption flag
            self.opened = True
        else:
            raise IOError('Master key invalid.')
Exemplo n.º 4
0
 def pay_check():
     if not USER.get('login', None):
         print(colored("Unregistered", "red"))
         input()
         return
     load_goods()
     print(cow.Moose().milk("Order"))
     print()
     token = input("Enter payment token: > ")
     _, good = decode_aes(token)
     name, cost, visible = unpad(good.decode())[1:-1].split(",")
     if int(cost) > int(USER['money']):
         print(colored("Not enough money", "red"))
     else:
         print(
             colored(
                 "Successfully bought {} ({})".format(
                     name, GOODS[name]["description"]), "green"))
         USER['money'] -= int(cost)
     input()
     return
Exemplo n.º 5
0
    def _decrypt(self, stream):
        """
        Build the master key from header settings and key-hash list.
        
        Start reading from `stream` after the header and decrypt all the data.
        Remove padding as needed and feed into hashed block reader, set as
        in-buffer.
        """
        super(KDB4File, self)._decrypt(stream)

        data = aes_cbc_decrypt(stream.read(), self.master_key,
                               self.header.EncryptionIV)
        data = unpad(data)

        length = len(self.header.StreamStartBytes)
        if self.header.StreamStartBytes == data[:length]:
            # skip startbytes and wrap data in a hashed block io
            self.in_buffer = HashedBlockIO(bytes=data[length:])
            # set successful decryption flag
            self.opened = True
        else:
            raise IOError('Master key invalid.')
Exemplo n.º 6
0
    def _decrypt(self, stream):
        """
        Build the master key from header settings and key-hash list.

        Start reading from `stream` after the header and decrypt all the data.
        Remove padding as needed and feed into hashed block reader, set as
        in-buffer.
        """
        super(KDB4File, self)._decrypt(stream)

        data = aes_cbc_decrypt(stream.read(), self.master_key,
            self.header.EncryptionIV)
        data = unpad(data)

        length = len(self.header.StreamStartBytes)
        if self.header.StreamStartBytes == data[:length]:
            # skip startbytes and wrap data in a hashed block io
            self.in_buffer = HashedBlockIO(bytes=data[length:])
            # set successful decryption flag
            self.opened = True
        else:
            raise IOError('Master key invalid.')