Jump to content
Xtreme .Net Talk

Search the Community

Showing results for tags 'decryption'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • New Member at Xtreme .Net Talk?
    • Meet and Greet
    • Announcements
  • .NET
    • General
    • Windows Forms
    • ASP.NET
    • Directory / File IO / Registry
    • Database / XML / Reporting
    • Network
    • Graphics and Multimedia
    • Interoperation / Office Integration
    • Deployment
    • Regular Expressions
    • Syntax Specific
  • Knowledge Base
    • Tutors Corner
    • Code Library
    • Quick Tips
  • Xtreme .Net Talk Members Area
    • Water Cooler
    • Suggestions, Bugs, and Comments

Blogs

There are no results to display.

Categories

  • Code Samples
  • Tutorials & Guides
  • Articles
  • Code Downloads

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


About Me


Location


Occupation


Visual Studio .NET Version


.NET Preferred Language


Skype


Facebook


Twitter ( X )

Found 1 result

  1. Good day one and all, Apologies if I'm not in the most suitable topic area for this. Can someone tell me why I'm getting a bad data error when I try using this decryption method? The encryption part works fine, but when decrypting the file I get the error: CryptographicExcpetion was unhandled Bad Data on the line fsDecrypted.Write(sr.ReadToEnd()) please see the code I'm trying to use: /// <summary> /// Encrypts a file - Not implemented /// </summary> /// <param name="sInputFilename">File to encrypt</param> /// <param name="sOutputFilename">Encrypted file name</param> /// <param name="sKey">Encryption Key</param> private void EncryptFile(string sInputFilename, string sOutputFilename, string sKey) { FileStream fsInput = new FileStream(sInputFilename, FileMode.Open, FileAccess.Read); FileStream fsEncrypted = new FileStream(sOutputFilename, FileMode.Create, FileAccess.Write); DESCryptoServiceProvider DES = new DESCryptoServiceProvider(); DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey); DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey); ICryptoTransform desencrypt = DES.CreateEncryptor(); CryptoStream cryptostream = new CryptoStream(fsEncrypted, desencrypt, CryptoStreamMode.Write); byte[] bytearrayinput = new byte[fsInput.Length - 1]; fsInput.Read(bytearrayinput, 0, bytearrayinput.Length); cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length); fsEncrypted.Close(); } /// <summary> /// Decrypts a file - Not implemented /// </summary> /// <param name="sInputFilename">File to decrypt</param> /// <param name="sOutputFilename">Decrypted file name</param> /// <param name="sKey">Decryption Key</param> static void DecryptFile(string sInputFilename, string sOutputFilename, string sKey) { DESCryptoServiceProvider DES = new DESCryptoServiceProvider(); //A 64 bit key and IV is required for this provider. //Set secret key For DES algorithm. DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey); //Set initialization vector. DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey); //Create a file stream to read the encrypted file back. FileStream fsread = new FileStream(sInputFilename, FileMode.Open, FileAccess.Read); //Create a DES decryptor from the DES instance. ICryptoTransform desdecrypt = DES.CreateDecryptor(); //Create crypto stream set to read and do a //DES decryption transform on incoming bytes. CryptoStream cryptostreamDecr = new CryptoStream(fsread, desdecrypt, CryptoStreamMode.Read); StreamReader sr = new StreamReader(cryptostreamDecr); //Print the contents of the decrypted file. StreamWriter fsDecrypted = new StreamWriter(sOutputFilename); fsDecrypted.Write(sr.ReadToEnd()); fsDecrypted.Flush(); fsDecrypted.Close(); } I'm using the same key for both "m43%gj&^", and the fact that it encrypts suggests that that is fine to use. Thanks in advance for your time. Jib
×
×
  • Create New...