This class uses a symmetric key algorithm (Rijndael/AES) to encrypt and decrypt data. As long as encryption and decryption routines use the same parameters to generate the keys, the keys are guaranteed to be the same.
The class uses static functions with duplicate code to make it easier to demonstrate encryption and decryption logic. In a real-life application, this may not be the most efficient way of handling encryption, so - as soon as you feel comfortable with it - you may want to redesign this class.
Exemplo n.º 1
0
 /// <summary>
 /// Decrypts a string
 /// </summary>
 /// <param name="text">String to be decrypted</param>
 /// <returns>Decrypted string</returns>
 public string Decrypt(string text)
 {
     try
     {
         return((!string.IsNullOrEmpty(text))
                    ? RijndaelSimple.Decrypt(text, PassPhrase, Salt, "SHA1", 2, IV16Chars, 256)
                    : text);
     }
     catch
     {
         return(text);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Encrypts a string using the specified Pass Key and Salt
 /// </summary>
 /// <param name="text">String to be encrypted</param>
 /// <returns>Encrypted String</returns>
 public string Encrypt(string text)
 {
     try
     {
         if (!string.IsNullOrEmpty(text))
         {
             return(RijndaelSimple.Encrypt(text, PassPhrase, Salt, "SHA1", 2, IV16Chars, 256));
         }
         else
         {
             return(text);
         }
     }
     catch { return(text); }
 }