示例#1
0
        private string DecryptOfficeDocument(string sidDocumentIdValue, string identityToken, string content)
        {
            var splittedContent = content.Split('.');

            if (splittedContent.Length != 3)
            {
                return(null);
            }

            var encryptionHelper = new EncryptionHelper();
            var kid                 = splittedContent[0];
            var credentials         = splittedContent[1];
            var encryptedContent    = splittedContent[2];
            var officeDocumentStore = OfficeDocumentStore.Instance();
            var decryptionResponse  = officeDocumentStore.RestoreDecryption(sidDocumentIdValue);

            if (decryptionResponse != null)
            {
                try
                {
                    var result = encryptionHelper.Decrypt(encryptedContent, decryptionResponse);
                    return(result);
                }
                catch (Exception) { }
            }


            var identityServerClientFactory    = new IdentityServerClientFactory();
            var identityServerUmaClientFactory = new IdentityServerUmaClientFactory();
            var documentManagementFactory      = new DocumentManagementFactory();
            var umaResourceId = officeDocumentStore.GetUmaResourceId(sidDocumentIdValue).Result;

            if (string.IsNullOrWhiteSpace(umaResourceId))
            {
                return(null);
            }

            var grantedToken = officeDocumentStore.GetOfficeDocumentAccessTokenViaUmaGrantType(umaResourceId).Result;

            if (grantedToken == null)
            {
                return(null);
            }

            var decryptedResult = documentManagementFactory.GetOfficeDocumentClient().DecryptResolve(new DecryptDocumentRequest
            {
                DocumentId  = sidDocumentIdValue,
                Credentials = credentials,
                Kid         = kid
            }, Constants.DocumentApiConfiguration, grantedToken.AccessToken).Result;

            if (decryptedResult.ContainsError)
            {
                return(null);
            }

            return(encryptionHelper.Decrypt(encryptedContent, decryptedResult.Content));
        }
 private OfficeDocumentStore()
 {
     _identityServerUmaClientFactory = new IdentityServerUmaClientFactory();
     _identityServerClientFactory    = new IdentityServerClientFactory();
     _documentManagementFactory      = new DocumentManagementFactory();
     _accessTokenStore    = AccessTokenStore.Instance();
     _authenticationStore = AuthenticationStore.Instance();
     _tokens    = new List <StoredUmaAccessToken>();
     _documents = new List <StoredOfficeDocument>();
 }
示例#3
0
 public ProtectUserController(Window window)
 {
     _window = window;
     _documentManagementFactory      = new DocumentManagementFactory();
     _identityServerUmaClientFactory = new IdentityServerUmaClientFactory();
     _identityServerClientFactory    = new IdentityServerClientFactory();
     _authenticationStore            = AuthenticationStore.Instance();
     _officeDocumentStore            = OfficeDocumentStore.Instance();
     ViewModel = new ProtectUserViewModel();
     Init();
     ViewModel.DocumentProtected         += HandleProtectDocument;
     ViewModel.SharedLinkAdded           += HandleAddSharedLink;
     ViewModel.SelectedSharedLinkRemoved += HandleRemoveSharedLink;
 }