Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello,

I want to encrypt data of file using c#,I am using this code my file it's not encrypting.
My code:-
FileStream fs1 = new FileStream("D:\\Licence.DAT", FileMode.OpenOrCreate, FileAccess.Write);
File.SetAttributes("D:\\Licence.DAT", FileAttributes.Encrypted);
StreamWriter writer = new StreamWriter(fs1);
writer.Write("Validated Days:" + "" + txtValidatedDays.Text);
writer.WriteLine("\n" + "MAC Address:" + "" + txtMacAddress.Text);
writer.Close();

MessageBox.Show("Licence Generated Successfully");

Please help me.

Thanks in Advance.

Ankit Agarwal
Software Engineer
Posted

1 solution

Don't encrypt it: you need to provide a key to decrypt it each time foe comparison.
Instead, use a hashing function and compare the outputs instead.
MSDN: SHA512[^]

And you are aware of just how easy it is to "spoof" a MAC address[^], aren't you?
 
Share this answer
 
Comments
Rob Philpott 4-Apr-14 10:42am    
I'm missing something here. How do you know he wants to check the integrity (compare hashes) rather than actually encrypt the data?
OriginalGriff 4-Apr-14 10:47am    
MessageBox.Show("Licence Generated Successfully");
Implies it's a license key he's generating.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900