Adding an exception, SHA256

This commit is contained in:
Rick Falkvinge
2019-05-16 11:31:28 +02:00
parent 5b12ad9abf
commit aa9ae710ea
7 changed files with 39 additions and 2 deletions
@@ -20,6 +20,6 @@ namespace Swarmops.Common.Exceptions
}
public string AttemptedCommand { get; }
public Exception InnerException { get; }
public new Exception InnerException { get; }
}
}
+1
View File
@@ -131,6 +131,7 @@ namespace Swarmops.Logic.Financial
}
ExternalBankDataRecord newRecord = new ExternalBankDataRecord();
newRecord.RawData = lineData;
if (fieldNameLookup.ContainsKey(ExternalBankDataFieldName.DescriptionPrimary))
{
@@ -21,6 +21,8 @@ namespace Swarmops.Logic.Financial
public long TransactionNetCents;
public string UniqueId;
public string RawData; // Used for further discrimination among ambiguous records - may contain more uniqueness
#region Implementation of IComparer<ExternalBankDataRecord>
public int Compare (ExternalBankDataRecord x, ExternalBankDataRecord y)
+1
View File
@@ -232,6 +232,7 @@
<Compile Include="Communications\Payload\PayloadEnvelope.cs" />
<Compile Include="Communications\Payload\NotificationPayload.cs" />
<Compile Include="Security\Impersonation.cs" />
<Compile Include="Security\Sha256.cs" />
<Compile Include="Support\LogEntries\ApplicantAddedLogEntry.cs" />
<Compile Include="Support\SharpCashAddr.cs" />
<Compile Include="Support\SocketMessages\SocketMessageBase.cs" />
+2
View File
@@ -1,3 +1,4 @@
using System;
using System.Security.Cryptography;
using System.Text;
@@ -8,6 +9,7 @@ namespace Swarmops.Logic.Security
/// </summary>
public class SHA1
{
[Obsolete("Warning: SHA1 is considered insecure. Do not use for anything authentication or security related. Consider migrating to Sha256.")]
public static string Hash (string input)
{
byte[] data = Encoding.GetEncoding (1252).GetBytes (input);
+31
View File
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace Swarmops.Logic.Security
{
public class Sha256
{
public static string Compute(string input)
{
byte[] data = Encoding.GetEncoding(1252).GetBytes(input);
System.Security.Cryptography.SHA256 Sha256 = new SHA256CryptoServiceProvider();
byte[] hash = Sha256.ComputeHash(data);
// Write the resulting hash to a string of hex values.
StringBuilder result = new StringBuilder();
foreach (byte oneByte in hash)
{
result.Append(oneByte.ToString("X02") + " ");
}
return result.ToString().TrimEnd();
}
}
}
@@ -707,7 +707,7 @@ namespace Swarmops.Site.Pages.Ledgers
FinancialTransaction transaction = FinancialTransaction.ImportWithStub(args.Organization.Identity,
row.DateTime,
assetAccount.Identity, amountCents,
row.Description, importKey, "" /* new SHA256 field */,
row.Description, importKey, Sha256.Compute (row.RawData),
args.CurrentUser.Identity);
if (transaction != null)