def decrypt(self, wif): """ Decrypt the content according to BIP38 :param str wif: Encrypted key """ if not self.unlocked(): raise WalletLocked return format(bip38.decrypt(wif, self.masterkey), "wif")
def test_deencrypt(self): self.assertEqual([ format( decrypt( "6PRN5mjUTtud6fUXbJXezfn6oABoSr6GSLjMbrGXRZxSUcxThxsUW8epQi", "TestingOneTwoThree"), "wif"), format( decrypt( "6PRVWUbkzzsbcVac2qwfssoUJAN1Xhrg6bNk8J7Nzm5H7kxEbn2Nh2ZoGg", "TestingOneTwoThree"), "wif"), format( decrypt( "6PRNFFkZc2NZ6dJqFfhRoFNMR9Lnyj7dYGrzdgXXVMXcxoKTePPX1dWByq", "Satoshi"), "wif") ], [ "5HqUkGuo62BfcJU5vNhTXKJRXuUi9QSE6jp8C3uBJ2BVHtB8WSd", "5KN7MzqK5wt2TP1fQCYyHBtDrXdJuXbUzm4A9rKAteGu3Qi5CVR", "5HtasZ6ofTHP6HCwTqTkLDuLQisYPah7aUnSKfC7h4hMUVw2gi5" ])
def decrypt_wif(self, encwif): """ decrypt a wif key """ try: # Try to decode as wif PrivateKey(encwif, prefix=self.prefix) return encwif except (ValueError, AssertionError): pass if self.locked(): raise AssertionError() return format(bip38.decrypt(encwif, self.masterpassword), "wif")