Click here to Skip to main content
16,004,927 members
Home / Discussions / Web Development
   

Web Development

 
GeneralRe: Stretch TextBox to fill rest of container. Pin
led mike13-Mar-08 5:33
led mike13-Mar-08 5:33 
GeneralRe: Stretch TextBox to fill rest of container. Pin
Shog913-Mar-08 12:42
sitebuilderShog913-Mar-08 12:42 
GeneralRe: Stretch TextBox to fill rest of container. Pin
Brady Kelly13-Mar-08 21:56
Brady Kelly13-Mar-08 21:56 
GeneralRe: Stretch TextBox to fill rest of container. Pin
Shog914-Mar-08 5:11
sitebuilderShog914-Mar-08 5:11 
GeneralRe: Stretch TextBox to fill rest of container. Pin
Brady Kelly16-Mar-08 22:25
Brady Kelly16-Mar-08 22:25 
GeneralRe: Stretch TextBox to fill rest of container. Pin
Shog917-Mar-08 3:58
sitebuilderShog917-Mar-08 3:58 
GeneralRe: Stretch TextBox to fill rest of container. Pin
Brady Kelly17-Mar-08 5:01
Brady Kelly17-Mar-08 5:01 
GeneralRijndael algo for Encryption and Decryption of Password Pin
salon13-Mar-08 3:13
salon13-Mar-08 3:13 
I am trying to encrypt and decrypt the password in ASP.NEt2.0 application with Rijndael
algo.
I am able to encrypt the password but not able to decrypt it.

Can anybody tell me what is the problem with my code,

I am pasting it here

public static string Encrypt(string StringToEncrypt, string Key)
{
Rijndael _encryptionservice = new RijndaelManaged();
ICryptoTransform _encryptor;
byte[] _bytesdata;
byte[] _byteskey;
string _encryptedstring;

Key = Key.ToLower();
_bytesdata = Encoding.ASCII.GetBytes(StringToEncrypt.PadRight(16));
_byteskey = Encoding.ASCII.GetBytes(Key.PadRight(32).Substring(0, 32));

_encryptionservice.Mode = CipherMode.CBC;
_encryptionservice.Key = _byteskey;
//_encryptionservice.IV = Encoding.ASCII.GetBytes("VIMSuitEncoding");

_encryptor = _encryptionservice.CreateEncryptor();

MemoryStream _memstreamencrypteddata = new MemoryStream();

CryptoStream encStream = new CryptoStream(_memstreamencrypteddata, _encryptor, CryptoStreamMode.Write);
try
{
encStream.Write(_bytesdata, 0, _bytesdata.Length);
}
catch (Exception ex)
{
throw new Exception("Error while writing encrypted data to the stream", ex);
}
encStream.FlushFinalBlock();
encStream.Close();

_encryptedstring = Convert.ToBase64String(_memstreamencrypteddata.ToArray());

return _encryptedstring;
}

public static string Decrypt(string StringToDecrypt, string Key)
{
Rijndael _encryptionservice = new RijndaelManaged();
byte[] _bytesdata;
byte[] _byteskey;
string _encryptedstring;
ICryptoTransform _decryptor;
int _decryptedstringlength;

Key = Key.ToLower();

_bytesdata = Convert.FromBase64String(StringToDecrypt);
_byteskey = Encoding.ASCII.GetBytes(Key.PadRight(32).Substring(0, 32));

_encryptionservice.Mode =CipherMode.CBC;
_encryptionservice.Key = _byteskey;
//_encryptionservice.IV = Encoding.ASCII.GetBytes("VIMSuitEncoding");

_decryptor = _encryptionservice.CreateDecryptor();

MemoryStream _memstreamencrypteddata = new MemoryStream(_bytesdata);
CryptoStream encStream = new CryptoStream(_memstreamencrypteddata, _decryptor, CryptoStreamMode.Read);
//_bytesdata = new byte[_bytesdata.Length];

try
{
_decryptedstringlength = encStream.Read(_bytesdata, 0, _bytesdata.Length);
}
catch (Exception ex)
{
throw new Exception("Error while writing encrypted data to the stream", ex);
}

encStream.Close();

//_encryptedstring = Convert.ToString(Encoding.ASCII.GetChars(_memstreamencrypteddata.ToArray())).Substring(0, _decryptedstringlength);

try
{
_encryptedstring = Convert.ToString(Encoding.ASCII.GetChars(_memstreamencrypteddata.ToArray())).Substring(0, _decryptedstringlength);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return _encryptedstring.Trim();
}
}
GeneralRe: Rijndael algo for Encryption and Decryption of Password Pin
led mike13-Mar-08 4:42
led mike13-Mar-08 4:42 
GeneralRe: Rijndael algo for Encryption and Decryption of Password Pin
salon13-Mar-08 18:00
salon13-Mar-08 18:00 
GeneralRe: Rijndael algo for Encryption and Decryption of Password Pin
Guffa15-Mar-08 23:54
Guffa15-Mar-08 23:54 
GeneralGeneral Architecture Advice Pin
Brady Kelly13-Mar-08 0:22
Brady Kelly13-Mar-08 0:22 
GeneralRe: General Architecture Advice Pin
led mike13-Mar-08 4:41
led mike13-Mar-08 4:41 
GeneralRe: General Architecture Advice Pin
Brady Kelly13-Mar-08 4:48
Brady Kelly13-Mar-08 4:48 
GeneralRe: General Architecture Advice Pin
led mike13-Mar-08 5:34
led mike13-Mar-08 5:34 
GeneralCreating a page to edit from Login Pin
Dave McCool12-Mar-08 23:16
Dave McCool12-Mar-08 23:16 
GeneralRe: Creating a page to edit from Login Pin
led mike13-Mar-08 4:35
led mike13-Mar-08 4:35 
GeneralCrystal report suppression problem Pin
tonymathewt12-Mar-08 19:07
professionaltonymathewt12-Mar-08 19:07 
QuestionCookies not setting in IE7 Pin
dboy22112-Mar-08 10:02
dboy22112-Mar-08 10:02 
GeneralJavaScript XPath help Pin
Gump61912-Mar-08 9:31
Gump61912-Mar-08 9:31 
GeneralRe: JavaScript XPath help Pin
led mike13-Mar-08 4:34
led mike13-Mar-08 4:34 
GeneralRe: JavaScript XPath help Pin
Shog916-Mar-08 7:03
sitebuilderShog916-Mar-08 7:03 
GeneralRe: JavaScript XPath help Pin
Gump61917-Mar-08 4:36
Gump61917-Mar-08 4:36 
GeneralRe: JavaScript XPath help Pin
Shog917-Mar-08 4:44
sitebuilderShog917-Mar-08 4:44 
GeneralRe: JavaScript XPath help Pin
Gump61917-Mar-08 4:50
Gump61917-Mar-08 4:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.