RMS (Rights Management Services)基于SDK2.1的二次开发代码示例
2016-10-18 17:26
537 查看
最近研究了RMS的二次开发方法,主要实现针对指定用户设置文档权限的方法,收集的参考网站如下:
错误码详情:
https://msdn.microsoft.com/zh-cn/library/windows/desktop/hh535248(v=vs.85).aspx
官方FAQ
http://social.technet.microsoft.com/wiki/contents/articles/3440.ad-rms-frequently-asked-questions-faq.aspx https://technet.microsoft.com/en-us/dn467883
SDK下载
https://www.microsoft.com/en-us/download/details.aspx?id=38397
API参考
https://docs.microsoft.com/zh-cn/information-protection/develop/api-reference-2-1
代码示例如下:
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <ipcbase.h>
#include <ipcprot.h>
#include <ipcfile.h>
int _tmain( int argc, _TCHAR* argv[] )
{
//初始化动态库
HRESULT hr = IpcInitialize();
if ( FAILED(hr) )
{
printf("Failed to IpcInitialize\n");
}
//获取RMS服务器上模板
PCIPC_TIL pcTil = NULL;
hr = IpcGetTemplateList( NULL, 0, 0, NULL, NULL, &pcTil );
if (FAILED(hr))
{
printf("Failed to IpcGetTemplateList(%0x)\n",hr);
}
if ( !pcTil || pcTil->cTi <= 0 )
{
printf("Has no temple at server.\n");
}
//根据模板创建license
IPC_LICENSE_HANDLE hLicense = NULL;
hr = IpcCreateLicenseFromTemplateID( pcTil->aTi[0].wszID,
0,
NULL,
&hLicense );
if ( FAILED(hr) )
{
printf("Failed to IpcCreateLicenseFromTemplateID(%0x)\n",hr);
}
// Create User Rights structure for Joe with Read permissions
IPC_USER_RIGHTS joeReadRight = {0};
LPCWSTR rgwszReadRights[1] = {IPC_GENERIC_READ};
// Assign values to members of Rights structure
joeReadRight.User.dwType = IPC_USER_TYPE_EMAIL;
joeReadRight.User.wszID = L"test@qq.com";
joeReadRight.rgwszRights = rgwszReadRights;
joeReadRight.cRights = 1;
// Create User Rights List and assign the above rights
size_t uNoOfUserRights = 1;
PIPC_USER_RIGHTS_LIST pUserRightsList = NULL;
pUserRightsList = reinterpret_cast<PIPC_USER_RIGHTS_LIST>
(new BYTE[ sizeof(IPC_USER_RIGHTS_LIST) + uNoOfUserRights * sizeof(IPC_USER_RIGHTS)]);
if(pUserRightsList == NULL)
{
printf("pUserRightsList is NULL\n");
}
// Assign values to members of Rights List structure for Joe and Mary Kay
(*pUserRightsList).cbSize = sizeof(IPC_USER_RIGHTS_LIST);
(*pUserRightsList).cUserRights = uNoOfUserRights;
(*pUserRightsList).rgUserRights[0] = joeReadRight;
// Set the Rights List property on the license via its handle
// hLicense is a license handle created with IpcCreateLicenseFromScratch
hr = IpcSetLicenseProperty(hLicense, FALSE, IPC_LI_USER_RIGHTS_LIST, pUserRightsList);
if ( FAILED(hr) )
{
printf("Failed to IpcSetLicenseProperty(%0x)\n",hr);
}
//对指定文件加密,使用上面的授权信息
LPCWSTR wszInputFilePath = L"c:\\test.docx";
LPCWSTR outputName = NULL;
hr = IpcfEncryptFile(wszInputFilePath,
hLicense,
1,
IPC_SL_FLAG_DEFAULT,
NULL,
NULL,
&outputName);
if ( FAILED(hr) )
{
printf("Failed to IpcfEncryptFile(%0x)\n",hr);
}
//记得释放内存
if( pcTil )
{
IpcFreeMemory((LPVOID)pcTil);
pcTil = NULL;
}
if( hLicense )
{
IpcCloseHandle((IPC_HANDLE )hLicense);
pcTil = NULL;
}
getchar();
return 0;
}
错误码详情:
https://msdn.microsoft.com/zh-cn/library/windows/desktop/hh535248(v=vs.85).aspx
官方FAQ
http://social.technet.microsoft.com/wiki/contents/articles/3440.ad-rms-frequently-asked-questions-faq.aspx https://technet.microsoft.com/en-us/dn467883
SDK下载
https://www.microsoft.com/en-us/download/details.aspx?id=38397
API参考
https://docs.microsoft.com/zh-cn/information-protection/develop/api-reference-2-1
代码示例如下:
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <ipcbase.h>
#include <ipcprot.h>
#include <ipcfile.h>
int _tmain( int argc, _TCHAR* argv[] )
{
//初始化动态库
HRESULT hr = IpcInitialize();
if ( FAILED(hr) )
{
printf("Failed to IpcInitialize\n");
}
//获取RMS服务器上模板
PCIPC_TIL pcTil = NULL;
hr = IpcGetTemplateList( NULL, 0, 0, NULL, NULL, &pcTil );
if (FAILED(hr))
{
printf("Failed to IpcGetTemplateList(%0x)\n",hr);
}
if ( !pcTil || pcTil->cTi <= 0 )
{
printf("Has no temple at server.\n");
}
//根据模板创建license
IPC_LICENSE_HANDLE hLicense = NULL;
hr = IpcCreateLicenseFromTemplateID( pcTil->aTi[0].wszID,
0,
NULL,
&hLicense );
if ( FAILED(hr) )
{
printf("Failed to IpcCreateLicenseFromTemplateID(%0x)\n",hr);
}
// Create User Rights structure for Joe with Read permissions
IPC_USER_RIGHTS joeReadRight = {0};
LPCWSTR rgwszReadRights[1] = {IPC_GENERIC_READ};
// Assign values to members of Rights structure
joeReadRight.User.dwType = IPC_USER_TYPE_EMAIL;
joeReadRight.User.wszID = L"test@qq.com";
joeReadRight.rgwszRights = rgwszReadRights;
joeReadRight.cRights = 1;
// Create User Rights List and assign the above rights
size_t uNoOfUserRights = 1;
PIPC_USER_RIGHTS_LIST pUserRightsList = NULL;
pUserRightsList = reinterpret_cast<PIPC_USER_RIGHTS_LIST>
(new BYTE[ sizeof(IPC_USER_RIGHTS_LIST) + uNoOfUserRights * sizeof(IPC_USER_RIGHTS)]);
if(pUserRightsList == NULL)
{
printf("pUserRightsList is NULL\n");
}
// Assign values to members of Rights List structure for Joe and Mary Kay
(*pUserRightsList).cbSize = sizeof(IPC_USER_RIGHTS_LIST);
(*pUserRightsList).cUserRights = uNoOfUserRights;
(*pUserRightsList).rgUserRights[0] = joeReadRight;
// Set the Rights List property on the license via its handle
// hLicense is a license handle created with IpcCreateLicenseFromScratch
hr = IpcSetLicenseProperty(hLicense, FALSE, IPC_LI_USER_RIGHTS_LIST, pUserRightsList);
if ( FAILED(hr) )
{
printf("Failed to IpcSetLicenseProperty(%0x)\n",hr);
}
//对指定文件加密,使用上面的授权信息
LPCWSTR wszInputFilePath = L"c:\\test.docx";
LPCWSTR outputName = NULL;
hr = IpcfEncryptFile(wszInputFilePath,
hLicense,
1,
IPC_SL_FLAG_DEFAULT,
NULL,
NULL,
&outputName);
if ( FAILED(hr) )
{
printf("Failed to IpcfEncryptFile(%0x)\n",hr);
}
//记得释放内存
if( pcTil )
{
IpcFreeMemory((LPVOID)pcTil);
pcTil = NULL;
}
if( hLicense )
{
IpcCloseHandle((IPC_HANDLE )hLicense);
pcTil = NULL;
}
getchar();
return 0;
}
相关文章推荐
- RMS (Rights Management Services)基于SDK2.1的二次开发环境搭建
- iOS APP开发集成Apple Pay与银联SDK开发教程(附示例代码)
- 基于Qt的海康威视网络摄像头SDK的二次开发——摄像头登录和预览
- 基于VLC SDK的二次开发
- 基于Qt的海康威视网络摄像头SDK的二次开发(一)
- 基于VLC SDK的二次开发
- ArcGIS 二次开发系列之Python版示例代码
- ArcSDE SDK For Java二次开发介绍、示例
- SkylineDemoForWeb JavaScript二次开发示例代码
- Asp.net 2.0 自定义控件开发[创建自定义HeaderRow的GridView控件][示例代码下载]
- Asp.net 2.0 自定义控件开发[实现自动计算功能(AutoComputeControl)][示例代码下载][续]
- [导入]Asp.net 2.0 自定义控件开发[实现GridView多行表头固定表体滚动效果][示例代码下载]
- Asp.net 2.0 自定义控件开发[实现自动计算功能(AutoComputeControl)][示例代码下载]
- Asp.net 2.0 自定义控件开发[创建自定义浮动菜单FloadMenu控件][示例代码下载]
- [导入]Asp.net 2.0 自定义控件开发[创建自定义HeaderRow的GridView控件][示例代码下载]
- Asp.net 2.0 自定义控件开发[创建自定义浮动菜单FloadMenu控件][示例代码下载]
- Asp.net 2.0 自定义控件开发[创建自定义HeaderRow的GridView控件][示例代码下载]
- [导入]Asp.net 2.0 自定义控件开发[创建自定义浮动菜单FloadMenu控件][示例代码下载]
- Asp.net 2.0 自定义控件开发[实现GridView多行表头固定表体滚动效果][示例代码下载]
- Asp.net 2.0 自定义控件开发[创建自定义右键PopupMenu控件][示例代码下载]