RE: DES Encryption/Decryption of Word documents
From: Ivan Medvedev [MS] (ivanmed_at_online.microsoft.com)
Date: 07/10/03
- Previous message: Eugene V. Bobukh [MS]: "RE: Approach for Code Access Security?"
- In reply to: Manav Khanna: "DES Encryption/Decryption of Word documents"
- Next in thread: Manav Khanna: "RE: DES Encryption/Decryption of Word documents"
- Reply: Manav Khanna: "RE: DES Encryption/Decryption of Word documents"
- Reply: Manav Khanna: "RE: DES Encryption/Decryption of Word documents"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Wed, 09 Jul 2003 22:07:08 GMT
Manav -
The mistake is that you treat the encrypted content as text
(StreamReader.ReadToEnd returns a string). Encrypted data can be any bytes,
not necesserily representable by characters. Here is how to fix your
program: use the following code right after the call to SetKey in your
decrypt routine:
FileStream inputFile = new FileStream(inputFilename, FileMode.Open,
FileAccess.Read);
ICryptoTransform desDecryptor = DES.CreateDecryptor();
FileStream fsDecrypted = new FileStream(outputFilename,
FileMode.OpenOrCreate, FileAccess.Write );
CryptoStream cryptostreamDecryptor = new CryptoStream(fsDecrypted,
desDecryptor, CryptoStreamMode.Write);
try
{
byte[] buffer = new byte[inputFile.Length];
inputFile.Read(buffer, 0, buffer.Length);
cryptostreamDecryptor.Write(buffer, 0, buffer.Length);
}
--Ivan
- Previous message: Eugene V. Bobukh [MS]: "RE: Approach for Code Access Security?"
- In reply to: Manav Khanna: "DES Encryption/Decryption of Word documents"
- Next in thread: Manav Khanna: "RE: DES Encryption/Decryption of Word documents"
- Reply: Manav Khanna: "RE: DES Encryption/Decryption of Word documents"
- Reply: Manav Khanna: "RE: DES Encryption/Decryption of Word documents"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|