wasSharpNET
/Cryptography/AES.cs |
@@ -81,7 +81,7 @@ |
public string wasAESDecrypt(string data, string key, string separator = ":") |
{ |
// retrieve the salt from the data. |
var segments = new List<string>(data.Split(new[] { separator }, StringSplitOptions.None)); |
var segments = new List<string>(data.Split(new[] {separator}, StringSplitOptions.None)); |
if (!segments.Count.Equals(2)) |
throw new ArgumentException("Invalid data."); |
|
@@ -115,4 +115,4 @@ |
return plaintext; |
} |
} |
} |
} |
/Cryptography/SHA1.cs |
@@ -5,7 +5,9 @@ |
/////////////////////////////////////////////////////////////////////////// |
|
using System; |
using System.Collections.Generic; |
using System.IO; |
using System.Linq; |
using System.Text; |
using System.Threading.Tasks; |
|
@@ -24,6 +26,16 @@ |
} |
|
/// <summary> |
/// Return a 40 character hex representation of a SHA1 hash from multiple sequential byte arrays. |
/// </summary> |
/// <param name="sha1">the SHA1 hash object</param> |
/// <param name="data">the byte data to compute the hash from</param> |
public static string ToHex(this System.Security.Cryptography.SHA1 sha1, IEnumerable<byte[]> data) |
{ |
return sha1.ToHex(data.Where(i => i != null).SelectMany(i => i).ToArray()); |
} |
|
/// <summary> |
/// Return a 40 character hex representation of a SHA1 hash. |
/// </summary> |
/// <param name="sha1">the SHA1 hash object</param> |
@@ -65,22 +77,21 @@ |
public static async Task CopyToAsync(this System.Security.Cryptography.SHA1 sha1, byte[] data, Stream outStream) |
{ |
var buffer = new char[1]; |
using (MemoryStream SHA1OutputStream = new MemoryStream()) |
using (var SHA1OutputStream = new MemoryStream()) |
{ |
using (StringReader SHA1InputStream = new StringReader(BitConverter.ToString(sha1.ComputeHash(data)).Replace("-", ""))) |
using (var SHA1InputStream = |
new StringReader(BitConverter.ToString(sha1.ComputeHash(data)).Replace("-", ""))) |
{ |
int count; |
while ((count = await SHA1InputStream.ReadAsync(buffer, 0, 1)) != 0) |
{ |
switch (buffer[0]) |
{ |
case '-': |
continue; |
default: |
SHA1OutputStream.WriteByte((byte)buffer[0]); |
SHA1OutputStream.WriteByte((byte) buffer[0]); |
break; |
} |
} |
} |
SHA1OutputStream.Position = 0L; |
await SHA1OutputStream.CopyToAsync(outStream); |
@@ -87,4 +98,4 @@ |
} |
} |
} |
} |
} |