Click here to Skip to main content
15,890,336 members
Home / Discussions / C#
   

C#

 
GeneralRe: parameter name from params Pin
Nick Seng28-Jul-03 17:22
Nick Seng28-Jul-03 17:22 
GeneralProcess Priority Pin
eggie528-Jul-03 10:51
eggie528-Jul-03 10:51 
GeneralRe: Process Priority Pin
Julian Bucknall [MSFT]28-Jul-03 11:51
Julian Bucknall [MSFT]28-Jul-03 11:51 
GeneralRe: Process Priority Pin
eggie528-Jul-03 11:58
eggie528-Jul-03 11:58 
GeneralRe: Process Priority Pin
David Stone28-Jul-03 12:28
sitebuilderDavid Stone28-Jul-03 12:28 
GeneralOT Pin
J. Dunlap28-Jul-03 12:17
J. Dunlap28-Jul-03 12:17 
GeneralEncrypting\Decrypting Pin
draco_iii28-Jul-03 9:39
draco_iii28-Jul-03 9:39 
GeneralRe: Encrypting\Decrypting Pin
Julian Bucknall [MSFT]28-Jul-03 11:28
Julian Bucknall [MSFT]28-Jul-03 11:28 
Not sure what's going on for you. Maybe it's something in the code you *don't* show <g>.

The following works just fine for me (I separated out the creation of some the objects into separate statements for readability):

class Class1 {
  static void Encrypt(string inputFile, string outputFile) {
    FileStream fsin = new FileStream(inputFile, FileMode.Open, FileAccess.Read);

    FileStream fsout = new FileStream(outputFile, FileMode.Create, FileAccess.Write);

    byte[] key = new byte[] {22,184,62,104,66,100,202,17,91,254,197,181,224,62,36,138,128,227,146,111,134,83,241,125};
    byte[] iv = new byte[] {216,237,102,42,142,11,133,104};

    TripleDESCryptoServiceProvider tripleDes = new TripleDESCryptoServiceProvider();
    ICryptoTransform t = tripleDes.CreateEncryptor(key, iv);

    CryptoStream cs = new CryptoStream(fsout, t, CryptoStreamMode.Write);

    int len = (int) fsin.Length;
    byte[] buffer = new byte[len];
    len = fsin.Read(buffer, 0, len);
    cs.Write(buffer, 0, len);

    cs.Close();
    fsout.Close();
    fsin.Close();
  }

  static void Decrypt(string inputFile, string outputFile) {
    FileStream fsin = new FileStream(inputFile, FileMode.Open, FileAccess.Read);

    FileStream fsout = new FileStream(outputFile, FileMode.Create, FileAccess.Write);

    byte[] key = new byte[] {22,184,62,104,66,100,202,17,91,254,197,181,224,62,36,138,128,227,146,111,134,83,241,125};
    byte[] iv = new byte[] {216,237,102,42,142,11,133,104};

    TripleDESCryptoServiceProvider tripleDes = new TripleDESCryptoServiceProvider();
    ICryptoTransform t = tripleDes.CreateDecryptor(key, iv);

    CryptoStream cs = new CryptoStream(fsout, t, CryptoStreamMode.Write);

    int len = (int) fsin.Length;
    byte[] buffer = new byte[len];
    len = fsin.Read(buffer, 0, len);
    cs.Write(buffer, 0, len);

    cs.Close();
    fsout.Close();
    fsin.Close();
  }

  static void Main(string[] args) {

    Console.WriteLine("Starting encryption...");
    Encrypt(@"c:\test.txt", @"c:\test.enc");
    Console.WriteLine("...done");

    Console.WriteLine("Starting decryption...");
    Decrypt(@"c:\test.enc", @"c:\test.dec");
    Console.WriteLine("...done");

    Console.ReadLine();
  }
}



Cheers, Julian
Program Manager, C#

This posting is provided "AS IS" with no warranties, and confers no rights.
GeneralRe: Encrypting\Decrypting Pin
draco_iii29-Jul-03 2:13
draco_iii29-Jul-03 2:13 
QuestionInstaller &quot;Catch 22&quot; with versioning? Pin
Arun Bhalla28-Jul-03 9:15
Arun Bhalla28-Jul-03 9:15 
GeneralIn Bitmap hell Pin
RB@Emphasys28-Jul-03 8:13
RB@Emphasys28-Jul-03 8:13 
GeneralRe: In Bitmap hell Pin
Not Active28-Jul-03 9:25
mentorNot Active28-Jul-03 9:25 
Questionhow to use SendMessage() from C#?? Pin
misterbear28-Jul-03 7:57
misterbear28-Jul-03 7:57 
AnswerI know one more thing... Pin
misterbear28-Jul-03 8:18
misterbear28-Jul-03 8:18 
GeneralRe: I know one more thing... Pin
J. Dunlap28-Jul-03 8:51
J. Dunlap28-Jul-03 8:51 
GeneralRe: I know one more thing... Pin
misterbear28-Jul-03 10:35
misterbear28-Jul-03 10:35 
GeneralRe: I know one more thing... Pin
J. Dunlap28-Jul-03 10:43
J. Dunlap28-Jul-03 10:43 
GeneralRe: I know one more thing... Pin
Eric Gunnerson (msft)28-Jul-03 11:17
Eric Gunnerson (msft)28-Jul-03 11:17 
GeneralRe: I know one more thing... Pin
leppie28-Jul-03 11:15
leppie28-Jul-03 11:15 
GeneralRe: I know one more thing... Pin
J. Dunlap28-Jul-03 11:21
J. Dunlap28-Jul-03 11:21 
GeneralRe: I know one more thing... Pin
leppie28-Jul-03 11:27
leppie28-Jul-03 11:27 
GeneralHttpWebRequest Timeout Pin
albean28-Jul-03 5:13
albean28-Jul-03 5:13 
GeneralRe: HttpWebRequest Timeout Pin
Arun Bhalla28-Jul-03 5:35
Arun Bhalla28-Jul-03 5:35 
GeneralRe: HttpWebRequest Timeout Pin
albean28-Jul-03 6:08
albean28-Jul-03 6:08 
GeneralRe: HttpWebRequest Timeout Pin
Arun Bhalla28-Jul-03 6:11
Arun Bhalla28-Jul-03 6:11 

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.