Click here to Skip to main content
15,895,084 members
Home / Discussions / C#
   

C#

 
AnswerRe: araye Pin
Nagy Vilmos27-Apr-09 5:52
professionalNagy Vilmos27-Apr-09 5:52 
JokeRe: araye Pin
OriginalGriff27-Apr-09 6:16
mveOriginalGriff27-Apr-09 6:16 
AnswerRe: araye Pin
Rolando CC27-Apr-09 5:53
professionalRolando CC27-Apr-09 5:53 
AnswerRe: araye Pin
Rolando CC27-Apr-09 6:19
professionalRolando CC27-Apr-09 6:19 
QuestionfolderBrowserDialog is not visible while installing the application ? Pin
Dattatraya K27-Apr-09 5:29
Dattatraya K27-Apr-09 5:29 
AnswerRe: folderBrowserDialog is not visible while installing the application ? Pin
MikaEG27-Apr-09 9:54
MikaEG27-Apr-09 9:54 
GeneralRe: folderBrowserDialog is not visible while installing the application ? Pin
Dattatraya K27-Apr-09 19:55
Dattatraya K27-Apr-09 19:55 
Questioni need help with a cryptography exception! Pin
Roshanakak27-Apr-09 3:29
Roshanakak27-Apr-09 3:29 
I have this code for encryption-decryption some data, when i run it, it makes the exception: "Padding is invalid and cannot be removed"
I did everything i found in google or forums but none helped me.
I appreciate any ideas! Please help me!
This is the Code:

using System;<br />
using System.IO;<br />
using System.Text;<br />
using System.Security.Cryptography;<br />
<br />
<br />
	public sealed class Cryption<br />
	{<br />
		private RijndaelManaged Algorithm;<br />
		private MemoryStream memStream;<br />
		private ICryptoTransform EncryptorDecryptor;<br />
		private CryptoStream crStream;<br />
		private StreamWriter strWriter;<br />
		private StreamReader strReader;<br />
        <br />
		private string m_key;<br />
		private string m_iv;<br />
<br />
		private byte[] key;<br />
		private byte[] iv;<br />
<br />
		private string pwd_str;<br />
		private byte[] pwd_byte;<br />
<br />
		public Cryption(string key_val, string iv_val)<br />
		{<br />
			key = new byte[32];<br />
			iv = new byte[32];<br />
<br />
			int i;<br />
			m_key = key_val;<br />
			m_iv = iv_val;<br />
<br />
			for(i=0;i<m_key.length;i++)><br />
			{<br />
				key[i] = Convert.ToByte(m_key[i]);<br />
			}<br />
			for(i=0;i<m_iv.length;i++)><br />
			{<br />
				iv[i] = Convert.ToByte(m_iv[i]);<br />
			}<br />
<br />
		}<br />
<br />
<br />
		public string Encrypt(string s)<br />
		{<br />
            Algorithm = new RijndaelManaged();<br />
<br />
			Algorithm.BlockSize = 256;<br />
			Algorithm.KeySize = 256;<br />
            Algorithm.Padding = PaddingMode.PKCS7;<br />
<br />
			memStream = new MemoryStream();<br />
<br />
			EncryptorDecryptor = Algorithm.CreateEncryptor(key,iv);<br />
<br />
			crStream = new CryptoStream(memStream, EncryptorDecryptor, CryptoStreamMode.Write);<br />
<br />
			strWriter = new StreamWriter(crStream);<br />
<br />
			strWriter.Write(s);<br />
<br />
			strWriter.Flush();<br />
			crStream.FlushFinalBlock();<br />
<br />
			pwd_byte = new byte[memStream.Length];<br />
			memStream.Position = 0;<br />
			memStream.Read(pwd_byte,0,(int)pwd_byte.Length);<br />
<br />
            pwd_str= new UnicodeEncoding().GetString(pwd_byte);             <br />
			return pwd_str;<br />
		}<br />
<br />
<br />
		public string Decrypt(string s)<br />
		{<br />
			Algorithm = new RijndaelManaged();<br />
<br />
			Algorithm.BlockSize = 256;<br />
			Algorithm.KeySize = 256;<br />
<br />
			MemoryStream memStream = new MemoryStream(new UnicodeEncoding().GetBytes(s));<br />
    <br />
			ICryptoTransform EncryptorDecryptor = Algorithm.CreateDecryptor(key,iv);<br />
			memStream.Position = 0;<br />
			CryptoStream crStream = new CryptoStream(memStream, EncryptorDecryptor, CryptoStreamMode.Read);<br />
			strReader = new StreamReader(crStream);<br />
            <br />
            return strReader.ReadToEnd();<br />
		}<br />
		<br />
	}<br />

AnswerRe: i need help with a cryptography exception! Pin
Simon P Stevens27-Apr-09 5:10
Simon P Stevens27-Apr-09 5:10 
QuestionRe: i need help with a cryptography exception! Pin
Roshanakak27-Apr-09 18:34
Roshanakak27-Apr-09 18:34 
AnswerRe: i need help with a cryptography exception! Pin
Simon P Stevens27-Apr-09 21:41
Simon P Stevens27-Apr-09 21:41 
GeneralRe: i need help with a cryptography exception! Pin
Roshanakak28-Apr-09 0:43
Roshanakak28-Apr-09 0:43 
GeneralRe: i need help with a cryptography exception! Pin
Simon P Stevens28-Apr-09 1:30
Simon P Stevens28-Apr-09 1:30 
QuestionGridview Pin
pginnare27-Apr-09 3:28
pginnare27-Apr-09 3:28 
AnswerRe: Gridview Pin
AnilJayanti27-Apr-09 3:40
AnilJayanti27-Apr-09 3:40 
AnswerRe: Gridview Pin
Jimmanuel27-Apr-09 4:17
Jimmanuel27-Apr-09 4:17 
Questionhow to select or get all values in listbox at pageload Pin
sakthi06karthi27-Apr-09 3:14
sakthi06karthi27-Apr-09 3:14 
AnswerRe: how to select or get all values in listbox at pageload Pin
AnilJayanti27-Apr-09 3:25
AnilJayanti27-Apr-09 3:25 
Questionc# interoperability with TCL Pin
Seraph_summer27-Apr-09 2:28
Seraph_summer27-Apr-09 2:28 
AnswerRe: c# interoperability with TCL Pin
Michael Bookatz27-Apr-09 2:52
Michael Bookatz27-Apr-09 2:52 
QuestionHow to get returned value from TableAdapter.Update method ? Pin
hdv21227-Apr-09 2:27
hdv21227-Apr-09 2:27 
AnswerRe: How to get returned value from TableAdapter.Update method ? Pin
musefan27-Apr-09 3:13
musefan27-Apr-09 3:13 
GeneralRe: How to get returned value from TableAdapter.Update method ? Pin
hdv21227-Apr-09 3:32
hdv21227-Apr-09 3:32 
QuestionProblem : Add New Window Form in c# Pin
ddravin200027-Apr-09 2:24
ddravin200027-Apr-09 2:24 
AnswerRe: Problem : Add New Window Form in c# Pin
Michael Bookatz27-Apr-09 2:50
Michael Bookatz27-Apr-09 2: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.