public static bool GetSharedFilePermission(string fileName, string processName, string userName, string tagStr, ref string iv, ref string key, ref uint accessFlags, ref string lastError) { bool retVal = false; try { lastError = string.Empty; ServiceReference1.ServiceSoapClient client = GetServiceClient(ref lastError); if (null == client) { return(false); } string ivStr = tagStr; string serverAccount = GlobalConfig.AccountName; int index = tagStr.IndexOf(";"); if (index > 0) { serverAccount = tagStr.Substring(0, index); ivStr = tagStr.Substring(index + 1); } UserInfo userInfo = new UserInfo(); string keyStr = string.Empty; userInfo.FileName = fileName; userInfo.AccountName = serverAccount; userInfo.ProcessName = processName; userInfo.UserName = userName; userInfo.UserPassword = password; userInfo.CreationTime = DateTime.Now.ToFileTime();; userInfo.EncryptionIV = ivStr; string userInfoStr = DigitalRightControl.EncryptObjectToStr <UserInfo>(userInfo); retVal = client.GetSharedFilePermission(userInfoStr, ref key, ref iv, ref accessFlags, ref lastError); } catch (Exception ex) { lastError = "Get file key failed with error:" + ex.Message; retVal = false; } return(retVal); }
public bool GetSharedFileList() { string lastError = string.Empty; string encryptFileList = string.Empty; Dictionary <string, DRPolicy> shareList = new Dictionary <string, DRPolicy>(); //bool retVal = WebFormServices.GetFileList(AccountForm.accountName, AccountForm.password, ref encryptFileList, ref lastError); //if (!retVal) //{ // MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); // MessageBox.Show(lastError, "GetFileList", MessageBoxButtons.OK, MessageBoxIcon.Error); // return false; //} //else { if (encryptFileList.Length > 0) { List <string> decrypFileList = DigitalRightControl.DecryptStrToObject <List <string> >(encryptFileList); foreach (string name in decrypFileList) { if (name.Length > 0) { //the extension of the file is the creation time. string creationTimeStr = Path.GetExtension(name).Substring(1); string fileName = Path.GetFileNameWithoutExtension(name); DRPolicy drPolicy = new DRPolicy(); drPolicy.FileName = fileName; drPolicy.CreationTime = long.Parse(creationTimeStr); drPolicy.ExpireTime = 0; shareList.Add(creationTimeStr, drPolicy); } } } sharedFileList = shareList; InitListView(); } return(true); }
private bool AddNewFileDRInfoToServer(ref string iv, ref string key, ref long creationTime) { bool retVal = false; string lastError = string.Empty; try { iv = string.Empty; key = string.Empty; creationTime = 0; if (AccountForm.accountName.Length == 0 || AccountForm.password.Length == 0) { MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show("Can't enable revoke access feature for guest user!", "Create share encrypted file", MessageBoxButtons.OK, MessageBoxIcon.Error); return(retVal); } selectedDRPolicy = GetDRSetting(); string encryptedDRPolicy = DigitalRightControl.EncryptObjectToStr <DRPolicy>(selectedDRPolicy); //retVal = WebFormServices.AddNewFile(AccountForm.accountName, AccountForm.password, encryptedDRPolicy, ref creationTime, ref key, ref iv, ref lastError); //if (!retVal) //{ // MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); // MessageBox.Show("Create share encrypted file failed with error:" + lastError, "Process share encrypted file", MessageBoxButtons.OK, MessageBoxIcon.Error); // return retVal; //} //else { selectedDRPolicy.CreationTime = creationTime; isNewFileAddedToServer = true; } } catch (Exception ex) { MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show("Get encryption key info failed with error:" + ex.Message, "GetEncryptionKeyAndIVFromServer", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(retVal); }
private void button_EditSharedFile_Click(object sender, EventArgs e) { if (listView_SharedFiles.SelectedItems.Count != 1) { MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show("Please select a file.", "Edit", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string creationTimeStr = (string)listView_SharedFiles.SelectedItems[0].Tag; if (sharedFileList.ContainsKey(creationTimeStr)) { DRPolicy drPolicy = sharedFileList[creationTimeStr]; if (drPolicy.ExpireTime == 0) { string fileName = drPolicy.FileName; long creationTime = drPolicy.CreationTime; string lastError = string.Empty; string encryptedDRPolicy = string.Empty; //bool retVal = WebFormServices.GetFileDRInfo(AccountForm.accountName, AccountForm.password, fileName, creationTime, ref encryptedDRPolicy, ref lastError); //if (!retVal) //{ // MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); // MessageBox.Show("Get digital right information for file " + fileName + " failed with error:" + lastError, "GetFileDRInfo", MessageBoxButtons.OK, MessageBoxIcon.Error); // return; //} drPolicy = DigitalRightControl.DecryptStrToObject <DRPolicy>(encryptedDRPolicy); drPolicy.CreationTime = creationTime; sharedFileList[creationTimeStr] = drPolicy; } ShareFileForm shareFileForm = new ShareFileForm(drPolicy); shareFileForm.ShowDialog(); } }
private bool GetAccessPermissionFromServer(FilterAPI.MessageSendData messageSend, DRPolicyData drPolicyData, string userName, string processName, string userPassword, ref CacheUserAccessInfo cacheUserAccessInfo) { Boolean retVal = true; string fileName = messageSend.FileName; string lastError = string.Empty; try { UserInfo userInfo = new UserInfo(); string keyStr = string.Empty; string ivStr = string.Empty; userInfo.FileName = Path.GetFileName(messageSend.FileName) + DigitalRightControl.SECURE_SHARE_FILE_EXTENSION; userInfo.AccountName = drPolicyData.AccountName; userInfo.ProcessName = processName; userInfo.UserName = userName; userInfo.UserPassword = userPassword; userInfo.CreationTime = drPolicyData.CreationTime; byte[] computerId = new byte[52]; uint computerIdLength = (uint)computerId.Length; IntPtr computerIdPtr = Marshal.UnsafeAddrOfPinnedArrayElement(computerId, 0); retVal = FilterAPI.GetUniqueComputerId(computerIdPtr, ref computerIdLength); if (!retVal) { string message = "Get computerId failed,return error:" + FilterAPI.GetLastErrorMessage(); EventManager.WriteMessage(366, "GetAccessPermissionFromServer", EventLevel.Error, message); return(retVal); } Array.Resize(ref computerId, (int)computerIdLength); userInfo.ComputerId = UnicodeEncoding.Unicode.GetString(computerId); string userInfoStr = DigitalRightControl.EncryptObjectToStr <UserInfo>(userInfo); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); //retVal = WebFormServices.GetFileKey(userInfoStr, ref keyStr, ref ivStr, ref lastError); stopWatch.Stop(); if (!retVal) { string message = "Get file " + messageSend.FileName + " permission from server return error:" + lastError; EventManager.WriteMessage(293, "GetAccessPermissionFromServer", EventLevel.Error, message); return(retVal); } else { string message = "Get file " + messageSend.FileName + " permission frome server return succeed, spent " + stopWatch.ElapsedMilliseconds + " milliseconds."; EventManager.WriteMessage(208, "GetAccessPermissionFromServer", EventLevel.Verbose, message); } cacheUserAccessInfo.key = keyStr; cacheUserAccessInfo.iv = ivStr; } catch (Exception ex) { EventManager.WriteMessage(286, "GetAccessPermissionFromServer", EventLevel.Error, "Get file " + messageSend.FileName + "permission failed with exception:" + ex.Message); retVal = false; } return(retVal); }
Boolean FilterCallback(IntPtr sendDataPtr, IntPtr replyDataPtr) { Boolean ret = true; try { FilterAPI.MessageSendData messageSend = (FilterAPI.MessageSendData)Marshal.PtrToStructure(sendDataPtr, typeof(FilterAPI.MessageSendData)); if (FilterAPI.MESSAGE_SEND_VERIFICATION_NUMBER != messageSend.VerificationNumber) { MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show("Received message corrupted.Please check if the MessageSendData structure is correct."); EventManager.WriteMessage(139, "FilterCallback", EventLevel.Error, "Received message corrupted.Please check if the MessageSendData structure is correct."); return(false); } EventManager.WriteMessage(149, "FilterCallback", EventLevel.Verbose, "Received message Id#" + messageSend.MessageId + " type:" + messageSend.MessageType + " CreateOptions:" + messageSend.CreateOptions.ToString("X") + " infoClass:" + messageSend.InfoClass + " fileName:" + messageSend.FileName); filterMessage.AddMessage(messageSend); FileProtectorUnitTest.FileIOEventHandler(messageSend); if (replyDataPtr.ToInt64() != 0) { FilterAPI.MessageReplyData messageReply = (FilterAPI.MessageReplyData)Marshal.PtrToStructure(replyDataPtr, typeof(FilterAPI.MessageReplyData)); //if (messageSend.MessageType == (uint)FilterAPI.FilterCommand.FILTER_SEND_PROCESS_TERMINATION_INFO) //{ // //the process termination callback, you can get the notification if you register the callback setting of the process filter. //} if (messageSend.MessageType == (uint)FilterAPI.FilterCommand.FILTER_SEND_PROCESS_CREATION_INFO) { //this is new process creation, you can block it here by returning the STATUS_ACCESS_DENIED, below is the process information FilterAPI.PROCESS_INFO processInfo = (FilterAPI.PROCESS_INFO)Marshal.PtrToStructure(sendDataPtr, typeof(FilterAPI.PROCESS_INFO)); messageReply.ReturnStatus = processInfo.Status; Marshal.StructureToPtr(messageReply, replyDataPtr, true); } else if (messageSend.MessageType == (uint)FilterAPI.FilterCommand.FILTER_REQUEST_ENCRYPTION_IV_AND_KEY) { //this is encryption filter rule with boolean config "REQUEST_ENCRYPT_KEY_AND_IV_FROM_SERVICE" enabled. //the filter driver request the IV and key to open or create the encrypted file. //if you want to deny the file open or creation, you set the value as below: //messageReply.ReturnStatus = (uint)FilterAPI.NTSTATUS.STATUS_ACCESS_DENIED; //messageReply.FilterStatus = (uint)FilterAPI.FilterStatus.FILTER_COMPLETE_PRE_OPERATION; EventManager.WriteMessage(200, "filtercallback", EventLevel.Verbose, messageSend.FileName + " FILTER_REQUEST_ENCRYPTION_IV_AND_KEY"); //Here we return the test iv and key to the filter driver, you need to replace with you own iv and key in your code. AESDataBuffer aesData = new AESDataBuffer(); aesData.AccessFlags = FilterAPI.ALLOW_MAX_RIGHT_ACCESS; aesData.IV = FilterAPI.DEFAULT_IV_TAG; aesData.IVLength = (uint)aesData.IV.Length; aesData.EncryptionKey = Utils.GetKeyByPassPhrase(DigitalRightControl.PassPhrase); aesData.EncryptionKeyLength = (uint)aesData.EncryptionKey.Length; byte[] aesDataArray = DigitalRightControl.ConvertAESDataToByteArray(aesData); messageReply.DataBufferLength = (uint)aesDataArray.Length; Array.Copy(aesDataArray, messageReply.DataBuffer, aesDataArray.Length); messageReply.ReturnStatus = (uint)FilterAPI.NTSTATUS.STATUS_SUCCESS; } else if (messageSend.MessageType == (uint)FilterAPI.FilterCommand.FILTER_REQUEST_ENCRYPTION_IV_AND_KEY_AND_TAGDATA) { //this is encryption filter rule with boolean config "REQUEST_ENCRYPT_KEY_IV_AND_TAGDATA_FROM_SERVICE" enabled. //the filter driver request the IV and key to open or create the encrypted file. //if you want to deny the file open or creation, you set the value as below: //messageReply.ReturnStatus = (uint)FilterAPI.NTSTATUS.STATUS_ACCESS_DENIED; //messageReply.FilterStatus = (uint)FilterAPI.FilterStatus.FILTER_COMPLETE_PRE_OPERATION; if (messageSend.DataBufferLength > 0) { //this is the tag data which attached to the encrypted file . string tagDataStr = Encoding.Unicode.GetString(messageSend.DataBuffer); EventManager.WriteMessage(235, "filtercallback", EventLevel.Verbose, "EncryptedFile:" + messageSend.FileName + ",tagData:" + tagDataStr); } //Here we return the test iv ,key and tag data to the filter driver, you need to replace with you own iv and key in your code. AESDataBuffer aesData = new AESDataBuffer(); aesData.AccessFlags = FilterAPI.ALLOW_MAX_RIGHT_ACCESS; aesData.IV = FilterAPI.DEFAULT_IV_TAG; aesData.IVLength = (uint)aesData.IV.Length; aesData.EncryptionKey = Utils.GetKeyByPassPhrase(DigitalRightControl.PassPhrase); aesData.EncryptionKeyLength = (uint)aesData.EncryptionKey.Length; aesData.TagData = Encoding.Unicode.GetBytes("TagData:" + messageSend.FileName); aesData.TagDataLength = (uint)aesData.TagData.Length; byte[] aesDataArray = DigitalRightControl.ConvertAESDataToByteArray(aesData); messageReply.DataBufferLength = (uint)aesDataArray.Length; Array.Copy(aesDataArray, messageReply.DataBuffer, aesDataArray.Length); messageReply.ReturnStatus = (uint)FilterAPI.NTSTATUS.STATUS_SUCCESS; } else { //this is for control filter driver when the pre-IO was registered. //here you can control the IO behaviour and modify the data. if (!FileProtectorUnitTest.UnitTestCallbackHandler(messageSend) || !FilterService.AuthorizeFileAccess(messageSend, ref messageReply)) { //to comple the PRE_IO messageReply.ReturnStatus = (uint)FilterAPI.NTSTATUS.STATUS_ACCESS_DENIED; messageReply.FilterStatus = (uint)FilterAPI.FilterStatus.FILTER_COMPLETE_PRE_OPERATION; EventManager.WriteMessage(160, "FilterCallback", EventLevel.Error, "Return error for I/O request:" + ((FilterAPI.MessageType)messageSend.MessageType).ToString() + ",fileName:" + messageSend.FileName); } else { messageReply.MessageId = messageSend.MessageId; messageReply.MessageType = messageSend.MessageType; messageReply.ReturnStatus = (uint)FilterAPI.NTSTATUS.STATUS_SUCCESS; } } Marshal.StructureToPtr(messageReply, replyDataPtr, true); } return(ret); } catch (Exception ex) { EventManager.WriteMessage(134, "FilterCallback", EventLevel.Error, "filter callback exception." + ex.Message); return(false); } }
private bool CreateOrModifyShareEncryptFile() { string lastError = string.Empty; string authorizedProcessNames = textBox_authorizedProcessNames.Text.Trim(); string unauthorizedProcessNames = textBox_UnauthorizedProcessNames.Text.Trim(); string authorizedUserNames = textBox_AuthorizedUserNames.Text.Trim(); string unauthorizedUserNames = textBox_UnauthorizedUserNames.Text.Trim(); string fileName = textBox_FileName.Text.Trim(); string targetFileName = textBox_TargetName.Text; try { if (fileName.Length == 0) { MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show("The file name can't be empty.", "Create share encrypted file", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } DateTime expireDateTime = dateTimePicker_ExpireDate.Value.Date + dateTimePicker_ExpireTime.Value.TimeOfDay; if (expireDateTime <= DateTime.Now) { MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show("The expire time can't be less than current time.", "Create share encrypted file", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (selectedDRPolicy != null) { DRPolicy drPolicy = GetDRSetting(); string encryptedDRPolicy = DigitalRightControl.EncryptObjectToStr <DRPolicy>(drPolicy); if (WebAPIServices.ModifySharedFileDRInfo(encryptedDRPolicy, ref lastError)) { MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show("Modify shared file " + textBox_FileName.Text + " policy succeeded.", "Modify shared file", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); } else { MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show("Modify shared file " + textBox_FileName.Text + " policy failed with error:" + lastError, "Modify shared file", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } //here we generate the random unique IV and key, you can use your own key and iv byte[] encryptionIV = Utils.GetRandomIV(); byte[] encryptionKey = Utils.GetRandomKey(); string keyStr = string.Empty; string ivStr = string.Empty; if (GlobalConfig.StoreSharedFileMetaDataInServer) { long creationTime = DateTime.Now.ToFileTime(); //send the encrypted file digital right information to the server and get back the iv and key. if (!AddNewFileDRInfoToServer(ref ivStr, ref keyStr, ref creationTime)) { return(false); } if (ivStr.Length > 0 && keyStr.Length > 0) { encryptionIV = Utils.ConvertHexStrToByteArray(ivStr); encryptionKey = Utils.ConvertHexStrToByteArray(keyStr); } } //for this example, we add the encryptIV and account name as the tag data to the encrypted file //you can add your own custom tag data to the encyrpted file, so when someone open the encrypted file, you will get the tag data. string tagStr = GlobalConfig.AccountName + ";" + ivStr; byte[] tagData = UnicodeEncoding.Unicode.GetBytes(tagStr); bool retVal = false; if (fileName.Equals(targetFileName, StringComparison.CurrentCulture)) { retVal = FilterAPI.AESEncryptFileWithTag(fileName, (uint)encryptionKey.Length, encryptionKey, (uint)encryptionIV.Length, encryptionIV, (uint)tagData.Length, tagData); } else { retVal = FilterAPI.AESEncryptFileToFileWithTag(fileName, targetFileName, (uint)encryptionKey.Length, encryptionKey, (uint)encryptionIV.Length, encryptionIV, (uint)tagData.Length, tagData); } if (!retVal) { MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show("Create encrypted file " + targetFileName + " failed with error:" + FilterAPI.GetLastErrorMessage(), "Create share encrypted file", MessageBoxButtons.OK, MessageBoxIcon.Error); if (GlobalConfig.StoreSharedFileMetaDataInServer) { WebAPIServices.DeleteShareFile(ivStr, ref lastError); } if (!fileName.Equals(targetFileName, StringComparison.CurrentCulture)) { File.Delete(targetFileName); } return(false); } else { //set this flag to the encrypted file, require to get permission from user mode when the file open if (!FilterAPI.SetHeaderFlags(targetFileName, (uint)AESFlags.Flags_Request_IV_And_Key_From_User, FilterAPI.ALLOW_MAX_RIGHT_ACCESS)) { MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show("SetHeaderFlags for file " + targetFileName + " failed with error:" + FilterAPI.GetLastErrorMessage(), "SetHeaderFlags", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (!GlobalConfig.StoreSharedFileMetaDataInServer) { //add the permission meta data to a file and store it in the server, it will be used when the file open. if (!DRServer.AddDRInfoToFile(targetFileName, authorizedProcessNames, unauthorizedProcessNames, authorizedUserNames, unauthorizedUserNames , expireDateTime, encryptionIV, encryptionKey, FilterAPI.ALLOW_MAX_RIGHT_ACCESS.ToString())) { return(false); } } MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); string message = "Create encrypted file " + targetFileName + " succeeded, you can distribute this encrypted file to your client.\r\n\r\nDownload this file to the share file drop folder in the client,"; message += " then start the filter service there, now you can open the encrypted file if the process in client has the permission."; MessageBox.Show(message, "Share encrypted file", MessageBoxButtons.OK, MessageBoxIcon.Information); } return(true); } catch (Exception ex) { MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show("Create share file failed with error " + ex.Message, "Create share encrypted file", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } }
static public bool GetFileAccessPermission(ref FilterAPI.MessageSendData messageSend, ref FilterAPI.MessageReplyData messageReply) { Boolean retVal = true; string fileName = messageSend.FileName; string lastError = string.Empty; string processName = string.Empty; string userName = string.Empty; string encryptKey = string.Empty; try { FilterAPI.DecodeProcessName(messageSend.ProcessId, out processName); FilterAPI.DecodeUserName(messageSend.Sid, out userName); //by default the tag data format is "accountName;ivStr" int tagDataLength = (int)messageSend.DataBufferLength; byte[] tagData = messageSend.DataBuffer; Array.Resize(ref tagData, tagDataLength); string tagStr = UnicodeEncoding.Unicode.GetString(tagData); int index = tagStr.IndexOf(";"); byte[] iv = tagData; if (index > 0) { string serverAccount = tagStr.Substring(0, index); string ivStr = tagStr.Substring(index + 1); iv = Utils.ConvertHexStrToByteArray(ivStr); } uint accessFlag = 0; retVal = IsFileAccessAuthorized(fileName, userName, processName, tagStr, ref encryptKey, ref accessFlag, ref lastError); if (retVal && !string.IsNullOrEmpty(encryptKey)) { byte[] keyArray = Utils.ConvertHexStrToByteArray(encryptKey); //write the iv and key to the reply data buffer with format FilterAPI.AESDataBuffer AESDataBuffer aesData = new AESDataBuffer(); if (messageSend.MessageType == (uint)FilterAPI.FilterCommand.FILTER_REQUEST_ENCRYPTION_IV_AND_KEY_AND_ACCESSFLAG) { aesData.AccessFlags = FilterAPI.ALLOW_MAX_RIGHT_ACCESS; } else { aesData.AccessFlags = FilterAPI.ALLOW_MAX_RIGHT_ACCESS; } aesData.IV = iv; aesData.IVLength = (uint)iv.Length; aesData.EncryptionKey = keyArray; aesData.EncryptionKeyLength = (uint)keyArray.Length; byte[] aesDataArray = DigitalRightControl.ConvertAESDataToByteArray(aesData); messageReply.DataBufferLength = (uint)aesDataArray.Length; Array.Copy(aesDataArray, messageReply.DataBuffer, aesDataArray.Length); messageReply.ReturnStatus = (uint)FilterAPI.NTSTATUS.STATUS_SUCCESS; } } catch (Exception ex) { lastError = "GetFileAccessPermission exception." + ex.Message; EventManager.WriteMessage(340, "GetFileAccessPermission", EventLevel.Error, lastError); retVal = false; } if (!retVal) { byte[] errorBuffer = UnicodeEncoding.Unicode.GetBytes(lastError); Array.Copy(errorBuffer, messageSend.DataBuffer, errorBuffer.Length); messageSend.DataBufferLength = (uint)errorBuffer.Length; } return(retVal); }
private bool CreateShareEncryptFile() { string lastError = string.Empty; string key = string.Empty; string iv = string.Empty; long creationTime = DateTime.Now.ToFileTime(); try { if (textBox_FileName.Text.Trim().Length == 0) { MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show("The file name can't be empty.", "Create share encrypted file", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } DateTime expireDateTime = dateTimePicker_ExpireDate.Value.Date + dateTimePicker_ExpireTime.Value.TimeOfDay; if (expireDateTime <= DateTime.Now) { MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show("The expire time can't be less than current time.", "Create share encrypted file", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } DRPolicyData policyData = GetDRPolicyData(); if (((uint)policyData.AESFlags & (uint)AESFlags.Flags_Enabled_Revoke_Access_Control) == (uint)AESFlags.Flags_Enabled_Revoke_Access_Control) { if (!AddNewFileDRInfoToServer(ref iv, ref key, ref creationTime)) { return(false); } policyData.CreationTime = creationTime; } byte[] encryptIV = null; byte[] encryptKey = null; if (iv.Length > 0 && key.Length > 0) { encryptIV = Utils.ConvertHexStrToByteArray(iv); encryptKey = Utils.ConvertHexStrToByteArray(key); } else { encryptIV = Utils.GetRandomIV(); encryptKey = Utils.GetRandomKey(); policyData.IV = encryptIV; policyData.IVLength = (uint)encryptIV.Length; policyData.EncryptionKey = encryptKey; policyData.EncryptionKeyLength = (uint)encryptKey.Length; } if (!DigitalRightControl.EncryptFileWithEmbeddedDRPolicy(textBox_FileName.Text, textBox_OutputFilePath.Text, encryptIV, encryptKey, policyData, out lastError)) { MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show("Create share encrypted file " + textBox_FileName.Text + " failed with error:" + lastError, "Process share encrypted file", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } else { MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show("Create encrypted file " + textBox_OutputFilePath.Text + " succeeded.", "Process share encrypted file", MessageBoxButtons.OK, MessageBoxIcon.Information); selectedDRPolicy.CreationTime = creationTime; selectedDRPolicy.FileName = Path.GetFileName(textBox_OutputFilePath.Text); isNewFileAddedToServer = true; return(true); } } catch (Exception ex) { MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show("Create share file failed with error " + ex.Message, "Create share encrypted file", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } }