自动文件加密演示

2023 年 4 月 25 日 | 0评论

下载 EaseFilter Encryption Filter SDK 安装文件
下载 EaseFilter Encryption Filter SDK压缩文件

Auto File Encryption Demo 是使用 EaseFilter Encryption Filter Driver(EEFD) SDK 开发的,它演示了如何对文件进行透明加密,只允许授权进程或用户读取加密文件,未授权进程或用户只能获取加密文件的原始密文。使用 EEFD 可以实现安全的文件共享解决方案,它允许你透明地分发加密文件,允许你在加密文件中嵌入数字版权管理(DRM),控制只有授权用户或进程才能读取加密文件。你可以随时随地授予或撤销分发加密文件的访问权限。

如何开发自动文件加密应用程序

使用 EEFD SDK,开发自动文件加密应用程序非常简单。EEFD 提供全面的安全解决方案,用于开发透明的访问文件级加密产品,对新建文件进行透明加密,在客户自定义策略的控制下授权或阻止访问加密/解密。

EEFD SDK 为不同编程语言提供了开发 Windows 加密应用程序的 API,并提供了 C++/C# 演示源代码,以演示如何使用 EEFD API。除了 C++ 和 C# 语言外,所有其他可以调用 Win32 本地 API 的语言都可以使用 EEFD API 开发安全应用程序。

设置自动文件加密过滤规则

要在应用程序中使用 EEFD,您的应用程序需要设置一个或多个过滤规则,作为过滤驱动程序的文件控制策略。自动文件加密过滤规则包括文件过滤掩码,它可以管理要加密的文件,默认情况下,文件过滤掩码是文件夹,它会加密文件夹中的所有文件。如果只想加密特定文件类型的文件,可以将文件过滤掩码设置为特定文件类型,但要确保应用程序不会生成未包含在文件过滤掩码中的文件,否则就不会加密。例如,Microsoft Office 总是会生成不带文件扩展名的临时文件,所以如果你将文件过滤屏蔽设置为只针对特定文件类型,那么这些临时文件就不会被自动加密。

使用 EEFD API "AddFileFilterRule "设置文件加密过滤规则非常简单,只需在文件过滤规则中设置自动加密文件夹并启用加密功能即可,如下所示:

/// <summary>
/// Add the new filter rule to the filter driver.
/// </summary>
/// <param name="accessFlag">access control rights of the file IO to the files which match the filter mask</param>
/// <param name="filterMask">the filter rule file filter mask, it must be unique.</param>
/// <param name="isResident">if it is true, the filter rule will be added to the registry, get protection in boot time.</param>
/// <param name="filterRuleId">the id to identify the filter rule, it will show up in messageId field of messageSend structure if the callback is registered</param>
/// <returns></returns>
[DllImport("FilterAPI.dll", SetLastError = true)]
public static extern bool AddFileFilterRule(
uint accessFlag,
[MarshalAs(UnmanagedType.LPWStr)]string filterMask,
bool isResident,
uint filterRuleId );

 //the code snippet to encrypt the file with the file filter rule.

 FilterControl filterControl = new FilterControl();
 FilterAPI.FilterType filterType = FilterAPI.FilterType.CONTROL_FILTER | FilterAPI.FilterType.ENCRYPTION_FILTER | FilterAPI.FilterType.PROCESS_FILTER;
 int filterConnectionThreads = 5;
 int connectionTimeOut = 30;
 string licenseKey = "your license key";
 string lastError = string.Empty;
 filterControl.StartFilter(filterType,filterConnectionThreads, GlobalConfig.ConnectionTimeOut, licenseKey, ref lastError);

 //setup a file filter rule for folder encryptFolder
 FileFilter fileFilter = new FileFilter("c:\\encryptionFolder\\*");
                
 //enable the encryption for the filter rule.
 fileFilter.EnableEncryption = true;
                           
 //setup the 256bits encryption key,put your own encryption key here
 byte[] encryptionKey =  {0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4};
 fileFilter.EncryptionKey = encryptionKey;

 //add the encryption file filter rule to the filter control
 filterControl.AddFilter(fileFilter);
                        

设置授权白名单程序和未授权黑名单程序

