def write_xml(self): # Created Salmon decrypted header decrypted_header = "<decrypted_header>\n\ <iv>%s</iv>\n\ <aes_key>%s</aes_key>\n\ <author>\n\ <name>%s</name>\n\ <uri>acct:%s</uri>\n\ </author>\n\ </decrypted_header>\n" % (base64.urlsafe_b64encode(self.aes_key[1]),base64.urlsafe_b64encode(self.aes_key[0]),self.author,self.author_uri) # Encrypt decrypted_header key = aes_helper.get_random_key() ciphertext = base64.b64encode(aes_helper.encrypt(decrypted_header,key)) # Encrypt AES session-key with the receivers public key key_hash = simplejson.dumps({'key':base64.b64encode(key[0]),'iv':base64.b64encode(key[1])}) encrypted_key = base64.b64encode(rsa_helper.encrypt(key_hash,self.public_key)) # Pack encrypted header encrypted_header = base64.b64encode(simplejson.dumps({'aes_key':encrypted_key,'ciphertext':ciphertext})) # Put it all together to a nice Salmon-friendly atom XML xml = "<?xml version='1.0' encoding='UTF-8'?>\n\ <entry xmlns='http://www.w3.org/2005/Atom'>\n\ <encrypted_header>%s</encrypted_header>\n\ %s\n\ </entry>" % (encrypted_header,self.envelope) return xml
res = rsa_helper.generate_rsa(4096) if res: print " - Success" success += 1 else: print " - Fail" fail +=1 except: print " - Epic fail" fail +=1 if test_rsa or test_salmon: print "Encrypting message with public key using rsa_helper..." try: plain = "Testing encryption" cipher = rsa_helper.encrypt(plain,res[0]) if cipher and cipher != plain: print " - Success" success += 1 else: print " - Fail" fail +=1 except: print " - Epic fail" fail +=1 if test_rsa or test_salmon: print "Decrypting message with private key using rsa_helper..." try: new_plain = rsa_helper.decrypt(cipher,res[1]) if new_plain == plain: