0

I have a large unicode text file (35 MB) containing words separated by punctuation marks. I need to somehow hide the content of the file (at least from the majority of people who are not specialised in cracking).

The best way until now seemed like encryption. I know almost nothing about encryption. I tried to use the solution to a similar question "Simple 2 way encryption for C#" but it takes a long time to execute the encryption.

What is the fastest way (algorithm) that works out of the box (i.e. it is contained in the .Net lib)? A short example on how to use it would be nice :) I don't care how strong the encryption is, if you open the encrypted file with a text editor and don't see the words then it's perfect. The important part is speed.

Brandon
  • 68,708
  • 30
  • 194
  • 223
ghet
  • 279
  • 2
  • 5
  • 8
  • 1
    If you don't need to access the file with a program, why not just use a passworded .zip file or something? – Marc B Mar 11 '11 at 21:49
  • I need to decrept it when my app start. – ghet Mar 11 '11 at 21:54
  • I've tried AES encryption as discribed here [Simple 2 way encryption for C#](http://stackoverflow.com/questions/165808/simple-2-way-encryption-for-c) but it's very slow. It didn't finish in more then 15 minuts on a core 2 duo (2.5 GHz) with 3GB RAM – ghet Mar 11 '11 at 22:00
  • 1
    If you want to just "hide" the raw data, you could use a simple XOR obfuscation. Wouldn't stand up to any serious cryptological attack, but would hide things. – Marc B Mar 11 '11 at 22:08
  • The biggest issue with security is not how secure it is, it is who gets the blame and is liable for the damages when it gets compromised. You do *not* want to be anywhere near that chain of blame. Do not implement your own encryption scheme, especially a weak one like tileryj suggests. Put the file on a secured file server with strong passwords in a server room with a lock. – Hans Passant Mar 11 '11 at 22:11
  • 15 minutes for AES on a 35MB file? TrueCrypt shows modern CPUs doing over 100MB/sec for AES and over 1500MB/sec for new AES-NI instruction set. 35MB should take somewhere between 25ms and 350ms, assuming not HD limited, not 15 minutes. – Bengie Mar 11 '11 at 22:21
  • @Hans Passant Thanks for youre advice , but this isn't such an importan file , it doesen't contain passwords and such stuf , it only has some word paterns. – ghet Mar 11 '11 at 23:32
  • Well, don't bother then. Be practical. – Hans Passant Mar 11 '11 at 23:46

3 Answers3

3

AES is pretty fast still, here's some help implementing it : Using AES encryption in C#

Anything other than industry standard Encryption is asking for problems sooner or later.

Community
  • 1
  • 1
DaveShaw
  • 52,123
  • 16
  • 112
  • 141
0

What have you tried so far? Are standard encryptions like AES and blowfish too slow?

You can always do something simple like xor-ing the contents against some pass-code repeated to the same length as the file.

tilleryj
  • 14,259
  • 3
  • 23
  • 22
  • I've tried AES encryption as discribed here [Simple 2 way encryption for C#](http://stackoverflow.com/questions/165808/simple-2-way-encryption-for-c) but it's very slow. It didn't finish in more then 15 minuts on a core 2 duo (2.5 GHz) with 3GB RAM – ghet Mar 11 '11 at 21:58
  • I guess I would try the xor method then. Does it make sense the way I described it? – tilleryj Mar 11 '11 at 22:03
  • yes xor does it for me. It encripts the 32MB in 1 - 2 seconds. Thanks!! – ghet Mar 11 '11 at 22:58
-1

As tilleryj said

xor-ing the contents against some pass-code repeated to the same length as the file is simple and fast

but it is les safe then other encription types. I wrote a simple class that helps you encript a string using another string as a password usig the xor method. hope some else can use it.

`using System;
using System.Text;

namespace MyEncriptionNameSpace { class XorStringEncripter { private string __passWord; public XorStringEncripter(string password) { if (password.Length == 0) { throw new Exception("invalide password"); } __passWord = password; } public string encript(string stringToEncript) { return __encript(stringToEncript); }

public string decript(string encripTedString) { return __encript(encripTedString); } public string __encript(string stringToEncript) { var encriptedStringBuilder = new StringBuilder(stringToEncript.Length); int positionInPassword = 0; for (int i = 0; i < stringToEncript.Length; i++) { __corectPositionInPassWord(ref positionInPassword); encriptedStringBuilder.Append((char)((int)stringToEncript[i] ^ (int)__passWord[positionInPassword])); ++positionInPassword; } return encriptedStringBuilder.ToString(); } private void __corectPositionInPassWord(ref int positionInPassword) { if (positionInPassword == __passWord.Length) { positionInPassword = 0; } } }

}`

actualy encript and decript do the same thing , I provided bouth to avoid confusion on using the same function for bouth encription and decrition. This is because if you have a nuber A and you xor it with B and you obtain C then if you xor C and B you get A.
A xor B = C ---> C xor B = A

ghet
  • 279
  • 2
  • 5
  • 8