查看 NTFS (EFS) 上加密文件的密文

问题描述 投票:0回答:1

因此,我正在根据我在学校学习的课程进行一些数据加密测试(对于此作业,我们仅使用 Windows 环境),并且我能够使用 Windows 内置的“cipher.txt”。 exe”工具足以满足我们需要做的事情。

我制作了一个小的 .txt 文件(我的纯文本),并使用“cipher /e PlainText.txt”对其进行了加密,没有错误。但是,我也希望能够查看密文。人们会如何去做这件事呢?我尝试以没有正确访问该文件的用户身份登录,但没有看到密文,而是显示为空白,显示“访问被拒绝”。

感谢您的任何想法。

windows encryption ntfs encrypting-file-system
1个回答
3
投票

打开加密文件以读取其原始加密内容(例如备份/恢复应用程序)的方法是使用 Windows API 函数:

用假设的混合语言即时编写代码:

void ExportEncryptedFileToStream(String filename, Stream targetStream)
{
   // Code released into public domain. No attribution required.
   Pointer context;

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

该函数需要一个回调,系统将多次调用该回调,因为它会为您提供大块的加密数据:

function ExportCallback(pbData: PBYTE, pvCallbackContext: PVOID, ulLength: ULONG): DWORD
{
   // Get the Stream we passed as part of our context
   Stream targetStream = Stream(pvCallbackContext);
      
   try
   {
      targetStream.Write(pbData, ulLength);
   }
   catch (Exception e)
   {
      return ERROR_WRITE_FAULT; //a non-zero winerror error code
   }
   return ERROR_SUCCESS; //return success if we were successful
}
© www.soinside.com 2019 - 2024. All rights reserved.