Skip to content

Commit

Permalink
Provide SDK version compatible with .NET Framework 4.5 (#20)
Browse files Browse the repository at this point in the history
* Issue #19 - convert all projects into new .csproj format for better multi-platform support.
* Issue #19 - add .NET Framework 4.5 as target and provide an old JWT package for it.
* Issue #19 - NuGet package `JWT` replaced with package `jose-jwt` (has better .NET 4.5 support).
  • Loading branch information
OlegRa authored Nov 14, 2019
1 parent 8aab720 commit 5a31e37
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 376 deletions.
32 changes: 8 additions & 24 deletions ILovePDF/ILovePDF/Core/RequestHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using JWT;
using JWT.Algorithms;
using JWT.Serializers;
using LovePdf.Model.Enums;
using LovePdf.Model.Enums;
using LovePdf.Model.Exception;
using LovePdf.Model.TaskParams;
using Newtonsoft.Json;
Expand All @@ -16,13 +13,15 @@
using System.Net.Http;
using System.Net.Http.Headers;
using System.Security.Authentication;
using System.Text;
using System.Threading.Tasks;
using Jose;

namespace LovePdf.Core
{
internal class RequestHelper
{
private string _privateKey;
private byte[] _privateKey;
private string _publicKey;
private readonly short _jwtDelay = 5400;

Expand Down Expand Up @@ -571,7 +570,7 @@ private static List<byte[]> ToChunks(Stream fileStream)

public RequestHelper SetKeys(string privateKey, string publicKey)
{
_privateKey = privateKey;
_privateKey = Encoding.UTF8.GetBytes(privateKey);
_publicKey = publicKey;
return this;
}
Expand Down Expand Up @@ -620,20 +619,10 @@ private bool IsExpiredGwt()
{
try
{
IJsonSerializer serializer = new JsonNetSerializer();
IDateTimeProvider provider = new UtcDateTimeProvider();
IJwtValidator validator = new JwtValidator(serializer, provider);
IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();
IJwtDecoder decoder = new JwtDecoder(serializer, validator, urlEncoder);

var json = decoder.Decode(Gwt, _privateKey, verify: true);
JWT.Decode(Gwt, _privateKey, JwsAlgorithm.HS256);
return false;
}
catch (TokenExpiredException)
{
return true;
}
catch (SignatureVerificationException)
catch (Exception)
{
return true;
}
Expand Down Expand Up @@ -665,12 +654,7 @@ private string GetJwt()
payLoad.Add("file_encryption_key", EncryptKey);
}

IJwtAlgorithm algorithm = new HMACSHA256Algorithm();
IJsonSerializer serializer = new JsonNetSerializer();
IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();
IJwtEncoder encoder = new JwtEncoder(algorithm, serializer, urlEncoder);

var token = encoder.Encode(payLoad, _privateKey);
var token = JWT.Encode(payLoad, _privateKey, JwsAlgorithm.HS256);

return token;
}
Expand Down
153 changes: 29 additions & 124 deletions ILovePDF/ILovePDF/ILovePDF.csproj
Original file line number Diff line number Diff line change
@@ -1,150 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E857560B-A766-4BF5-A601-A5503CDBC825}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>LovePdf</RootNamespace>
<AssemblyName>ILovePdf</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<TargetFrameworks>net45;net46</TargetFrameworks>
<AssemblyTitle>iLovePDF</AssemblyTitle>
<Product>iLovePDF</Product>
<Description>Develop and automate PDF processing tasks like Compress PDF, Merge PDF, Split PDF, convert Office to PDF, PDF to JPG, Images to PDF, add Page Numbers, Rotate PDF, Unlock PDF, stamp a Watermark and Repair PDF. Each one with several settings to get your desired results.</Description>
<Copyright>Copyright 2017</Copyright>
<Version>1.2.1.0</Version>
<AssemblyVersion>1.2.1.0</AssemblyVersion>
<FileVersion>1.2.1.0</FileVersion>
<OutputPath>bin\$(Configuration)\</OutputPath>
<Authors>Mario Martinez, Alexandra Kyluk, Aleksey Sidorov, Egor Krivoshapka</Authors>
<PackageId>ILove_PDF</PackageId>
<PackageLicenseUrl>https://opensource.org/licenses/MIT</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/ilovepdf/ilovepdf-net</PackageProjectUrl>
<PackageReleaseNotes>.Net Compliance, bug fixes</PackageReleaseNotes>
<PackageTags>ILOVEPDF Merge PDF Split convert Office to pdf PDf JPG Images unlock Pdf repair rotate pdf</PackageTags>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\ILovePdf.xml</DocumentationFile>
<DocumentationFile>bin\$(Configuration)\ILovePdf.xml</DocumentationFile>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>false</SignAssembly>
</PropertyGroup>

<PropertyGroup>
<AssemblyOriginatorKeyFile>iLovePdf.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="jose-jwt" Version="2.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

<ItemGroup>
<Reference Include="JWT, Version=4.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\JWT.4.0.0\lib\net46\JWT.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Core\ConnectTaskResponse.cs" />
<Compile Include="Core\ExecuteTaskResponse.cs" />
<Compile Include="Core\StartTaskResponse.cs" />
<Compile Include="Core\LovePdfApi.cs" />
<Compile Include="Core\Validation.cs" />
<Compile Include="Model\Enums\Gravity.cs" />
<Compile Include="Model\Enums\ValidationStatus.cs" />
<Compile Include="Model\Enums\EnumExtensions.cs" />
<Compile Include="Model\Enums\FontFamilies.cs" />
<Compile Include="Model\Exception\DownloadException.cs" />
<Compile Include="Model\Enums\BadRequestErrors.cs" />
<Compile Include="Model\Enums\ConformanceValues.cs" />
<Compile Include="Model\Enums\Layer.cs" />
<Compile Include="Model\Enums\WatermarkHorizontalPositions.cs" />
<Compile Include="Model\Enums\WatermarkVerticalPositions.cs" />
<Compile Include="Model\Enums\Rotate.cs" />
<Compile Include="Model\Exception\ProcessingException.cs" />
<Compile Include="Model\Exception\UploadException.cs" />
<Compile Include="Model\TaskParams\BaseParams.cs" />
<Compile Include="Model\TaskParams\CompressParams.cs" />
<Compile Include="Model\TaskParams\ExtractParams.cs" />
<Compile Include="Model\TaskParams\PdftoJpgParams.cs" />
<Compile Include="Model\TaskParams\PdfToPdfAParams.cs" />
<Compile Include="Model\TaskParams\ProtectParams.cs" />
<Compile Include="Model\TaskParams\SplitModeFixedRanges.cs" />
<Compile Include="Model\TaskParams\SplitModeRanges.cs" />
<Compile Include="Model\TaskParams\SplitModeRemovePages.cs" />
<Compile Include="Model\TaskParams\ValidatePdfAParams.cs" />
<Compile Include="Model\TaskParams\WatermarkModeImage.cs" />
<Compile Include="Model\TaskParams\WatermarkModeText.cs" />
<Compile Include="Model\TaskParams\WaterMarkParamsElement.cs" />
<Compile Include="Model\Task\CompressTask.cs" />
<Compile Include="Model\Enums\CompressionLevels.cs" />
<Compile Include="Model\Enums\FontStyles.cs" />
<Compile Include="Model\Enums\HorizontalPositions.cs" />
<Compile Include="Model\Enums\Orientations.cs" />
<Compile Include="Model\Enums\PageSizes.cs" />
<Compile Include="Model\Enums\PdfJpgModes.cs" />
<Compile Include="Model\Enums\SplitModes.cs" />
<Compile Include="Model\Enums\VerticalPositions.cs" />
<Compile Include="Model\Enums\WatermarkModes.cs" />
<Compile Include="Model\Enums\Tool.cs" />
<Compile Include="Core\FileParameter.cs" />
<Compile Include="Core\BaseTaskRequest.cs" />
<Compile Include="Core\DeleteTaskResponse.cs" />
<Compile Include="Core\StatusTaskResponse.cs" />
<Compile Include="Core\UploadTaskResponse.cs" />
<Compile Include="Model\TaskParams\ImageToPdfParams.cs" />
<Compile Include="Core\FileModel.cs" />
<Compile Include="Model\Task\ExtractTask.cs" />
<Compile Include="Model\Task\ImagetoPDFTask.cs" />
<Compile Include="Model\Task\LovePdfTask.cs" />
<Compile Include="Model\TaskParams\MergeParams.cs" />
<Compile Include="Model\Task\MergeTask.cs" />
<Compile Include="Model\TaskParams\PageNumbersParams.cs" />
<Compile Include="Model\Task\OfficeToPdfTask.cs" />
<Compile Include="Model\Task\PageNumbersTask.cs" />
<Compile Include="Model\Task\PdfToJpgTask.cs" />
<Compile Include="Model\Task\PdfToPdfATask.cs" />
<Compile Include="Model\Task\ProtectTask.cs" />
<Compile Include="Model\Task\RepairTask.cs" />
<Compile Include="Model\Task\RotateTask.cs" />
<Compile Include="Model\Task\UnlockTask.cs" />
<Compile Include="Model\Exception\NotFoundException.cs" />
<Compile Include="Model\Task\ValidatePdfATask.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Core\RequestHelper.cs" />
<Compile Include="Model\Exception\ServerErrorException.cs" />
<Compile Include="Core\Settings.cs" />
<Compile Include="Model\TaskParams\SplitParams.cs" />
<Compile Include="Model\Task\SplitTask.cs" />
<Compile Include="Model\TaskParams\WatermarkParams.cs" />
<Compile Include="Model\Task\WaterMarkTask.cs" />
<Compile Include="Model\Exception\TooManyRequestsException.cs" />
</ItemGroup>

<ItemGroup>
<None Include="app.config" />
<None Include="ILovePDF.nuspec" />
<None Include="iLovePdf.snk" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->

</Project>
18 changes: 0 additions & 18 deletions ILovePDF/ILovePDF/ILovePDF.nuspec

This file was deleted.

25 changes: 0 additions & 25 deletions ILovePDF/ILovePDF/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@
using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("iLovePDF")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("iLovePDF")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
Expand All @@ -22,17 +10,4 @@
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e857560b-a766-4bf5-a601-a5503cdbc825")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.1.0")]
[assembly: AssemblyFileVersion("1.2.1.0")]

[assembly: CLSCompliant(true)]
5 changes: 0 additions & 5 deletions ILovePDF/ILovePDF/packages.config

This file was deleted.

25 changes: 0 additions & 25 deletions ILovePDF/Samples/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,10 @@
using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Samples")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Samples")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("652b4674-62cf-46a2-9fdf-f1d342fc79a5")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit 5a31e37

Please sign in to comment.