Hi,
as part of a project I am encrypting a string as part of my Win
Application and write it to file.
Reading and decrypting the string from Win works without problem, but
when I try to run the decryption part on Linux (encrypted on Win),
I end up with an error, caused by the encrypted string in the file not
read properly (I suppose), i.e. the characters get misinterpreted ...
I can see it in my frontend that writes the encryped string to a simple
wx.TextCtrl ...
So my question:
What is the correct way to open the file and read the encrypted string
so I end up fine doing the decryption part on Linux?
ThanX
Sample follows
···
------
# encryption sample run from windows
# -*- coding: iso-8859-15 -*-
from Crypto.Cipher import DES
import os
import sys
#test: 2 strings
# string 1 whose decryption works on Linux
#serial = "2401623B"
#
# string 2 whose decryption DOES NOT WORK on Linux
serial = "AA4C4DF7"
# make the string a multiple of 8 ... 16 max is OK for now
if len(serial) == 8:
pass
else:
while len(serial) < 16:
serial = serial + "0"
print serial
print "Serial of char length " + str(len(serial))+ ": " + str(serial)
try:
obj=DES.new('12345678', DES.MODE_ECB)rog
encrypted_request = obj.encrypt(serial+'01234567')oki
print encrypted_request
data = encrypted_request
rq = file('serial_test.txt','w')
rq.write(data)
rq.close()
except:
print "Crypto error"
--------
# decryption sample run from Linux
# -*- coding: iso-8859-15 -*-
from Crypto.Cipher import DES
# for test purposes:
request_file = open("serial_test.txt", 'r')
encrypted_request = request_file.read()
print "Serial file request encrypted: "
# for test purposes
print str(encrypted_request)
obj=DES.new('12345678', DES.MODE_ECB)
# this throws the error
decrypted_request = obj.decrypt(encrypted_request)
decrypted_request_sanitized = decrypted_request.replace('01234567','')
print "Decrypted request"
print str(decrypted_request_sanitized)