使用 EEFD SDK,您可以设置控制策略来保护加密文件,防止敏感文件被读取或复制。有了访问控制策略,你就可以设置白名单进程或可以读取加密文件的用户,他们可以获取加密文件的明文。你可以设置黑名单进程或不能读取加密文件的用户,他们将获得加密文件的原始密码文本。有两个选项可以设置白名单和黑名单进程或用户。

  1. 设置加密过滤规则,默认情况下,所有进程或用户都不能读取加密文件,它们都在黑名单中。如果要允许特定进程或用户,则需要为这些进程或用户添加加密访问权限。这就是实现零信任解决方案的方法。
  2. 设置加密过滤规则时,默认情况下所有进程或用户都会读取加密文件,它们都在白名单中。如果要允许特定进程或用户,则需要添加没有加密访问权限的进程或用户。

如果你想将加密文件上载或分发到组织之外的地方,并希望加密文件保持加密状态,你需要将上载或分发加密文件的进程添加到黑名单中。例如,你可以将备份进程、资源管理器或 outlook 进程添加到黑名单中,那么这些进程就会在加密文件被复制出去或上传到互联网后保持加密状态。

使用 DRM 安全共享文件

通过加密文件中的嵌入式 DRM,您可以保护和监控您的关键业务文档,如知识产权和产品设计,无论其在何处生存或移动--跨越设备、应用程序、云服务和内部部署。在组织内外安全共享信息。使用额外的数字版权管理数据加密文件,您可以使用自定义 DRM 控制加密文件,使加密文件过期,随时随地授予或撤销对加密文件的控制权,即使这些文件已被分发。EEFD 支持数百种文件类型,包括 Microsoft Office 文件、Adobe PDF、源代码(java、cpp 等)、2D 和 3D CAD 文件(dwg、prt、stp 等)。

在加密文件中嵌入自定义 DRM 数据

要在加密文件中嵌入自定义 DRM 数据并使用唯一密钥加密文件,需要将过滤器属性 "EnableEncryptionKeyFromService "设为 true,并设置 OnFilterRequestEncryptKey 的回调函数。有了这个设置,创建新文件时就会调用 OnFilterRequestEncryptKey 的回调函数,在回调函数中,你可以将自定义标签数据作为头添加到新创建的加密文件中。您还可以为新创建的文件设置自己独有的自定义加密密钥,这样就可以用每个文件独有的密钥加密文件,并用自己的解决方案管理加密密钥。


//enable the encryption key from service, you can append the custom DRM data
fileFilter.EnableEncryptionKeyFromService = true;
//in the callback function OnFilterRequestEncryptKey, you can authorize the file access in the callback function
fileFilter.OnFilterRequestEncryptKey += OnFilterRequestEncryptKey;
  
public void OnFilterRequestEncryptKey(object sender, EncryptEventArgs e)
{
    e.ReturnStatus = NtStatus.Status.Success;

    if (e.IsNewCreatedFile)
    {
        //if you want to block the new file creation, you can return accessdenied status.
        //e.ReturnStatus = NtStatus.Status.AccessDenied;

        //if you want to the file being created without encryption, return below status.
        //e.ReturnStatus = NtStatus.Status.FileIsNoEncrypted;

        //for the new created file, you can add your custom tag data to the header of the encyrpted file.
        //here we just add the file name as the tag data.
        e.EncryptionTag = UnicodeEncoding.Unicode.GetBytes(e.FileName);
    }
    else
    {
        //this is the encrytped file open request, request the encryption key and iv.

        //if you want to block encrypted file being opened, you can return accessdenied status.
        //e.ReturnStatus = NtStatus.Status.AccessDenied;

        //if you want to return the raws encrypted data for this encrypted file, return below status.
        //e.ReturnStatus = NtStatus.Status.FileIsEncrypted;

        //here is the tag data if you set custom tag data when the new created file requested the key.
        byte[] tagData = e.EncryptionTag;
    }

    //here is the encryption key for the encrypted file, you can set it with your own key.
    e.EncryptionKey = Utils.GetKeyByPassPhrase(GlobalConfig.MasterPassword, 32);
           
    //if you want to use your own iv for the encrypted file, set the value here, 
    //or don't set the iv here, then the unique auto generated iv will be assigned to the file.
    //e.IV = Utils.GetIVByPassPhrase(GlobalConfig.MasterPassword);

}

创建自己的定制 DRM 数据

