My Expirience with Cryptography
- Silvan Bauer
- Oct 29, 2022
- 3 min read
So ever wondered how to encrypt and decrypt text, data or files? I was curious and took a look at it.
AES the Secure Algorithm
So I took a look at cryptography since I was interested in it. Cryptography is something which exists since a long time and was even used before computers existed. But the kind of Cryptography I'm interested in is the one for the Computers. So I was looking at some of the different Cryptography Algorithms since I wanted to try it out.
I looked into the C# Api documentation and found a few Algorithms which were implemented in C#. Since I knew that many Cryptography Algorithms were actually not secure and could be decrypted without knowing the actual key I was looking for a secure Algorithm were I could use a password a user provided. And when I was looking around I found the AES (Advanced Encryption Standard) Algorithm. It uses an individual value which can be anything and is provided as a byte array and a key which is also a byte array. And according to the English Wikipedia the AES is actually the only approved algorithm by the NSA for top secret information.
Implementing it in C#
So then I started implementing it in C# by using the Aes class. Overall is quite easy once you know how to but since I was looking at it the first time ever it was a bit confusing considering you had to use a Cryptograph (Aes in my case), a stream to write to and a CryptoStream. Then I tested it on a few things like text and files.
Text and files were working pretty well but the I had a thought but what about a whole application or game? So I started writing a code to encrypt a whole application.
Encrypting a whole application
To encrypt an application you just have to encrypt everything which doesn't change. And since it might contain a whole directory structure with files I also created models to save the whole directory and file structure. In the end I was able to make it work. However I did have an issue with larger files since I loaded the whole data before encrypting it so the whole file was written into the RAM. To improve this I had to load a part of a file encrypt it and then load the next part of the file until the whole file is encrypted.
All in all it worked and I was also able to decrypt it. The end result of an encrypted application was two files one containing the data and one the directory and file structure. Both encrypted with AES, the same IV and Key. Decrypting was also possible but since a game is normally not small (though I did take smaller games since I didn't want to wait for bigger games) it took quite a bit of time. So overall I would say it works but it's not really useful since you don't need to encrypt an application (like literally probably never).
Conclusion
Cryptography is an interesting topic but you probably will never need it yourself except for maybe if you're working with sensitive data. And the larger the file the longer it will take obviously to encrypt and decrypt data. But one interesting thing I noticed was that decrypting seems to be a bit faster than encrypting.
コメント