Skip to content

Commit

Permalink
Updated code to be compatible with .NET 6.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tape-Worm committed Nov 11, 2021
1 parent 0afb39e commit 39ed8f6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 27 deletions.
14 changes: 1 addition & 13 deletions Gorgon/Gorgon.Core/Plugins/GorgonMefPluginCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,21 +329,9 @@ public static AssemblySigningResults VerifyAssemblyStrongName(string assemblyPat
return AssemblySigningResults.NotSigned;
}

var clrStrongNameClsId = new Guid("B79B0ACD-F5CD-409b-B5A5-A16244610B92");
var clrStrongNameriid = new Guid("9FD93CCF-3280-4391-B3A9-96E1CDE77C8D");

var strongName = (IClrStrongName)RuntimeEnvironment.GetRuntimeInterfaceAsObject(clrStrongNameClsId, clrStrongNameriid);

int result = strongName.StrongNameSignatureVerificationEx(assemblyPath, true, out bool wasVerified);

if ((result != 0) || (!wasVerified))
{
return AssemblySigningResults.NotSigned;
}

if (publicKey is null)
{
return AssemblySigningResults.Signed;
return AssemblySigningResults.NotSigned;
}

var assemblyName = AssemblyName.GetAssemblyName(assemblyPath);
Expand Down
6 changes: 3 additions & 3 deletions Gorgon/Gorgon.Core/Security/Aes256Encryption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public byte[] Decrypt(byte[] data)
return Array.Empty<byte>();
}

using var aes = new AesManaged();
using var aes = Aes.Create();
using ICryptoTransform transform = aes.CreateDecryptor(_ivKey.Key, _ivKey.IV);
using MemoryStream stream = _streamManager.GetStream();
using var writer = new CryptoStream(stream, transform, CryptoStreamMode.Write);
Expand Down Expand Up @@ -104,7 +104,7 @@ public byte[] Encrypt(byte[] data)
return Array.Empty<byte>();
}

using var aes = new AesManaged();
using var aes = Aes.Create();
using ICryptoTransform transform = aes.CreateEncryptor(_ivKey.Key, _ivKey.IV);
using MemoryStream stream = _streamManager.GetStream();
using var writer = new CryptoStream(stream, transform, CryptoStreamMode.Write);
Expand Down Expand Up @@ -208,7 +208,7 @@ public static (byte[] IV, byte[] Key) GenerateIvKey(string password, byte[] salt
rndGen.GetBytes(salt);
}

using var aes = new AesManaged();
using var aes = Aes.Create();
using var hashGen = new Rfc2898DeriveBytes(password, salt, 100);
return (hashGen.GetBytes(aes.BlockSize / 8), hashGen.GetBytes(aes.KeySize / 8));
}
Expand Down
14 changes: 3 additions & 11 deletions Gorgon/Gorgon.Core/Security/PasswordHasher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,13 @@ public static class PasswordHasher
#endregion

#region Methods.
#if NET6_0_OR_GREATER
/// <summary>
/// Function to generate a salt value.
/// </summary>
/// <returns>A byte array containing the salt data.</returns>
public static byte[] GenerateSalt()
{
byte[] result = new byte[SaltLength];

using (var cryptoRngProvider = new RNGCryptoServiceProvider())
{
cryptoRngProvider.GetBytes(result);
}

return result;
}
public static byte[] GenerateSalt() => RandomNumberGenerator.GetBytes(SaltLength);
#endif

/// <summary>
/// Function to hash and salt a password and return a base-64 encoded string containing encrypted hash and salt values.
Expand Down

0 comments on commit 39ed8f6

Please sign in to comment.