diff options
Diffstat (limited to 'pipermail/pycrypto/attachments/20140203/dd2d7c15/attachment-0001.html')
-rw-r--r-- | pipermail/pycrypto/attachments/20140203/dd2d7c15/attachment-0001.html | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/pipermail/pycrypto/attachments/20140203/dd2d7c15/attachment-0001.html b/pipermail/pycrypto/attachments/20140203/dd2d7c15/attachment-0001.html new file mode 100644 index 0000000..da55600 --- /dev/null +++ b/pipermail/pycrypto/attachments/20140203/dd2d7c15/attachment-0001.html @@ -0,0 +1,142 @@ +<tt> +<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br> +<grin/><br><br> +Not sure Jeremy! I'd never heard of it.<br></blockquote><div><br></div><div>Actually, it looks like 'rU' might be the way to go, not 'Urb'. I've never used it but probably should. :-) </div><div> </div><br> +<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br> +I'll let you know.... I'm assuming it is 2.x compatible?<br></blockquote><div><br></div><div>yes 2.7, not sure about earlier</div><div><br></div><div>--Jeremy</div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br> +<br> +<br> +<br><br> +regards<br><br> +<div><div><br><br> +On 3 February 2014 12:40, Jeremy Gray <<a href="mailto:jrgray@gmail.com" target="_blank">jrgray@gmail.com</a>> wrote:<br><br> +> I may not understand the constraints of your situation, but wouldn't<br><br> +> python's "universal newlines" file-open mode achieve what you want? infile<br><br> +> = open(filename, 'Urb')<br><br> +><br><br> +> --Jeremy<br><br> +><br><br> +><br><br> +> On Mon, Feb 3, 2014 at 5:35 AM, Dave Pawson <<a href="mailto:dave.pawson@gmail.com" target="_blank">dave.pawson@gmail.com</a>> wrote:<br><br> +>><br><br> +>> Now resolved.<br><br> +>> Source plain text is created / modified in either DOS or Linux (np to add<br><br> +>> Mac)<br><br> +>><br><br> +>> read using<br><br> +>> chunk = unicode(infile.read(chunksize))<br><br> +>> # replace newline as appropriate<br><br> +>> chunk=replaceNL(chunk)<br><br> +>> # Convert to byte string<br><br> +>> chunk=safe_str(chunk)<br><br> +>> encrypt and write to disk<br><br> +>><br><br> +>><br><br> +>> # for decrypt<br><br> +>> #Iterate over file to read into string<br><br> +>> # replace the individual bytes of the Unicode character (u2022 in my case)<br><br> +>> # with \n for the local machine<br><br> +>> retval = replaceBullet(retval)<br><br> +>><br><br> +>> code below<br><br> +>><br><br> +>> #<br><br> +>> #Swap \n for \u2022<br><br> +>> #<br><br> +>> def replaceNL(str):<br><br> +>> # If DOS, replace \r\x0A<br><br> +>> # If Unix, replace \n<br><br> +>> lineEnd=u'\n'<br><br> +>> if string.find(str,'\r\x0a'):<br><br> +>> lineEnd=u'\r\x0A'<br><br> +>> return string.replace(str,lineEnd,u'\u2022')<br><br> +>><br><br> +>> #<br><br> +>> # Replace bullet by \n<br><br> +>> #<br><br> +>> def replaceBullet(bstr):<br><br> +>> return string.replace(bstr,u'\\u2022',u'\n')<br><br> +>><br><br> +>><br><br> +>><br><br> +>> def safe_str(obj):<br><br> +>> """ return the byte string representation of obj """<br><br> +>> try:<br><br> +>> return str(obj)<br><br> +>> except UnicodeEncodeError:<br><br> +>> # obj is unicode<br><br> +>> return unicode(obj).encode('unicode_escape')<br><br> +>><br><br> +>> HTH others, though it seems messy, it works.<br><br> +>><br><br> +>> Dave<br><br> +>><br><br> +>><br><br> +>> On 3 February 2014 09:39, Dave Pawson <<a href="mailto:dave.pawson@gmail.com" target="_blank">dave.pawson@gmail.com</a>> wrote:<br><br> +>> > I'm having a problem 'sharing' an encrypted file between<br><br> +>> > MSDOS and Linux.<br><br> +>> ><br><br> +>> > so I thought I'd replace \nl in the plain text with a non ASCII<br><br> +>> > character prior to encryption.<br><br> +>> ><br><br> +>> > encryptor = AES.new(key, AES.MODE_CBC, iv)<br><br> +>> > outfile.write(encryptor.encrypt(chunk))<br><br> +>> ><br><br> +>> > gives me<br><br> +>> ><br><br> +>> > File "/usr/lib64/python2.7/site-packages/Crypto/Cipher/blockalgo.py",<br><br> +>> > line 244, in encrypt<br><br> +>> > return self._cipher.encrypt(plaintext)<br><br> +>> > UnicodeEncodeError: 'ascii' codec can't encode character u'\u2022' in<br><br> +>> > position 34: ordinal not in range(128)<br><br> +>> ><br><br> +>> ><br><br> +>> > It would seem I can't use non-ASCII characters, at least with AES, is<br><br> +>> > this right ?<br><br> +>> ><br><br> +>> > If not, how to address it please?<br><br> +>> ><br><br> +>> ><br><br> +>> > regards<br><br> +>> ><br><br> +>> ><br><br> +>> > --<br><br> +>> > Dave Pawson<br><br> +>> > XSLT XSL-FO FAQ.<br><br> +>> > Docbook FAQ.<br><br> +>> > <a href="http://www.dpawson.co.uk" target="_blank">http://www.dpawson.co.uk</a><br><br> +>><br><br> +>><br><br> +>><br><br> +>> --<br><br> +>> Dave Pawson<br><br> +>> XSLT XSL-FO FAQ.<br><br> +>> Docbook FAQ.<br><br> +>> <a href="http://www.dpawson.co.uk" target="_blank">http://www.dpawson.co.uk</a><br><br> +>> _______________________________________________<br><br> +>> pycrypto mailing list<br><br> +>> <a href="mailto:pycrypto@lists.dlitz.net" target="_blank">pycrypto@lists.dlitz.net</a><br><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><br> +><br><br> +><br><br> +><br><br> +> _______________________________________________<br><br> +> pycrypto mailing list<br><br> +> <a href="mailto:pycrypto@lists.dlitz.net" target="_blank">pycrypto@lists.dlitz.net</a><br><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><br> +><br><br> +<br><br> +<br><br> +<br><br> +--<br><br> +Dave Pawson<br><br> +XSLT XSL-FO FAQ.<br><br> +Docbook FAQ.<br><br> +<a href="http://www.dpawson.co.uk" target="_blank">http://www.dpawson.co.uk</a><br><br> +_______________________________________________<br><br> +pycrypto mailing list<br><br> +<a href="mailto:pycrypto@lists.dlitz.net" target="_blank">pycrypto@lists.dlitz.net</a><br><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><br> +</div></div></blockquote></div><br></div></div><br> + +</tt> |