Skip to content

Commit

Permalink
Merge branch 'release/v3.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominic Beger committed May 23, 2018
2 parents 28d5d2e + 3d3f5bf commit 3539667
Show file tree
Hide file tree
Showing 165 changed files with 5,418 additions and 5,311 deletions.
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -2,9 +2,9 @@

# nUpdate - .NET Update Solution

[![Release](https://img.shields.io/badge/release-v3.2.1-blue.svg)](https://github.com/ProgTrade/nUpdate/releases)
[![NuGet](https://img.shields.io/badge/nuget%20nUpdate.ProvideTAP-v3.2.1-red.svg)](https://www.nuget.org/packages/nUpdate.ProvideTAP/)
[![NuGet](https://img.shields.io/badge/nuget%20nUpdate.WithoutTAP-v3.2.1-red.svg)](https://www.nuget.org/packages/nUpdate.WithoutTAP/)
[![Release](https://img.shields.io/badge/release-v3.3-blue.svg)](https://github.com/ProgTrade/nUpdate/releases)
[![NuGet](https://img.shields.io/badge/nuget%20nUpdate.ProvideTAP-v3.3-red.svg)](https://www.nuget.org/packages/nUpdate.ProvideTAP/)
[![NuGet](https://img.shields.io/badge/nuget%20nUpdate.WithoutTAP-v3.3-red.svg)](https://www.nuget.org/packages/nUpdate.WithoutTAP/)
[![Issues](https://img.shields.io/github/issues/ProgTrade/nUpdate.svg)](https://github.com/ProgTrade/nUpdate/issues)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/ProgTrade/nUpdate/master/LICENSE)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=dominic%2ebeger%40hotmail%2ede&lc=DE&item_name=nUpdate&no_note=0&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest)
Expand Down Expand Up @@ -41,7 +41,7 @@ You can get the necessary libraries and applications from the current [releases]
If you want to use nUpdate with the Taskbased Asynchronous Pattern including `async` and `await`, then install this package:

```
PM> Install-Package nUpdate.ProvideTAP -Version 3.2.1
PM> Install-Package nUpdate.ProvideTAP -Version 3.3.0
```

##### Trouble installing nUpdate.ProvideTAP?
Expand All @@ -53,7 +53,7 @@ It may be that Visual Studio shows you a warning like `The primary reference "nU
Otherwise, if you want to use the Eventbased Asynchronous Pattern, make sure to install this package:

```
PM> Install-Package nUpdate.WithoutTAP -Version 3.2.1
PM> Install-Package nUpdate.WithoutTAP -Version 3.3.0
```

## Web
Expand Down
91 changes: 46 additions & 45 deletions nUpdate.Administration/Core/AesManager.cs
@@ -1,4 +1,4 @@
// Author: Dominic Beger (Trade/ProgTrade) 2016
// Copyright © Dominic Beger 2018

using System;
using System.IO;
Expand All @@ -10,16 +10,16 @@ namespace nUpdate.Administration.Core
public class AesManager
{
/// <summary>
/// Encrypts a string with the given key and initializing vector.
/// Decrypts a string with the given key and initializing vector.
/// </summary>
/// <param name="plainText">The text to encrypt.</param>
/// <param name="keyPassword">The password which the key should be derived from.</param>
/// <param name="ivPassword">The password which the initializing vector should be drived from.</param>
/// <returns>Returns the encrypted string as a byte-array.</returns>
public static byte[] Encrypt(string plainText, string keyPassword, string ivPassword)
/// <param name="cipherText">The byte-array of the encrypted string.</param>
/// <param name="keyPassword">The key to use.</param>
/// <param name="ivPassword">The initializing vector to use.</param>
/// <returns>Returns the plain string as SecureString.</returns>
public static SecureString Decrypt(byte[] cipherText, string keyPassword, string ivPassword)
{
if (string.IsNullOrEmpty(plainText))
throw new ArgumentNullException(nameof(plainText));
if (cipherText == null || cipherText.Length <= 0)
throw new ArgumentNullException(nameof(cipherText));
if (keyPassword == null || keyPassword.Length <= 0)
throw new ArgumentNullException(nameof(keyPassword));
if (ivPassword == null || ivPassword.Length <= 0)
Expand All @@ -29,47 +29,49 @@ public static byte[] Encrypt(string plainText, string keyPassword, string ivPass
new byte[] {0x43, 0x87, 0x23, 0x72, 0x45, 0x56, 0x68, 0x14, 0x62, 0x84});
var ivPasswordDeriveBytes = new Rfc2898DeriveBytes(ivPassword,
new byte[] {0x43, 0x87, 0x23, 0x72, 0x45, 0x56, 0x68, 0x14, 0x62, 0x84});
byte[] encrypted;

string plaintext;
using (var aesAlg = new AesManaged())
{
aesAlg.KeySize = 256;
aesAlg.Key = keyPasswordDeriveBytes.GetBytes(aesAlg.KeySize/8);
aesAlg.IV = ivPasswordDeriveBytes.GetBytes(aesAlg.BlockSize/8);
aesAlg.Key = keyPasswordDeriveBytes.GetBytes(aesAlg.KeySize / 8);
aesAlg.IV = ivPasswordDeriveBytes.GetBytes(aesAlg.BlockSize / 8);

// Create a decrytor to perform the stream transform.
var encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
var decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);

// Create the streams used for encryption.
using (var msEncrypt = new MemoryStream())
// Create the streams used for decryption.
using (var msDecrypt = new MemoryStream(cipherText))
{
using (var csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
using (var csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
{
using (var swEncrypt = new StreamWriter(csEncrypt))
using (var srDecrypt = new StreamReader(csDecrypt))
{
//Write all data to the stream.
swEncrypt.Write(plainText);
// Read the decrypted bytes from the decrypting stream
// and place them in a string.
plaintext = srDecrypt.ReadToEnd();
}
encrypted = msEncrypt.ToArray();
}
}
}

// Return the encrypted bytes from the memory stream.
return encrypted;
var securedPlainText = new SecureString();
foreach (var c in plaintext)
securedPlainText.AppendChar(c);
return securedPlainText;
}

/// <summary>
/// Decrypts a string with the given key and initializing vector.
/// Encrypts a string with the given key and initializing vector.
/// </summary>
/// <param name="cipherText">The byte-array of the encrypted string.</param>
/// <param name="keyPassword">The key to use.</param>
/// <param name="ivPassword">The initializing vector to use.</param>
/// <returns>Returns the plain string as SecureString.</returns>
public static SecureString Decrypt(byte[] cipherText, string keyPassword, string ivPassword)
/// <param name="plainText">The text to encrypt.</param>
/// <param name="keyPassword">The password which the key should be derived from.</param>
/// <param name="ivPassword">The password which the initializing vector should be drived from.</param>
/// <returns>Returns the encrypted string as a byte-array.</returns>
public static byte[] Encrypt(string plainText, string keyPassword, string ivPassword)
{
if (cipherText == null || cipherText.Length <= 0)
throw new ArgumentNullException(nameof(cipherText));
if (string.IsNullOrEmpty(plainText))
throw new ArgumentNullException(nameof(plainText));
if (keyPassword == null || keyPassword.Length <= 0)
throw new ArgumentNullException(nameof(keyPassword));
if (ivPassword == null || ivPassword.Length <= 0)
Expand All @@ -79,36 +81,35 @@ public static SecureString Decrypt(byte[] cipherText, string keyPassword, string
new byte[] {0x43, 0x87, 0x23, 0x72, 0x45, 0x56, 0x68, 0x14, 0x62, 0x84});
var ivPasswordDeriveBytes = new Rfc2898DeriveBytes(ivPassword,
new byte[] {0x43, 0x87, 0x23, 0x72, 0x45, 0x56, 0x68, 0x14, 0x62, 0x84});
byte[] encrypted;

string plaintext;
using (var aesAlg = new AesManaged())
{
aesAlg.KeySize = 256;
aesAlg.Key = keyPasswordDeriveBytes.GetBytes(aesAlg.KeySize/8);
aesAlg.IV = ivPasswordDeriveBytes.GetBytes(aesAlg.BlockSize/8);
aesAlg.Key = keyPasswordDeriveBytes.GetBytes(aesAlg.KeySize / 8);
aesAlg.IV = ivPasswordDeriveBytes.GetBytes(aesAlg.BlockSize / 8);

// Create a decrytor to perform the stream transform.
var decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
var encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);

// Create the streams used for decryption.
using (var msDecrypt = new MemoryStream(cipherText))
// Create the streams used for encryption.
using (var msEncrypt = new MemoryStream())
{
using (var csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
using (var csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
{
using (var srDecrypt = new StreamReader(csDecrypt))
using (var swEncrypt = new StreamWriter(csEncrypt))
{
// Read the decrypted bytes from the decrypting stream
// and place them in a string.
plaintext = srDecrypt.ReadToEnd();
//Write all data to the stream.
swEncrypt.Write(plainText);
}

encrypted = msEncrypt.ToArray();
}
}
}

var securedPlainText = new SecureString();
foreach (var c in plaintext)
securedPlainText.AppendChar(c);
return securedPlainText;
// Return the encrypted bytes from the memory stream.
return encrypted;
}
}
}
@@ -1,4 +1,4 @@
// Author: Dominic Beger (Trade/ProgTrade) 2016
// Copyright © Dominic Beger 2018

using System.Collections.Generic;

Expand All @@ -9,27 +9,6 @@ namespace nUpdate.Administration.Core.Application.Extension
/// </summary>
public class AssociationManager
{
/// <summary>
/// Determines of the list of extensions are associated with the specified program id.
/// </summary>
/// <param name="progId">Program id to check against.</param>
/// <param name="extensions">String array of extensions to check against the program id.</param>
/// <returns>String array of extensions that were not associated with the program id.</returns>
public string[] CheckAssociation(string progId, params string[] extensions)
{
var notAssociated = new List<string>();

foreach (var s in extensions)
{
var fai = new FileAssociationInfo(s);

if (!fai.Exists || fai.ProgId != progId)
notAssociated.Add(s);
}

return notAssociated.ToArray();
}

/// <summary>
/// Associates a single executable with a list of extensions.
/// </summary>
Expand Down Expand Up @@ -78,5 +57,26 @@ public void Associate(string progId, params string[] extensions)
fai.ProgId = progId;
}
}

/// <summary>
/// Determines of the list of extensions are associated with the specified program id.
/// </summary>
/// <param name="progId">Program id to check against.</param>
/// <param name="extensions">String array of extensions to check against the program id.</param>
/// <returns>String array of extensions that were not associated with the program id.</returns>
public string[] CheckAssociation(string progId, params string[] extensions)
{
var notAssociated = new List<string>();

foreach (var s in extensions)
{
var fai = new FileAssociationInfo(s);

if (!fai.Exists || fai.ProgId != progId)
notAssociated.Add(s);
}

return notAssociated.ToArray();
}
}
}

0 comments on commit 3539667

Please sign in to comment.