/// <summary> /// Load pdf file /// </summary> /// <param name="fileName"></param> /// <returns></returns> private bool LoadFile(string fileName) { bool isrmsProtect = true; byte[] license = null; try { //RMS化PDFファイルから、RMSライセンス情報と、暗号化された本文情報を分割する //RMS署名情報から、RMSサーバー情報を抽出する //RMSサーバーでの認証 //RMSサーバーからRMSライセンスの取得 license = SafeFileApiNativeMethods.IpcfGetSerializedLicenseFromFile(fileName); } catch (Exception ex) { isrmsProtect = false; } if (isrmsProtect) { try { //SymmetricKeyCredential symmkey = new SymmetricKeyCredential(); //symmkey.AppPrincipalId = "0C5BDABD-CF4D-4FBB-BF4A-DD62BCF7E976"; //symmkey.Base64Key = "P@ssw0rd"; //symmkey.BposTenantId = "*****@*****.**"; SymmetricKeyCredential symmkey = null; //RMSライセンスから、復号鍵の抽出 SafeInformationProtectionKeyHandle keyHandle = SafeNativeMethods.IpcGetKey(license, false, false, true, this); //symmkey = (SymmetricKeyCredential)keyHandle; //RMSライセンスから、権利リストの抽出 //Collection<UserRights> userRights = new Collection<UserRights>(); //userRights = SafeNativeMethods.IpcGetSerializedLicenseUserRightsList(license, keyHandle); bool accessGranted = SafeNativeMethods.IpcAccessCheck(keyHandle, "VIEW"); if (accessGranted) { SafeFileApiNativeMethods.IpcfDecryptFile(fileName, SafeFileApiNativeMethods.DecryptFlags.IPCF_DF_FLAG_DEFAULT, false, false, true, this, symmkey); } //使用権限が正しく設定されていません //ConnectionInfo connectionInfo = SafeNativeMethods.IpcGetSerializedLicenseConnectionInfo(license); //System.Collections.ObjectModel.Collection<TemplateIssuer> templateIssuerList = SafeNativeMethods.IpcGetTemplateIssuerList(connectionInfo, false, false, false, false, this, symmkey); //TemplateIssuer templateIssuer = templateIssuerList[0]; //SafeInformationProtectionLicenseHandle licenseHandle = SafeNativeMethods.IpcCreateLicenseFromScratch(templateIssuer); //SafeFileApiNativeMethods.IpcfEncryptFile(fileName, licenseHandle, SafeFileApiNativeMethods.EncryptFlags.IPCF_EF_FLAG_DEFAULT, false, false, false, this, symmkey); //テンプレートは管理者によって作成されていません //TemplateInfo templateInfo = SafeNativeMethods.IpcGetSerializedLicenseDescriptor(license, keyHandle, System.Globalization.CultureInfo.CurrentCulture); //SafeFileApiNativeMethods.IpcfEncryptFile(fileName, templateInfo.TemplateId, SafeFileApiNativeMethods.EncryptFlags.IPCF_EF_FLAG_DEFAULT, false, false, true, this, null); } catch (InformationProtectionException ex) { isrmsProtect = false; MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK); } catch (Exception ex) { isrmsProtect = false; } } try { pdfDoc.LoadPDF(fileName); return(true); } catch (System.Security.SecurityException sex) { String password = Interaction.InputBox("Please enter the document password:"******"Document Password", ""); if (password.Equals(string.Empty)) { return(false); } if (pdfDoc != null) { pdfDoc.Dispose(); pdfDoc = null; } pdfDoc = new PDFWrapper(); pdfDoc.UserPassword = password; return(LoadFile(fileName)); } catch (Exception ex) { return(false); } }