Bitcoin Forum
December 10, 2016, 06:40:33 PM *
News: To be able to use the next phase of the beta forum software, please ensure that your email address is correct/functional.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: wallet email backup script w/embedded encryption  (Read 907 times)
kokjo
Legendary
*
Offline Offline

Activity: 1050

You are WRONG!


View Profile
April 23, 2012, 06:33:20 PM
 #1

Wrote this for a cronjob on my server, it might be useful for you.
Donations goes to 1JpsKmkim7REYq2EWE5aEXG8YN4zJTTX16
Code:
#!/usr/bin/python
import os
import sys
import smtplib
# For guessing MIME type based on file name extension
import mimetypes

from optparse import OptionParser
from email import encoders
from email.message import Message
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
import time
import Crypto.Cipher.AES as AES
import hashlib
import jsonrpc
import random

PASSWORD = "ENCRYPTION PASSWORD"
BITCOIN_USER = ""
BITCOIN_PASS = "BITCOIND PASSWORD"
TO_EMAIL = "someone@some.where"

DECRYPT_SCRIPT = """#!/usr/bin/python
import Crypto.Cipher.AES as AES
import hashlib
DATA = "%s"
CKSUM = "%s"
PASSWORD = raw_input("Password: ")
OUTPUTFILE = raw_input("Output file: ")
KEY = hashlib.sha256(PASSWORD).digest()
CRYPTER = AES.new(KEY, AES.MODE_CFB)

decrypted_data = CRYPTER.decrypt(DATA.decode("hex"))
if hashlib.sha256(decrypted_data).digest() == CKSUM.decode("hex"):
    open(OUTPUTFILE, "w").write(decrypted_data)
    print "wallet decrypted!"
else:
    print "Wrong password(cksum wrong)"
"""
BITCOIN_ACCESS = jsonrpc.ServiceProxy("http://%s:%s@127.0.0.1:8332"%(BITCOIN_USER, BITCOIN_PASS))
TEMPFILE = "/tmp/wallet.tmp.%d"%random.randint(0,2**23)

HOSTNAME = open("/etc/hostname").readline().strip("\n")
DATESTRING = time.ctime(time.time())
KEY = hashlib.sha256(PASSWORD).digest()
CRYPTER = AES.new(KEY, AES.MODE_CFB)

msg = MIMEMultipart()
msg['Subject'] = "Wallet Backup from %s on %s" %(HOSTNAME, DATESTRING)
msg['To'] = TO_EMAIL
msg['From'] = "walletbackup@%s" % HOSTNAME

BITCOIN_ACCESS.backupwallet(TEMPFILE)
walletdata = open(TEMPFILE, "r").read()

cksum = hashlib.sha256(walletdata).digest()
wallet = CRYPTER.encrypt(walletdata)

wallet_attachment = MIMEBase("application", "octet-stream")
wallet_attachment.set_payload(DECRYPT_SCRIPT % (wallet.encode("hex"), cksum.encode("hex")))
wallet_attachment.add_header('Content-Disposition', 'attachment', filename="decrypter.py")
encoders.encode_base64(wallet_attachment)

msg.attach(wallet_attachment)

#print msg.as_string()
s = smtplib.SMTP('localhost')
s.sendmail("walletbackup@%s" % HOSTNAME, TO_EMAIL, msg.as_string())
s.quit()

"The whole problem with the world is that fools and fanatics are always so certain of themselves and wiser people so full of doubts." -Bertrand Russell
1481395233
Hero Member
*
Offline Offline

Posts: 1481395233

View Profile Personal Message (Offline)

Ignore
1481395233
Reply with quote  #2

1481395233
Report to moderator
1481395233
Hero Member
*
Offline Offline

Posts: 1481395233

View Profile Personal Message (Offline)

Ignore
1481395233
Reply with quote  #2

1481395233
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1481395233
Hero Member
*
Offline Offline

Posts: 1481395233

View Profile Personal Message (Offline)

Ignore
1481395233
Reply with quote  #2

1481395233
Report to moderator
1481395233
Hero Member
*
Offline Offline

Posts: 1481395233

View Profile Personal Message (Offline)

Ignore
1481395233
Reply with quote  #2

1481395233
Report to moderator
kokjo
Legendary
*
Offline Offline

Activity: 1050

You are WRONG!


View Profile
May 04, 2012, 06:46:29 AM
 #2

BUMP! no one replyed?  Shocked I though i was writing good code, to help you people.

"The whole problem with the world is that fools and fanatics are always so certain of themselves and wiser people so full of doubts." -Bertrand Russell
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!