Beispiel #1
0
 def unlock(self, password: str):
     """Sets the master password and unlocks the wallet"""
     if not self._locked:
         return
     if not self._infos['encrypted']:
         return
     # decrypt the addresses and keys
     try:
         addresses = []
         for address in self._data['addresses']:
             decoded = json.loads(
                 decrypt(password, b64decode(
                     address.encode('utf-8'))).decode('utf-8'))
             addresses.append(decoded)
         self._addresses = addresses
         self._master_password = password
         self._locked = False
         # Now decode the spend
         decoded = json.loads(
             decrypt(password, b64decode(
                 self._data['spend'].encode('utf-8'))).decode('utf-8'))
         self._infos['spend'] = decoded
     except Exception as e:
         self.log.error(e)
         raise RuntimeWarning("Password does not seem to match")
Beispiel #2
0
def keys_unlock(private_key_encrypted: str) -> tuple:
    password = getpass.getpass()
    encrypted_privkey = private_key_encrypted
    decrypted_privkey = decrypt(password, base64.b64decode(encrypted_privkey))
    key = RSA.importKey(decrypted_privkey)  # be able to sign
    private_key_readable = key.exportKey().decode("utf-8")
    return key, private_key_readable
 def get_der_key(self, wallet_file: str='wallet.der', password: str=''):
     try:
         old = False
         with open(wallet_file, 'r') as f:
             line1 = f.readline()
             if line1.startswith("-----BEGIN RSA PRIVATE KEY-----"):
                 # print(wallet_file, "OLD")
                 old = True
         if old:
             with open(wallet_file, 'r') as f:
                 content = f.read()
                 key = RSA.importKey(content)
                 public_key_readable = key.publickey().exportKey().decode("utf-8")
                 address = sha224(public_key_readable.encode("utf-8")).hexdigest()  # hashed public key
             return {"private_key": content, "public_key": public_key_readable, "address": address, "label": '',
                     'timestamp': int(time())}
         else:
             with open(wallet_file, 'r') as f:
                 content = json.load(f)
                 if password:
                     content['Private Key'] = decrypt(password,b64decode(content['Private Key'])).decode('utf-8')
                 key = RSA.importKey(content['Private Key'])
                 public_key = content['Public Key']
                 private_key = content['Private Key']
                 address = content["Address"]
                 # TODO: check that address matches rebuilded pubkey
                 return {"private_key": private_key, "public_key": public_key, "address": address, "label":'',
                         'timestamp': int(time())}
     except Exception as e:
         exc_type, exc_obj, exc_tb = sys.exc_info()
         fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
         print(exc_type, fname, exc_tb.tb_lineno)
         # encrypted
         return None
Beispiel #4
0
    def get_der_key(self, wallet_file: str = 'wallet.der', password: str = ''):
        try:
            with open(wallet_file, 'r') as f:
                content = json.load(f)
                address = content['Address']  # Warning case change!!!
                if password:
                    content['Private Key'] = decrypt(
                        password,
                        b64decode(content['Private Key'])).decode('utf-8')

                key = RSA.importKey(content['Private Key'])
                public_key = content['Public Key']
                private_key = content['Private Key']
                address = content["Address"]
                # TODO: check that address matches rebuilded pubkey
                return {
                    "private_key": private_key,
                    "public_key": public_key,
                    "address": address,
                    "label": '',
                    'timestamp': int(time())
                }
        except Exception as e:
            self.log.error(e)
            # encrypted
            return None
 def unlock(self, password:str):
     """Sets the master password and unlocks the wallet"""
     if not self._locked:
         return
     if not self._infos['encrypted']:
         return
     # decrypt the addresses and keys
     try:
         addresses = []
         for address in self._data['addresses']:
             decoded = json.loads(decrypt(password, b64decode(address.encode('utf-8'))).decode('utf-8'))
             addresses.append(decoded)
         self._addresses = addresses
         self._master_password = password
         self._locked = False
         # Now decode the spend
         decoded = json.loads(decrypt(password, b64decode(self._data['spend'].encode('utf-8'))).decode('utf-8'))
         self._infos['spend'] = decoded
     except Exception as e:
         exc_type, exc_obj, exc_tb = sys.exc_info()
         fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
         print(exc_type, fname, exc_tb.tb_lineno)
         raise RuntimeWarning("Password does not seem to match")