URI: 
       tuse python slowaes library - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit c87533acaad1e8499bd4efdd99535a39d8359a04
   DIR parent e7d233a7a2de7424c737ed115b0e59fdc3e30c6c
  HTML Author: ThomasV <thomasv@gitorious>
       Date:   Tue, 29 Nov 2011 10:26:47 +0100
       
       use python slowaes library
       
       Diffstat:
         M client/electrum.py                  |      41 ++++++++++++++-----------------
         A client/upgrade.py                   |      34 +++++++++++++++++++++++++++++++
       
       2 files changed, 53 insertions(+), 22 deletions(-)
       ---
   DIR diff --git a/client/electrum.py b/client/electrum.py
       t@@ -26,10 +26,11 @@ except:
            sys.exit(1)
        
        try:
       -    import Crypto
       -    has_encryption = True
       +    import aes
        except:
       -    has_encryption = False
       +    print "AES does not seem to be installed. Try 'sudo easy_install slowaes'"
       +    sys.exit(1)
       +
        
        
        ############ functions from pywallet ##################### 
       t@@ -149,13 +150,10 @@ def int_to_hex(i, length=1):
            return s.decode('hex')[::-1].encode('hex')
        
        
       -# password encryption
       -from Crypto.Cipher import AES
       -BLOCK_SIZE = 32
       -PADDING = '{'
       -pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
       -EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
       -DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
       +
       +EncodeAES = lambda secret, s: base64.b64encode(aes.encryptData(secret,s))
       +DecodeAES = lambda secret, e: aes.decryptData(secret, base64.b64decode(e))
       +
        
        
        # secp256k1, http://www.oid-info.com/get/1.3.132.0.10
       t@@ -224,7 +222,7 @@ class Wallet:
                self.host = 'ecdsa.org'
                self.port = 50000
                self.fee = 0.005
       -        self.version = 1
       +        self.version = 2             # bump this everytime the wallet format is modified
        
                # saved fields
                self.use_encryption = False
       t@@ -381,6 +379,8 @@ class Wallet:
                     self.labels, self.addressbook) = sequence
                except:
                    raise BaseException("version error.")
       +        if self.version == 1 and self.use_encryption:
       +            raise BaseException("version error: please upgrade your wallet first")
                self.update_tx_history()
                return True
                
       t@@ -529,16 +529,14 @@ class Wallet:
            def pw_encode(self, s, password):
                if password:
                    secret = Hash(password)
       -            cipher = AES.new(secret)
       -            return EncodeAES(cipher, s)
       +            return EncodeAES(secret, s)
                else:
                    return s
        
            def pw_decode(self, s, password):
                if password:
                    secret = Hash(password)
       -            cipher = AES.new(secret)
       -            return DecodeAES(cipher, s)
       +            return DecodeAES(secret, s)
                else:
                    return s
        
       t@@ -671,13 +669,12 @@ if __name__ == '__main__':
                if wallet.read():
                    print "remove the existing wallet first!"
                    sys.exit(0)
       -        if has_encryption:
       -            password = getpass.getpass("Password (hit return if you do not wish to encrypt your wallet):")
       -            if password:
       -                password2 = getpass.getpass("Confirm password:")
       -                if password != password2:
       -                    print "error"
       -                    sys.exit(1)
       +        password = getpass.getpass("Password (hit return if you do not wish to encrypt your wallet):")
       +        if password:
       +            password2 = getpass.getpass("Confirm password:")
       +            if password != password2:
       +                print "error"
       +                sys.exit(1)
                else:
                    password = None
                    print "in order to use wallet encryption, please install pycrypto  (sudo easy_install pycrypto)"
   DIR diff --git a/client/upgrade.py b/client/upgrade.py
       t@@ -0,0 +1,34 @@
       +import electrum, getpass, base64,ast
       +
       +wallet = electrum.Wallet(None)
       +try:
       +    wallet.read()
       +    print "ok"
       +except BaseException:
       +    if wallet.version == 1 and wallet.use_encryption:
       +        # version 1 used pycrypto for wallet encryption
       +        import Crypto
       +        from Crypto.Cipher import AES
       +        BLOCK_SIZE = 32
       +        PADDING = '{'
       +        pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
       +        EncodeAES = lambda secret, s: base64.b64encode(AES.new(secret).encrypt(pad(s)))
       +        DecodeAES = lambda secret, e: AES.new(secret).decrypt(base64.b64decode(e)).rstrip(PADDING)
       +
       +        print "encrypted seed", wallet.seed
       +        print "please provide your password"
       +        password = getpass.getpass("Password:")
       +        secret = electrum.Hash(password)
       +        try:
       +            seed = DecodeAES( secret, wallet.seed )
       +            private_keys = ast.literal_eval( DecodeAES( secret, wallet.private_keys ) )
       +        except:
       +            print "sorry"
       +            exit(1)
       +        print seed
       +        print private_keys
       +        wallet.version = 2
       +        wallet.seed = wallet.pw_encode( seed, password)
       +        wallet.private_keys = wallet.pw_encode( repr( private_keys ), password)
       +        wallet.save()
       +        print "wallet was upgraded"