Skip to content

Commit

Permalink
修正RSA在Linux下的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ldqk committed Aug 1, 2020
1 parent 0610f8e commit 90305b3
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Masuit.Tools.Core/Masuit.Tools.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Version>2.2.9.1</Version>
<Version>2.2.9.2</Version>
<Authors>懒得勤快</Authors>
<Company>masuit.com</Company>
<Description>包含一些常用的操作类,大都是静态类,加密解密,反射操作,硬件信息,字符串扩展方法,日期时间扩展操作,大文件拷贝,图像裁剪,html处理,验证码、NoSql等常用封装。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Bson" Version="2.10.4" />
<PackageReference Include="MongoDB.Driver" Version="2.10.4" />
<PackageReference Include="MongoDB.Driver.Core" Version="2.10.4" />
<PackageReference Include="MongoDB.Bson" Version="2.11.0" />
<PackageReference Include="MongoDB.Driver" Version="2.11.0" />
<PackageReference Include="MongoDB.Driver.Core" Version="2.11.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Masuit.Tools.UnitTest/ExtensionMethodsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void MatchUrl_True()
[TestMethod]
public void MatchEmail()
{
bool expect = "[email protected]".MatchEmail();
var (expect, match) = "[email protected]".MatchEmail();
Assert.AreEqual(true, expect);
}
[TestMethod]
Expand Down
3 changes: 3 additions & 0 deletions Masuit.Tools.UnitTest/Masuit.Tools.UnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.Helpers.dll</HintPath>
Expand Down
1 change: 1 addition & 0 deletions Masuit.Tools.UnitTest/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<package id="NUnit" version="3.12.0" targetFramework="net461" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.7.1" targetFramework="net461" />
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net461" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net461" />
<package id="xunit" version="2.4.1" targetFramework="net461" />
<package id="xunit.abstractions" version="2.0.3" targetFramework="net461" />
<package id="xunit.analyzers" version="0.10.0" targetFramework="net461" />
Expand Down
7 changes: 5 additions & 2 deletions Masuit.Tools/Masuit.Tools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="SharpCompress, Version=0.25.1.0, Culture=neutral, PublicKeyToken=afb0a02973931d96, processorArchitecture=MSIL">
<HintPath>..\packages\SharpCompress.0.25.1\lib\net46\SharpCompress.dll</HintPath>
<Reference Include="SharpCompress, Version=0.26.0.0, Culture=neutral, PublicKeyToken=afb0a02973931d96, processorArchitecture=MSIL">
<HintPath>..\packages\SharpCompress.0.26.0\lib\net46\SharpCompress.dll</HintPath>
</Reference>
<Reference Include="StackExchange.Redis, Version=1.2.6.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\StackExchange.Redis.1.2.6\lib\net45\StackExchange.Redis.dll</HintPath>
Expand All @@ -85,6 +85,9 @@
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Numerics" />
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.Helpers.dll</HintPath>
Expand Down
Binary file modified Masuit.Tools/Properties/AssemblyInfo.cs
Binary file not shown.
20 changes: 10 additions & 10 deletions Masuit.Tools/Security/RSA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ public bool Verify(string hash, byte[] sgin, byte[] data)
/// </summary>
public RSA(int keySize)
{
var rsaParams = new CspParameters
{
Flags = CspProviderFlags.UseMachineKeyStore
};
RSAObject = new RSACryptoServiceProvider(keySize, rsaParams);
//var rsaParams = new CspParameters()
//{
// Flags = CspProviderFlags.UseMachineKeyStore
//};
RSAObject = new RSACryptoServiceProvider(keySize);
}

/// <summary>
Expand All @@ -229,11 +229,11 @@ public RSA(string key)
}
else
{
var rsaParams = new CspParameters
{
Flags = CspProviderFlags.UseMachineKeyStore
};
RSAObject = new RSACryptoServiceProvider(rsaParams);
//var rsaParams = new CspParameters
//{
// Flags = CspProviderFlags.UseMachineKeyStore
//};
RSAObject = new RSACryptoServiceProvider();

RSAObject.FromXmlString(key);
}
Expand Down
8 changes: 4 additions & 4 deletions Masuit.Tools/Security/RsaPem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ public RsaPem(byte[] modulus, byte[] exponent, byte[] dOrNull)
/// </summary>
public RSACryptoServiceProvider GetRSA()
{
var rsaParams = new CspParameters();
rsaParams.Flags = CspProviderFlags.UseMachineKeyStore;
var rsa = new RSACryptoServiceProvider(rsaParams);
//var rsaParams = System.Security.Cryptography.RSA.Create();
//rsaParams.Flags = CspProviderFlags.UseMachineKeyStore;
var rsa = new RSACryptoServiceProvider();

var param = new RSAParameters
{
Expand All @@ -181,7 +181,7 @@ public RSACryptoServiceProvider GetRSA()
/// </summary>
public static BigInteger BigX(byte[] bigb)
{
if (bigb[0] > 0x7F)
if (bigb[0] > 127)
{
byte[] c = new byte[bigb.Length + 1];
Array.Copy(bigb, 0, c, 1, bigb.Length);
Expand Down
2 changes: 1 addition & 1 deletion Masuit.Tools/package.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!--*-->
<id>Masuit.Tools.Net</id>
<!--*-->
<version>2.2.9.1</version>
<version>2.2.9.2</version>
<title>Masuit.Tools</title>
<!--*-->
<authors>masuit.com</authors>
Expand Down
3 changes: 2 additions & 1 deletion Masuit.Tools/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
<package id="Microsoft.AspNet.WebPages" version="3.2.7" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net461" />
<package id="SharpCompress" version="0.25.1" targetFramework="net461" />
<package id="SharpCompress" version="0.26.0" targetFramework="net461" />
<package id="StackExchange.Redis" version="1.2.6" targetFramework="net45" requireReinstallation="true" />
<package id="System.Buffers" version="4.5.1" targetFramework="net461" />
<package id="System.Runtime.Numerics" version="4.3.0" targetFramework="net461" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net461" />
</packages>
15 changes: 13 additions & 2 deletions NetCoreTest/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
using Microsoft.AspNetCore.Mvc;
using Masuit.Tools.Security;
using Microsoft.AspNetCore.Mvc;
using System.Net;
using System.Threading.Tasks;

namespace NetCoreTest.Controllers
{
public class HomeController : Controller
{

[HttpGet("rsaenc")]
[ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Rsa(string str)
{
var rsaKey = RsaCrypt.GenerateRsaKeys();
var enc = str.RSAEncrypt();
var dec = enc.RSADecrypt();
return Ok(dec);
}
}
}
11 changes: 9 additions & 2 deletions NetCoreTest/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Microsoft.AspNetCore;
using Masuit.Tools.Security;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using System;
using System.ComponentModel;

namespace NetCoreTest
Expand All @@ -8,7 +10,12 @@ public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
var rsaKey = RsaCrypt.GenerateRsaKeys();
var enc = "123456".RSAEncrypt();
var dec = enc.RSADecrypt();
Console.WriteLine(dec);
Console.ReadKey();
//CreateWebHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
Expand Down

0 comments on commit 90305b3

Please sign in to comment.