Reading a binary file as text and manipulating it... [C#] Versus [VB.NET] -


well guys in bit of pickle here...

i doing exercises on encrypting data. 1 of them binary files. using triple des encrypt , decrypt files both in vb.net , c#...

now thing is, once decrypted in vb.net , saved, can execute again...

but reason, c# file bigger! 20,4k vb.net 1 19,0. c# file rendered unexecutable...

upon closer look. files appear same, c# seems add in few bytes here , there in (seemingly) random places...

i using file.readalltext(string filepath, encoding encoding); utf-8 encoding

thanks!

you you're using file.readalltext... these binary files. makes me suggest you're treating opaque binary data (e.g. result of encryption) if text (e.g. calling encoding.getstring on it).

don't that.

basically, encryption works on binary data - binary in, binary out. if need encrypt text text, you'll apply "normal" encoding convert text binary data (e.g. encoding.utf8.getbytes(text)) , use base64 convert opaque binary data text in lossless way - e.g. convert.tobase64string(encrypted).

decrypting reverse: use convert.frombase64string(encryptedtext) encrypted binary data, decrypt it, , use encoding.utf8.getstring(decrypted) text.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -