public async Task <DecryptedResponse> Execute(DecryptOfficeDocumentParameter decryptOfficeDocumentParameter, string accessToken, AuthenticateParameter authenticateParameter) { if (decryptOfficeDocumentParameter == null) { throw new ArgumentNullException(nameof(decryptOfficeDocumentParameter)); } if (authenticateParameter == null) { throw new ArgumentNullException(nameof(authenticateParameter)); } _decryptOfficeDocumentParameterValidator.Check(decryptOfficeDocumentParameter); await _getOfficeDocumentAction.Execute(decryptOfficeDocumentParameter.DocumentId); var jsonWebKey = await _jsonWebKeyRepository.Get(decryptOfficeDocumentParameter.Kid); if (jsonWebKey == null) { throw new BaseDocumentManagementApiException(ErrorCodes.InvalidRequest, string.Format(ErrorDescriptions.TheJsonWebKeyDoesntExist, decryptOfficeDocumentParameter.Kid)); } var payload = Convert.FromBase64String(decryptOfficeDocumentParameter.Credentials); byte[] decryptedPayload = null; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { using (var provider = new RSACryptoServiceProvider()) { provider.FromXmlStringCore(jsonWebKey.SerializedKey); decryptedPayload = provider.Decrypt(payload, true); } } else { using (var rsa = new RSAOpenSsl()) { rsa.FromXmlString(jsonWebKey.SerializedKey); decryptedPayload = rsa.Decrypt(payload, RSAEncryptionPadding.OaepSHA1); } } var decryptedContent = Encoding.UTF8.GetString(decryptedPayload); var splitted = decryptedContent.Split('.'); return(new DecryptedResponse { Password = splitted[0], Salt = splitted[1] }); }
public void Check(DecryptOfficeDocumentParameter decryptOfficeDocumentParameter) { if (decryptOfficeDocumentParameter == null) { throw new ArgumentNullException(nameof(decryptOfficeDocumentParameter)); } if (string.IsNullOrWhiteSpace(decryptOfficeDocumentParameter.DocumentId)) { throw new BaseDocumentManagementApiException(ErrorCodes.InvalidRequest, string.Format(ErrorDescriptions.ParameterIsMissing, "document_id")); } if (string.IsNullOrWhiteSpace(decryptOfficeDocumentParameter.Kid)) { throw new BaseDocumentManagementApiException(ErrorCodes.InvalidRequest, string.Format(ErrorDescriptions.ParameterIsMissing, "kid")); } if (string.IsNullOrWhiteSpace(decryptOfficeDocumentParameter.Credentials)) { throw new BaseDocumentManagementApiException(ErrorCodes.InvalidRequest, string.Format(ErrorDescriptions.ParameterIsMissing, "credentials")); } }
public Task <DecryptedResponse> Decrypt(DecryptOfficeDocumentParameter decryptOfficeDocumentParameter, string accessToken, AuthenticateParameter authenticateParameter) { return(_decryptOfficeDocumentAction.Execute(decryptOfficeDocumentParameter, accessToken, authenticateParameter)); }