def _encrypt(key, plaintext): padsize = 16 - (len(key) % 16) padded_key = key + ("." * padsize) # Pad with "\r" for string shorter than 66 (I don't know why) if len(plaintext) < 66: padsize = 66 - len(plaintext) plaintext += padsize * "\r" cipher = aes.encryptData(padded_key, plaintext) cipher_text = base64.encodestring(cipher) return cipher_text
if method == 'generate': seed = btc.sha256(os.urandom(64))[:32] words = old_mnemonic.mn_encode(seed) print 'Write down this wallet recovery seed\n\n' + ' '.join(words) + '\n' elif method == 'recover': words = raw_input('Input 12 word recovery seed: ') words = words.split(' ') seed = old_mnemonic.mn_decode(words) print seed password = getpass.getpass('Enter wallet encryption passphrase: ') password2 = getpass.getpass('Reenter wallet encryption passphrase: ') if password != password2: print 'ERROR. Passwords did not match' sys.exit(0) password_key = btc.bin_dbl_sha256(password) encrypted_seed = slowaes.encryptData(password_key, seed.decode('hex')) timestamp = datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S") walletfile = json.dumps({'creator': 'joinmarket project', 'creation_time': timestamp, 'encrypted_seed': encrypted_seed.encode('hex'), 'network': common.get_network()}) walletname = raw_input('Input wallet file name (default: wallet.json): ') if len(walletname) == 0: walletname = 'wallet.json' fd = open(os.path.join('wallets', walletname), 'w') fd.write(walletfile) fd.close() print 'saved to ' + walletname elif method == 'showseed': hexseed = wallet.seed print 'hexseed = ' + hexseed words = old_mnemonic.mn_encode(hexseed) print 'Wallet recovery seed\n\n' + ' '.join(words) + '\n'
print 'total balance = %.8fbtc' % (total_balance/1e8) elif method == 'generate' or method == 'recover': if method == 'generate': seed = btc.sha256(os.urandom(64))[:32] words = old_mnemonic.mn_encode(seed) print 'Write down this wallet recovery seed\n\n' + ' '.join(words) + '\n' elif method == 'recover': words = raw_input('Input 12 word recovery seed: ') words = words.split() #default for split is 1 or more whitespace chars if len(words) != 12: print 'ERROR: Recovery seed phrase must be exactly 12 words.' sys.exit(0) seed = old_mnemonic.mn_decode(words) print seed password_key = btc.bin_dbl_sha256(password) encrypted_seed = slowaes.encryptData(password_key, seed.decode('hex')) timestamp = datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S") walletfile = json.dumps({'creator': 'joinmarket project', 'creation_time': timestamp, 'encrypted_seed': encrypted_seed.encode('hex'), 'network': common.get_network()}) fd = open(os.path.join('wallets', walletname), 'w') fd.write(walletfile) fd.close() print 'saved to ' + walletname if password == '': print 'without password' elif method == 'showseed': hexseed = wallet.seed print 'hexseed = ' + hexseed words = old_mnemonic.mn_encode(hexseed) print 'Wallet recovery seed\n\n' + ' '.join(words) + '\n' elif method == 'importprivkey':
words) + '\n' elif method == 'recover': words = raw_input('Input 12 word recovery seed: ') words = words.split() #default for split is 1 or more whitespace chars if len(words) != 12: print 'ERROR: Recovery seed phrase must be exactly 12 words.' sys.exit(0) seed = old_mnemonic.mn_decode(words) print seed password = getpass.getpass('Enter wallet encryption passphrase: ') password2 = getpass.getpass('Reenter wallet encryption passphrase: ') if password != password2: print 'ERROR. Passwords did not match' sys.exit(0) password_key = btc.bin_dbl_sha256(password) encrypted_seed = slowaes.encryptData(password_key, seed.decode('hex')) timestamp = datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S") walletfile = json.dumps({ 'creator': 'joinmarket project', 'creation_time': timestamp, 'encrypted_seed': encrypted_seed.encode('hex'), 'network': common.get_network() }) walletname = raw_input('Input wallet file name (default: wallet.json): ') if len(walletname) == 0: walletname = 'wallet.json' fd = open(os.path.join('wallets', walletname), 'w') fd.write(walletfile) fd.close() print 'saved to ' + walletname elif method == 'showseed':
seed = btc.sha256(os.urandom(64))[:32] words = old_mnemonic.mn_encode(seed) print 'Write down this wallet recovery seed\n\n' + ' '.join( words) + '\n' elif method == 'recover': words = raw_input('Input 12 word recovery seed: ') words = words.split(' ') seed = old_mnemonic.mn_decode(words) print seed password = getpass.getpass('Enter wallet encryption passphrase: ') password2 = getpass.getpass('Reenter wallet encryption passphrase: ') if password != password2: print 'ERROR. Passwords did not match' sys.exit(0) password_key = btc.bin_dbl_sha256(password) encrypted_seed = slowaes.encryptData(password_key, seed.decode('hex')) timestamp = datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S") walletfile = json.dumps({ 'creator': 'joinmarket project', 'creation_time': timestamp, 'encrypted_seed': encrypted_seed.encode('hex'), 'network': common.get_network() }) walletname = raw_input('Input wallet file name (default: wallet.json): ') if len(walletname) == 0: walletname = 'wallet.json' fd = open(os.path.join('wallets', walletname), 'w') fd.write(walletfile) fd.close() print 'saved to ' + walletname elif method == 'showseed':
def encrypt(self, raw): return slowaes.encryptData(self.key, raw)