Click here to Skip to main content
15,891,943 members
Home / Discussions / C#
   

C#

 
GeneralRe: Best way to read ASCII input Pin
spainchaud22-Feb-10 8:48
spainchaud22-Feb-10 8:48 
GeneralRe: Best way to read ASCII input Pin
Dr.Walt Fair, PE22-Feb-10 9:23
professionalDr.Walt Fair, PE22-Feb-10 9:23 
GeneralRe: Best way to read ASCII input Pin
Scott Serl22-Feb-10 10:13
Scott Serl22-Feb-10 10:13 
QuestionReports Pin
muka6622-Feb-10 3:22
muka6622-Feb-10 3:22 
AnswerRe: Reports Pin
Not Active22-Feb-10 3:42
mentorNot Active22-Feb-10 3:42 
GeneralRe: Reports Pin
Anubhava Dimri22-Feb-10 18:18
Anubhava Dimri22-Feb-10 18:18 
QuestionDecrypting a text using Rijndael Pin
3bood.ghzawi22-Feb-10 2:52
3bood.ghzawi22-Feb-10 2:52 
QuestionDecrypting a text using Rijndael Pin
3bood.ghzawi22-Feb-10 2:51
3bood.ghzawi22-Feb-10 2:51 
Hi all, i have been using a Rijndael algorithm to encrypt and decrypt a sequence of bytes, but when i run the code i get the following exeption "Padding is invalid and cannot be removed.", this exeption belongs to decrypt function at line <code>int decryptedByteCount = cryptoStream.Read(pTextBytes, 0, pTextBytes.Length);
</code>


i writ my code here:

<pre>public static byte[] Encrypt(byte[] clearData)
{
System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
//Get your key from config file to open the lock!
string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));

MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
byte[] keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
hashmd5.Clear();

Rijndael rijKey = Rijndael.Create();
rijKey.Mode = CipherMode.;
rijKey.Padding = PaddingMode.PKCS7;
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms,rijKey.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(clearData, 0, clearData.Length);
cs.FlushFinalBlock();
byte[] cipherTextBytes = ms.ToArray();
ms.Close();
cs.Close();

return cipherTextBytes;
}

public static byte[] Decrypt(byte[] encryptedData)
{
System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
//Get your key from config file to open the lock!
string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));
MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
byte[] keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
hashmd5.Clear();

Rijndael rijKey = Rijndael.Create();
rijKey.Mode = CipherMode.ECB;
rijKey.Padding = PaddingMode.PKCS7;
MemoryStream memoryStream = new MemoryStream(encryptedData);
CryptoStream cryptoStream = new CryptoStream(memoryStream, rijKey.CreateDecryptor(),
CryptoStreamMode.Read);
byte[] pTextBytes = new byte[encryptedData.Length];
int decryptedByteCount = cryptoStream.Read(pTextBytes, 0, pTextBytes.Length);
memoryStream.Close();
cryptoStream.Close();
return pTextBytes;
}</pre>

thanks.....................Rose | [Rose]
AnswerRe: Decrypting a text using Rijndael Pin
Not Active22-Feb-10 3:13
mentorNot Active22-Feb-10 3:13 
AnswerRe: Decrypting a text using Rijndael Pin
Keith Barrow22-Feb-10 4:20
professionalKeith Barrow22-Feb-10 4:20 
AnswerRe: Decrypting a text using Rijndael Pin
Luc Pattyn22-Feb-10 4:51
sitebuilderLuc Pattyn22-Feb-10 4:51 
GeneralRe: Decrypting a text using Rijndael Pin
Keith Barrow22-Feb-10 5:03
professionalKeith Barrow22-Feb-10 5:03 
GeneralRe: Decrypting a text using Rijndael Pin
Luc Pattyn22-Feb-10 5:49
sitebuilderLuc Pattyn22-Feb-10 5:49 
QuestionDatatable Pin
jojoba201122-Feb-10 2:36
jojoba201122-Feb-10 2:36 
AnswerRe: Datatable Pin
Not Active22-Feb-10 3:12
mentorNot Active22-Feb-10 3:12 
GeneralRe: Datatable Pin
jojoba201122-Feb-10 4:25
jojoba201122-Feb-10 4:25 
Questionidentify authorised user on web method using c# Pin
dalila y22-Feb-10 2:01
dalila y22-Feb-10 2:01 
AnswerRe: identify authorised user on web method using c# Pin
Not Active22-Feb-10 2:04
mentorNot Active22-Feb-10 2:04 
GeneralRe: identify authorised user on web method using c# Pin
dalila y22-Feb-10 5:27
dalila y22-Feb-10 5:27 
GeneralRe: identify authorised user on web method using c# Pin
Not Active22-Feb-10 5:47
mentorNot Active22-Feb-10 5:47 
QuestionMDI Problem in C#.Net? Pin
Pawan Kiran22-Feb-10 1:58
Pawan Kiran22-Feb-10 1:58 
AnswerRe: MDI Problem in C#.Net? Pin
DaveyM6922-Feb-10 8:39
professionalDaveyM6922-Feb-10 8:39 
GeneralRe: MDI Problem in C#.Net? Pin
Pawan Kiran22-Feb-10 18:15
Pawan Kiran22-Feb-10 18:15 
QuestionParse javascript Pin
Ziga122-Feb-10 1:37
Ziga122-Feb-10 1:37 
AnswerRe: Parse javascript Pin
Not Active22-Feb-10 2:02
mentorNot Active22-Feb-10 2:02 

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.