mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-28 15:31:30 +12:00
Trying to use Security.Cryptography library (http://clrsecurity.codeplex.com) for Up1 file uploader
This commit is contained in:
parent
b5bfb756fc
commit
4cdbdebdb8
4 changed files with 20 additions and 18 deletions
BIN
Lib/Security.Cryptography.dll
Normal file
BIN
Lib/Security.Cryptography.dll
Normal file
Binary file not shown.
|
@ -24,9 +24,7 @@ You should have received a copy of the GNU General Public License
|
|||
#endregion License Information (GPL v3)
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using Org.BouncyCastle.Crypto.Engines;
|
||||
using Org.BouncyCastle.Crypto.Modes;
|
||||
using Org.BouncyCastle.Crypto.Parameters;
|
||||
using Security.Cryptography;
|
||||
using ShareX.HelpersLib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -153,18 +151,24 @@ private static MemoryStream Encrypt(Stream source, string fileName, out string s
|
|||
byte[] ccmIV = new byte[ccmIVLen];
|
||||
Array.Copy(iv, ccmIV, ccmIVLen);
|
||||
|
||||
// Set up the encryption parameters
|
||||
KeyParameter keyParam = new KeyParameter(key);
|
||||
CcmParameters ccmParams = new CcmParameters(keyParam, MacSize, ccmIV, new byte[0]);
|
||||
CcmBlockCipher ccmMode = new CcmBlockCipher(new AesFastEngine());
|
||||
ccmMode.Init(true, ccmParams);
|
||||
// http://blogs.msdn.com/b/shawnfa/archive/2009/03/17/authenticated-symmetric-encryption-in-net.aspx
|
||||
using (AuthenticatedAesCng aes = new AuthenticatedAesCng())
|
||||
{
|
||||
aes.CngMode = CngChainingMode.Ccm;
|
||||
aes.Key = key;
|
||||
aes.IV = ccmIV;
|
||||
|
||||
// Perform the encryption
|
||||
byte[] encBytes = new byte[ccmMode.GetOutputSize(data.Length)];
|
||||
int res = ccmMode.ProcessBytes(data, 0, data.Length, encBytes, 0);
|
||||
ccmMode.DoFinal(encBytes, res);
|
||||
MemoryStream ms = new MemoryStream();
|
||||
|
||||
return new MemoryStream(encBytes);
|
||||
using (IAuthenticatedCryptoTransform encryptor = aes.CreateAuthenticatedEncryptor())
|
||||
{
|
||||
CryptoStream cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write);
|
||||
cs.Write(data, 0, data.Length);
|
||||
cs.FlushFinalBlock();
|
||||
//tag = encryptor.GetTag();
|
||||
return ms;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override UploadResult Upload(Stream input, string fileName)
|
||||
|
|
|
@ -77,10 +77,6 @@
|
|||
<HintPath>..\packages\AWSSDK.S3.3.1.2.0\lib\net35\AWSSDK.S3.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="crypto, Version=1.7.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Portable.BouncyCastle.1.7.0.2\lib\portable-net4+sl5+wp8+win8+wpa81+MonoTouch10+MonoAndroid10+xamarinmac20+xamarinios10\crypto.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="MegaApiClient, Version=1.1.1.44, Culture=neutral, PublicKeyToken=0480d311efbeb4e2, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MegaApiClient.1.1.1\lib\net40\MegaApiClient.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
|
@ -93,6 +89,9 @@
|
|||
<HintPath>..\packages\SSH.NET.2014.4.6-beta2\lib\net40\Renci.SshNet.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Security.Cryptography">
|
||||
<HintPath>..\Lib\Security.Cryptography.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Design" />
|
||||
<Reference Include="System.Drawing" />
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
<package id="AWSSDK.S3" version="3.1.2.0" targetFramework="net4" />
|
||||
<package id="MegaApiClient" version="1.1.1" targetFramework="net4" />
|
||||
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net4" />
|
||||
<package id="Portable.BouncyCastle" version="1.7.0.2" targetFramework="net4" />
|
||||
<package id="SSH.NET" version="2014.4.6-beta2" targetFramework="net4" />
|
||||
<package id="System.Net.FtpClient" version="1.0.5281.14359" targetFramework="net4" />
|
||||
</packages>
|
Loading…
Reference in a new issue