要将 DRM 数据嵌入到加密文件中,您可以使用自己的自定义 DRM 数据,也可以使用我们内置的 DRM 数据,其结构格式如下,过滤器驱动程序支持如下:

  1. 您可以在 AESFlags 中启用“Flags_Enabled_Expire_Time”标志来设置到期日期,这样加密的文件只能在到期日期之前访问。
  2. 您可以设置计算机 ID,并在 AESFlags 中启用“Flags_Enabled_Check_Computer_Id”标志,只有具有相同计算机 ID 的计算机才能访问加密文件。
  3. 您可以设置用户名验证,并在AESFlags中启用标志“Flags_Enabled_Check_UserName”,如果IncludeUserNames不为空,则只有列表中的用户可以访问加密文件,如果ExcludeUserNames不为空,则所有用户 列表中的用户无法访问加密文件。
  4. 您可以在 AESFlags 中启用“Flags_Enabled_Check_ProcessName”标志来设置进程名称验证,如果 IncludeProcessNames 不为空,则只有列表中的进程可以访问加密文件,如果 ExcludeProcessNames 不为空,则所有进程 列表中的用户无法访问加密文件。

typedef enum _AESFlags
{
    Flags_Enabled_Expire_Time			=	0x00000010, 
    Flags_Enabled_Check_ProcessName		=	0x00000020, 
    Flags_Enabled_Check_UserName		=	0x00000040, 
    Flags_Enabled_Check_AccessFlags		=	0x00000080, 
    Flags_Enabled_Check_User_Permit		=	0x00000100, 
    Flags_AES_Key_Was_Embedded			=	0x00000200, 
    Flags_Request_AccessFlags_From_User	=	0x00000400, 
    Flags_Request_IV_And_Key_From_User	=	0x00000800, 
    Flags_Enabled_Check_Computer_Id		=	0x00001000, 
    Flags_Enabled_Check_User_Password	=	0x00002000, 

}AESFlags;

typedef struct _AES_TAG_CONTROL_DATA 
{
    ULONG		VerificationKey;
    ULONG		AESFlags;
    LONGLONG    CreationTime;
    LONGLONG    ExpireTime;
    ULONG		AccessFlags;
    ULONG		LengthOfIncludeProcessNames;
    ULONG		OffsetOfIncludeProcessNames;
    ULONG		LengthOfExcludeProcessNames;
    ULONG		OffsetOfExcludeProcessNames;
    ULONG		LengthOfIncludeUserNames;
    ULONG		OffsetOfIncludeUserNames;
    ULONG		LengthOfExcludeUserNames;
    ULONG		OffsetOfExcludeUserNames;
    ULONG		LengthOfAccountName;
    ULONG		OffsetOfAccountName;
    ULONG		LengthOfComputerId;
    ULONG		OffsetOfComputerId;
    ULONG		LengthOfUserPassword;
    ULONG		OffsetOfUserPassword;

    //the data store here.
    //IncludeProcessNames;
    //ExcludeProcessNames;
    //IncludeUserNames;
    //ExcludeUserNames;
    //AccountNames;
    //ComputerId;
    //UserPassword;
    
} AES_TAG_CONTROL_DATA, *PAES_TAG_CONTROL_DATA;

最新文章

Process Monitor SDK
File Security Filter Driver SDK
Using EaseFilter Filter Driver SDK
EEFD Transparent File Encryption SDK
EaseFilter File Access Control SDK
EaseFilter File Access Monitor SDK
Process Control SDK
Registry Protection SDK 自动文件加密演示
文件保护器分步演示
文件监视器分步演示
文件访问控制列表
认证与授权
零信任文件访问安全
黑名单和白名单
网络文件监控和保护器
阻止文件访问 USB 驱动器
设置可信进程权限
使用标头加密文件
随时随地加密文件
跟踪应用程序中的文件更改
如何设置文件访问权限
文件访问过滤规则

文件知识库
  • 了解文件 I/O
  • 了解文件加密
  • 了解 I/O 系统
  • 了解IRP
  • IRP 与快速 I/O
  • 了解过滤器驱动程序
  • 过滤器驱动程序资源
  • 过滤器驱动框架
  • 隔离滤波器驱动器
  • 存储分层过滤驱动程序
文件加密
  • 了解文件加密
  • 了解 AES 加密
  • C# 中的文件加密
  • C++ 中的文件加密
  • BitLocker、EFS 与 EEFD
  • 对称加密
  • 非对称加密
  • 数字签名
  • EEFD透明文件加密開發包
  • EaseFilter文件監控開發包
  • EaseFilter文件訪問控制開發包
京公网安备 号    |    备案号:京ICP备09015132号-1024