Example #1
0
    def download_file(self, document_hash, storing_file_name, encrypted=False):
        if encrypted:
            reg_status = self.register_user_status()
            private_key_hex = str(reg_status['file_encryption_key'])
            private_key_wif = base58.base58_check_encode(0x80, private_key_hex.decode("hex"))
            private_key = CBitcoinSecret(private_key_wif)
            public_key = private_key.pub

        cookies = self.authenticate()
        if cookies is not None:
            download_response = requests.get(self.notary_server.get_upload_url(self.address, document_hash),
                                             cookies=cookies, allow_redirects=True, verify=False)
            if download_response.status_code == 200:
                # Need to add error handling
                ultimate_file_name = str(storing_file_name)
                if encrypted:
                    ultimate_file_name = storing_file_name+".download_encrypted"
                with open(ultimate_file_name, 'wb') as f:
                    for chunk in download_response.iter_content(chunk_size=1024):
                        if chunk:  # filter out keep-alive new chunks
                            f.write(chunk)
                if encrypted:
                    file_stream_encrypt.decrypt_file(storing_file_name+".download_encrypted",  storing_file_name, private_key_wif)
                return storing_file_name
        return None
Example #2
0
    def download_file_decrypted(self, document_hash, storing_file_name):
        """
        uploads a file to server
        Parameters
        ----------
        document_hash : hash of file.
        storing_file_name : file name to write to.

        Returns
        -------
         storing_file_name

        """

        try:
            file_encryption_wallet = self.get_file_encryption_wallet()
            cookies = self.authenticate()
        except NotaryException as e:
            raise NotaryException(e.error_code, e.message)

        try:
            download_response = requests.get(
                self.notary_server.get_document_url(self.address, document_hash),
                cookies=cookies,
                allow_redirects=True,
                verify=False,
            )
            if download_response.status_code != 200:
                raise NotaryException(download_response.status_code, "Problem downloading file!")
                # Need to add error handling
            ultimate_file_name = str(storing_file_name)
            with open(ultimate_file_name + ".decrypted", "wb") as f:
                for chunk in download_response.iter_content(chunk_size=1024):
                    if chunk:  # filter out keep-alive new chunks
                        f.write(chunk)

            file_stream_encrypt.decrypt_file(
                ultimate_file_name + ".decrypted", storing_file_name, file_encryption_wallet.get_private_key_wif()
            )
            return storing_file_name
        except requests.ConnectionError as e:
            raise NotaryException(-1, e.message)
        except NotaryException as ne:
            raise NotaryException(ne.error_code, ne.message)
Example #3
0
import file_stream_encrypt
import wallet
from bitcoinlib.core.key import CPubKey
import requests

requests.packages.urllib3.disable_warnings()

file_name = "/Users/tssbi08/Downloads/jdk-8u65-macosx-x64.dmg"
encrypted_file = "/Users/tssbi08/Downloads/encrypt_jdk-8u65-macosx-x64.dmg"
decrypted_file = "/Users/tssbi08/Downloads/decrypt-8u65-macosx-x64.dmg"

wallet = wallet.PlainWallet()
public_key = CPubKey(wallet.get_public_key_hex().decode("hex"))


file_stream_encrypt.encrypt_file(file_name,encrypted_file,public_key)
file_stream_encrypt.decrypt_file(encrypted_file,decrypted_file,wallet.get_private_key_wif())