RE: DES Encryption/Decryption of Word documents

From: Ivan Medvedev [MS] (ivanmed_at_online.microsoft.com)
Date: 07/10/03

  • Next message: Ivan Medvedev [MS]: "RE: Code Group Question"
    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


  • Next message: Ivan Medvedev [MS]: "RE: Code Group Question"

    Relevant Pages

    • Re: CryptoStream makes encrypted data bigger than original string
      ... ict = m_csp.CreateEncryptor; ... Console.WriteLine("Enc - ", hexString); ... >> While encrypting data with DES through CryptoStream makes encrypted data ... bigger than original string. ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: Obtaining length of binary string
      ... >> I read encrypted data from a server and save it in a variable. ... > It is right since you say it's a binary string. ... OP to selectively decide whether he wants characters or bytes to be ...
      (comp.lang.perl.misc)
    • Re: Copying string to byte array
      ... >>byte array and I at the moment I am confident I can figure out how to do ... > Dim sSomeString As String ... > Dim btSomeByteArray() As Byte ... I need to convert that (encrypted data such as that) to a byte array to ...
      (microsoft.public.vb.general.discussion)
    • Re: Encrypted Data Storage Size
      ... CAPICOM can convert the binary encrypted data to/from a string. ... a 50 character database column. ...
      (microsoft.public.platformsdk.security)
    • RE: DES Encryption/Decryption of Word documents
      ... Thanks a lot for your help, Ivan. ... >The mistake is that you treat the encrypted content as ... >(StreamReader.ReadToEnd returns a string). ... Encrypted data ...
      (microsoft.public.dotnet.security)

  • Quantcast