[VS 2008] Strong encryption and hashing class - Updated! 31/August/2009
Updated - August/31/2009
FYI:
Someone asked me if one should use the whole algorithm to encrypt or hash; the answer is NO, if you want to encrypt a string (with AES or Rijndael) then just copy the region and paste it in your code, same thing goes for hashing. The code is divided into regions to serve that purpose.
Updates:
Added an enumeration to hold the cryptographic actions that can be performed (encryption or decryption).
Added a function to generate an IV from the given key (after playing around with it ).
Added an exception handler... Just in case the password isn't the right one.
Hello,
I have been working on this for a while now, I have based my work on Jenner's submission. Since I had noticed that it was for VS 2005, I decided to create my own, for VS 2008...
I have included AES for encryption and used SHA256 for hashing the strings, also some overloads so it'll handle more object types (to permit more "flexibility").
Even though AES and Rijndael ARE THE SAME ALGORITHMS, they have some particularities:
AES:
Has a fixed block size of 128bits.
Allows key sizes of 128, 192 and 256 bits.
Rijndael:
Allows block sizes of 128bits, 192bits and 256bits.
Permits the use of 64, 96, 128, 192, 256 bits key sizes.
(The block size is specific to each algorithm since it indicates which the size of the IV to be used or that is supported by one of these two algorithms.)
Re: [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009
Which one is better, this one, or DES Encryption? By better I mean more secure from hackers (I suppose that either one COULD be hacked if somebody really wanted to).
Re: [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009
Hey man, I had searched for a response to your question. I found these articles about DES and AES.
DES is now considered to be insecure for many applications. This is chiefly due to the 56-bit key size being too small; in January, 1999, distributed.net and the Electronic Frontier Foundation collaborated to publicly break a DES key in 22 hours and 15 minutes (see chronology). There are also some analytical results which demonstrate theoretical weaknesses in the cipher, although they are unfeasible to mount in practice. The algorithm is believed to be practically secure in the form of Triple DES, although there are theoretical attacks. In recent years, the cipher has been superseded by the Advanced Encryption Standard (AES).
The design and strength of all key lengths of the AES algorithm (i.e., 128, 192 and 256) are sufficient to protect classified information up to the SECRET level. TOP SECRET information will require use of either the 192 or 256 key lengths. The implementation of AES in products intended to protect national security systems and/or information must be reviewed and certified by NSA prior to their acquisition and use.
Aside from that, I personally use AES because of the length of the cypher key and because the 256-bit key AES hasn't been successfully attacked yet (there is also the fact that AES substituted DES as the current, most secure standard).
"In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
Niklaus E. Wirth
Rate any post that helped you, it's a good way of saying thanks
Please specify your Visual Studio Version!
Re: [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009
Hi, i need to encrypt and decrypt my passwords in my projects. When i enter some texts in my textbox1, it needs to be encrypted and then saved to the database. How to do add this to my project?
Re: [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009
Hey, to add this to your project you can click Ctrl + D and add the class (if you have downloaded it) or you can create a new class and copy-paste the code in it. Then you have to import the correct namespace into your project.
"In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
Niklaus E. Wirth
Rate any post that helped you, it's a good way of saying thanks
Please specify your Visual Studio Version!