Click here to Skip to main content
15,180,782 members
Home / Discussions / C#
   

C#

 
GeneralI Got It! I think? Pin
redfish3416-Jan-06 10:19
Memberredfish3416-Jan-06 10:19 
GeneralRe: I Got It! I think? Pin
J4amieC16-Jan-06 22:57
MemberJ4amieC16-Jan-06 22:57 
QuestionSend a double click? Pin
melanieab16-Jan-06 8:15
Membermelanieab16-Jan-06 8:15 
AnswerRe: Send a double click? Pin
Judah Gabriel Himango16-Jan-06 9:32
sponsorJudah Gabriel Himango16-Jan-06 9:32 
QuestionJoinMulticastGroup from multiple processes on same machine Pin
John Fisher16-Jan-06 7:30
MemberJohn Fisher16-Jan-06 7:30 
QuestionEncryption and Decryption Problems Pin
thepolishguy16-Jan-06 6:49
Memberthepolishguy16-Jan-06 6:49 
AnswerRe: Encryption and Decryption Problems Pin
John Fisher16-Jan-06 7:23
MemberJohn Fisher16-Jan-06 7:23 
GeneralRe: Encryption and Decryption Problems Pin
thepolishguy16-Jan-06 7:37
Memberthepolishguy16-Jan-06 7:37 
Okay, here's the code I'm using to encrypt:

public void EncryptData()
{
FileStream fs=null;
if(File.Exists(Directory.GetCurrentDirectory() + "\\c#.ini") == false)
{
fs=new FileStream(Directory.GetCurrentDirectory() + "\\c#.ini",
System.IO.FileMode.CreateNew);

}
else
{
fs=new FileStream(Directory.GetCurrentDirectory() + "\\c#.ini",
System.IO.FileMode.Append);
}


byte[] Key = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
byte[] IV = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10,
0x11, 0x12, 0x13, 0x14, 0x15, 0x16};

RijndaelManaged RMCrypto=new RijndaelManaged();
System.Security.Cryptography.CryptoStream cryption=new CryptoStream(fs,
RMCrypto.CreateEncryptor(Key, IV), CryptoStreamMode.Write);
StreamWriter tnWriter2 = new StreamWriter(cryption,
System.Text.Encoding.Unicode);
tnWriter2.WriteLine(log);
tnWriter2.Close();
fs.Close();
}

And here's the code for Decrypting:

private void DecryptDataLog()
{
FileStream read=new FileStream(currPath + "\\c#.ini",
System.IO.FileMode.OpenOrCreate);

byte[] Key = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10,
0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
byte[] IV = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10,
0x11, 0x12, 0x13, 0x14, 0x15, 0x16};

RijndaelManaged RMCrypto=new RijndaelManaged();
System.Security.Cryptography.CryptoStream cryption=new CryptoStream(read,
RMCrypto.CreateDecryptor(Key, IV), CryptoStreamMode.Read);
StreamReader tnReader = new StreamReader(cryption,
System.Text.Encoding.Unicode);
this.textBox1.Text=tnReader.ReadToEnd();

tnReader.Close();
read.Close();


}

When the file I'm writing to has more than one line, the first few characters of the 2nd, 3rd, etc lines of encrypted text show up as gibberish, while the rest of the line is OK.


GeneralRe: Encryption and Decryption Problems Pin
John Fisher16-Jan-06 7:50
MemberJohn Fisher16-Jan-06 7:50 
GeneralRe: Encryption and Decryption Problems Pin
thepolishguy16-Jan-06 8:03
Memberthepolishguy16-Jan-06 8:03 
GeneralRe: Encryption and Decryption Problems Pin
John Fisher16-Jan-06 9:20
MemberJohn Fisher16-Jan-06 9:20 
GeneralRe: Encryption and Decryption Problems Pin
thepolishguy16-Jan-06 9:29
Memberthepolishguy16-Jan-06 9:29 
GeneralRe: Encryption and Decryption Problems Pin
John Fisher16-Jan-06 9:33
MemberJohn Fisher16-Jan-06 9:33 
GeneralRe: Encryption and Decryption Problems Pin
thepolishguy16-Jan-06 9:52
Memberthepolishguy16-Jan-06 9:52 
GeneralRe: Encryption and Decryption Problems Pin
John Fisher16-Jan-06 10:09
MemberJohn Fisher16-Jan-06 10:09 
AnswerRe: Encryption and Decryption Problems Pin
Guffa16-Jan-06 9:21
MemberGuffa16-Jan-06 9:21 
QuestionPrevent Multiple Forms Pin
dimx216-Jan-06 5:49
Memberdimx216-Jan-06 5:49 
AnswerRe: Prevent Multiple Forms Pin
exhaulted16-Jan-06 6:11
Memberexhaulted16-Jan-06 6:11 
AnswerRe: Prevent Multiple Forms Pin
tarasn16-Jan-06 6:16
Membertarasn16-Jan-06 6:16 
GeneralRe: Prevent Multiple Forms Pin
dimx216-Jan-06 6:54
Memberdimx216-Jan-06 6:54 
AnswerRe: Prevent Multiple Forms Pin
microsoc16-Jan-06 16:57
Membermicrosoc16-Jan-06 16:57 
AnswerRe: Prevent Multiple Forms Pin
Hesham Desouky16-Jan-06 23:17
MemberHesham Desouky16-Jan-06 23:17 
QuestionSize of the object Pin
vSoares16-Jan-06 5:49
professionalvSoares16-Jan-06 5:49 
AnswerRe: Size of the object Pin
John Fisher16-Jan-06 7:20
MemberJohn Fisher16-Jan-06 7:20 
Questionclosing an application Pin
Mridang Agarwalla16-Jan-06 5:42
MemberMridang Agarwalla16-Jan-06 5:42 

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.