2

So I'm doing some testing with data encryption per a course I'm taking in school (for this assignment we're meant to use only a Windows environment), and I'm able to use Windows built-in "cipher.exe" tool just fine for what we need to do.

I made a small .txt file (my plain text), and I encrypted it using "cipher /e PlainText.txt" which has no error. However, I want to be able to view the ciphertext as well. How would one go about doing this? I tried logging in as a user that didn't have the proper access to the file and instead of seeing ciphertext it just comes up blank saying "Access Denied".

Thank you for any ideas.

usr
  • 168,620
  • 35
  • 240
  • 369
Sigterm
  • 127
  • 7
  • 1
    Use a tool that accesses the raw disk sectors. WinHex can open a volume, understand the file system and open a file in "raw mode". – usr Sep 01 '13 at 17:41
  • thanks for that; simple enough answer! i was trying to see if there was a way to view the text natively in Windows (or Linux out of curiosity) but I couldn't figure that one out. – Sigterm Sep 01 '13 at 18:32
  • I don't know if there is a way or not. That's why I'm not formally answering. I'm thinking of backup mode for CreateFile here... Might do the job. – usr Sep 01 '13 at 18:34
  • Well regardless of if it can be done natively or not, this gets the job done perfectly. Thanks again! – Sigterm Sep 01 '13 at 18:40
  • Actually, I just tried this again and unfortunately it seems to show the same hexidecimal information whether the text file is encrypted or not. When I load the txt file into WinHex it shows the hex values, as well as the plain text. And when I open the encrypted one in WinHex under a different user account it shows access denied again. Maybe I"m opening the encrypted files incorrectly? Sorry about the confusion. – Sigterm Sep 01 '13 at 20:29
  • You need to use "Open Disk" from the menu. Then WinHex parses the file system on its own. – usr Sep 02 '13 at 09:37

1 Answers1

2

The way you open an encrypted file in order to read its raw encrypted contents (e.g. for a backup/restore application) is to use the:

api functions.

Writing the code on the fly, in a hypothetical hybrid language:

void ExportEncryptedFileToStream(String filename, Stream targetStream)
{
   Pointer context;

   res = OpenEncryptedFileRaw("C:\Users\Ian\wallet.dat", 0, ref context);
   if (res <> ERROR_SUCCESS)
      RaiseWin32Error(res);
   try
   {
      res = ReadEncryptedFileRaw(exportCallback, null, context);
      if (res != ERROR_SUCCESS)
         RaiseWin32Error(res);
   }
   finally
   {
      CloseEncryptedFileRaw(context)
   }
}

function ExportCallback(pbData: PBYTE, pvCallbackContext: PVOID, ulLength: ULONG): DWORD
{
   Stream targetStream = Stream(pvCallbackContext);

   try
   {
      targetStream.Write(pbData, ulLength);
   }
   catch (Exception e)
   {
      return ERROR_WRITE_FAULT;
   }
   return ERROR_SUCCESS;
}

Note: Any code released into public domain. No attribution required.

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219