<div dir="ltr">I may not understand the constraints of your situation, but wouldn't python's "universal newlines" file-open mode achieve what you want?  infile = open(filename, 'Urb')<div><br></div>
<div class="gmail_extra"><div><div dir="ltr">--Jeremy</div></div>
<br><br><div class="gmail_quote">On Mon, Feb 3, 2014 at 5:35 AM, Dave Pawson <span dir="ltr"><<a href="mailto:dave.pawson@gmail.com" target="_blank">dave.pawson@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Now resolved.<br>
Source plain text is created / modified in either DOS or Linux (np to add Mac)<br>
<br>
read using<br>
chunk = unicode(infile.read(chunksize))<br>
# replace newline as appropriate<br>
chunk=replaceNL(chunk)<br>
# Convert to byte string<br>
chunk=safe_str(chunk)<br>
encrypt and write to disk<br>
<br>
<br>
# for decrypt<br>
#Iterate over file to read into string<br>
# replace the individual bytes of the Unicode character (u2022 in my case)<br>
# with \n for the local machine<br>
retval = replaceBullet(retval)<br>
<br>
code below<br>
<br>
#<br>
#Swap \n for \u2022<br>
#<br>
def replaceNL(str):<br>
    # If DOS, replace \r\x0A<br>
    # If Unix, replace \n<br>
    lineEnd=u'\n'<br>
    if string.find(str,'\r\x0a'):<br>
        lineEnd=u'\r\x0A'<br>
    return string.replace(str,lineEnd,u'\u2022')<br>
<br>
#<br>
# Replace bullet by \n<br>
#<br>
def replaceBullet(bstr):<br>
    return string.replace(bstr,u'\\u2022',u'\n')<br>
<br>
<br>
<br>
def safe_str(obj):<br>
    """ return the byte string representation of obj """<br>
    try:<br>
        return str(obj)<br>
    except UnicodeEncodeError:<br>
        # obj is unicode<br>
        return unicode(obj).encode('unicode_escape')<br>
<br>
HTH others, though it seems messy, it works.<br>
<span class="HOEnZb"><font color="#888888"><br>
Dave<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
On 3 February 2014 09:39, Dave Pawson <<a href="mailto:dave.pawson@gmail.com">dave.pawson@gmail.com</a>> wrote:<br>
> I'm having a problem 'sharing' an encrypted file between<br>
> MSDOS and Linux.<br>
><br>
> so I thought I'd replace \nl in the plain text with a non ASCII<br>
> character prior to encryption.<br>
><br>
> encryptor = AES.new(key, AES.MODE_CBC, iv)<br>
> outfile.write(encryptor.encrypt(chunk))<br>
><br>
> gives me<br>
><br>
>  File "/usr/lib64/python2.7/site-packages/Crypto/Cipher/blockalgo.py",<br>
> line 244, in encrypt<br>
>     return self._cipher.encrypt(plaintext)<br>
> UnicodeEncodeError: 'ascii' codec can't encode character u'\u2022' in<br>
> position 34: ordinal not in range(128)<br>
><br>
><br>
> It would seem I can't use non-ASCII characters, at least with AES, is<br>
> this right ?<br>
><br>
> If not, how to address it please?<br>
><br>
><br>
> regards<br>
><br>
><br>
> --<br>
> Dave Pawson<br>
> XSLT XSL-FO FAQ.<br>
> Docbook FAQ.<br>
> <a href="http://www.dpawson.co.uk" target="_blank">http://www.dpawson.co.uk</a><br>
<br>
<br>
<br>
--<br>
Dave Pawson<br>
XSLT XSL-FO FAQ.<br>
Docbook FAQ.<br>
<a href="http://www.dpawson.co.uk" target="_blank">http://www.dpawson.co.uk</a><br>
_______________________________________________<br>
pycrypto mailing list<br>
<a href="mailto:pycrypto@lists.dlitz.net">pycrypto@lists.dlitz.net</a><br>
<a href="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto" target="_blank">http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto</a><br>
</div></div></blockquote></div><br></div></div>