diff --git a/ServerMaint/Program.cs b/ServerMaint/Program.cs index 9eb6349..6813f84 100644 --- a/ServerMaint/Program.cs +++ b/ServerMaint/Program.cs @@ -16,6 +16,7 @@ using Teknik.Configuration; using Teknik.Utilities; using Teknik.Models; using System.Threading.Tasks; +using Teknik.Utilities.Cryptography; namespace ServerMaint { @@ -168,7 +169,7 @@ namespace ServerMaint byte[] keyBytes = Encoding.UTF8.GetBytes(upload.Key); byte[] ivBytes = Encoding.UTF8.GetBytes(upload.IV); FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); - AESCryptoStream aesStream = new AESCryptoStream(fs, false, keyBytes, ivBytes); + AesCounterStream aesStream = new AesCounterStream(fs, false, keyBytes, ivBytes); // We have the data, let's scan it ClamScanResult scanResult = clam.SendAndScanFile(aesStream); diff --git a/ServerMaint/ServerMaint.csproj b/ServerMaint/ServerMaint.csproj index b56ce1f..d8ad276 100644 --- a/ServerMaint/ServerMaint.csproj +++ b/ServerMaint/ServerMaint.csproj @@ -52,10 +52,6 @@ false - - ..\packages\BouncyCastle.1.8.1\lib\BouncyCastle.Crypto.dll - True - ..\packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll True @@ -84,10 +80,6 @@ ..\packages\Newtonsoft.Json.10.0.1\lib\net45\Newtonsoft.Json.dll True - - ..\packages\Inferno.1.4.0\lib\net452\SecurityDriven.Inferno.dll - True - diff --git a/ServerMaint/packages.config b/ServerMaint/packages.config index 36d1d7c..0bce754 100644 --- a/ServerMaint/packages.config +++ b/ServerMaint/packages.config @@ -1,10 +1,8 @@  - - diff --git a/Teknik/Areas/Paste/Controllers/PasteController.cs b/Teknik/Areas/Paste/Controllers/PasteController.cs index 3173a69..e479318 100644 --- a/Teknik/Areas/Paste/Controllers/PasteController.cs +++ b/Teknik/Areas/Paste/Controllers/PasteController.cs @@ -79,7 +79,7 @@ namespace Teknik.Areas.Paste.Controllers string hash = string.Empty; if (!string.IsNullOrEmpty(password)) { - byte[] passBytes = Utilities.SHA384.Hash(paste.Key, password); + byte[] passBytes = Utilities.Cryptography.SHA384.Hash(paste.Key, password); hash = passBytes.ToHex(); // We need to convert old pastes to the new password scheme if (paste.Transfers.ToList().Exists(t => t.Type == TransferTypes.ASCIIPassword)) @@ -103,8 +103,8 @@ namespace Teknik.Areas.Paste.Controllers data = Convert.FromBase64String(paste.Content); // Now we decrypt the content byte[] ivBytes = Encoding.Unicode.GetBytes(paste.IV); - byte[] keyBytes = AES.CreateKey(password, ivBytes, paste.KeySize); - data = AES.Decrypt(data, keyBytes, ivBytes); + byte[] keyBytes = AesCounterManaged.CreateKey(password, ivBytes, paste.KeySize); + data = AesCounterManaged.Decrypt(data, keyBytes, ivBytes); model.Content = Encoding.Unicode.GetString(data); } diff --git a/Teknik/Areas/Paste/PasteHelper.cs b/Teknik/Areas/Paste/PasteHelper.cs index c251e1e..ba2f4b1 100644 --- a/Teknik/Areas/Paste/PasteHelper.cs +++ b/Teknik/Areas/Paste/PasteHelper.cs @@ -65,8 +65,8 @@ namespace Teknik.Areas.Paste // Encrypt Content byte[] data = Encoding.Unicode.GetBytes(content); byte[] ivBytes = Encoding.Unicode.GetBytes(iv); - byte[] keyBytes = AES.CreateKey(password, ivBytes, config.PasteConfig.KeySize); - byte[] encData = AES.Encrypt(data, keyBytes, ivBytes); + byte[] keyBytes = AesCounterManaged.CreateKey(password, ivBytes, config.PasteConfig.KeySize); + byte[] encData = AesCounterManaged.Encrypt(data, keyBytes, ivBytes); content = Convert.ToBase64String(encData); paste.Key = key; diff --git a/Teknik/Areas/Upload/Controllers/UploadController.cs b/Teknik/Areas/Upload/Controllers/UploadController.cs index 2055f65..6e4f08d 100644 --- a/Teknik/Areas/Upload/Controllers/UploadController.cs +++ b/Teknik/Areas/Upload/Controllers/UploadController.cs @@ -20,6 +20,7 @@ using Teknik.Models; using Teknik.Attributes; using System.Text; using Org.BouncyCastle.Crypto; +using Teknik.Utilities.Cryptography; namespace Teknik.Areas.Upload.Controllers { @@ -291,7 +292,7 @@ namespace Teknik.Areas.Upload.Controllers return new FileGenerateResult(url, contentType, - (response) => ResponseHelper.StreamToOutput(response, true, new AESCryptoStream(fs, false, keyBytes, ivBytes), (int)length, Config.UploadConfig.ChunkSize), + (response) => ResponseHelper.StreamToOutput(response, true, new AesCounterStream(fs, false, keyBytes, ivBytes), (int)length, Config.UploadConfig.ChunkSize), false); } else // Otherwise just send it diff --git a/Teknik/Areas/Upload/Uploader.cs b/Teknik/Areas/Upload/Uploader.cs index a92a5e2..0838c3c 100644 --- a/Teknik/Areas/Upload/Uploader.cs +++ b/Teknik/Areas/Upload/Uploader.cs @@ -55,7 +55,7 @@ namespace Teknik.Areas.Upload byte[] ivBytes = Encoding.UTF8.GetBytes(iv); // Encrypt the file to disk - AES.EncryptToFile(filePath, file, config.UploadConfig.ChunkSize, keyBytes, ivBytes); + AesCounterManaged.EncryptToFile(filePath, file, config.UploadConfig.ChunkSize, keyBytes, ivBytes); } else { diff --git a/Teknik/Areas/User/Controllers/UserController.cs b/Teknik/Areas/User/Controllers/UserController.cs index da0d71e..9c3e729 100644 --- a/Teknik/Areas/User/Controllers/UserController.cs +++ b/Teknik/Areas/User/Controllers/UserController.cs @@ -16,6 +16,7 @@ using QRCoder; using TwoStepsAuthenticator; using System.Drawing; using Teknik.Attributes; +using Teknik.Utilities.Cryptography; namespace Teknik.Areas.Users.Controllers { diff --git a/Teknik/Areas/User/Utility/UserHelper.cs b/Teknik/Areas/User/Utility/UserHelper.cs index ca7899b..4556f8c 100644 --- a/Teknik/Areas/User/Utility/UserHelper.cs +++ b/Teknik/Areas/User/Utility/UserHelper.cs @@ -17,6 +17,7 @@ using Teknik.Areas.Users.Models; using Teknik.Configuration; using Teknik.Utilities; using Teknik.Models; +using Teknik.Utilities.Cryptography; namespace Teknik.Areas.Users.Utility { diff --git a/Teknik/Teknik.csproj b/Teknik/Teknik.csproj index 522a97d..aa12f71 100644 --- a/Teknik/Teknik.csproj +++ b/Teknik/Teknik.csproj @@ -132,10 +132,6 @@ ..\packages\QRCoder.1.2.3\lib\net40\QRCoder.dll True - - ..\packages\Inferno.1.4.0\lib\net452\SecurityDriven.Inferno.dll - True - diff --git a/Teknik/packages.config b/Teknik/packages.config index 21e998d..11146f2 100644 --- a/Teknik/packages.config +++ b/Teknik/packages.config @@ -8,7 +8,6 @@ - diff --git a/Utilities/Configuration/Config.cs b/Utilities/Configuration/Config.cs index 5d50774..6aabf36 100644 --- a/Utilities/Configuration/Config.cs +++ b/Utilities/Configuration/Config.cs @@ -3,6 +3,7 @@ using System.IO; using System.Threading; using Newtonsoft.Json; using Teknik.Utilities; +using Teknik.Utilities.Cryptography; namespace Teknik.Configuration { diff --git a/Utilities/Utilities/BundleExtensions.cs b/Utilities/Utilities/BundleExtensions.cs index db59c01..0a854d0 100644 --- a/Utilities/Utilities/BundleExtensions.cs +++ b/Utilities/Utilities/BundleExtensions.cs @@ -56,7 +56,7 @@ namespace Teknik.Utilities return; } - using (var hashAlgorithm = SHA256.CreateHashAlgorithm()) + using (var hashAlgorithm = Cryptography.SHA256.CreateHashAlgorithm()) { var hash = HttpServerUtility.UrlTokenEncode(hashAlgorithm.ComputeHash(Encoding.Unicode.GetBytes(response.Content))); context.BundleCollection.GetBundleFor(context.BundleVirtualPath).CdnPath = string.Format("{0}/{1}/{2}?v={3}&group={4}", CdnHost.TrimEnd('/'), dir, file, hash, group); diff --git a/Utilities/Utilities/Crypto.cs b/Utilities/Utilities/Crypto.cs deleted file mode 100644 index 3daf1d9..0000000 --- a/Utilities/Utilities/Crypto.cs +++ /dev/null @@ -1,227 +0,0 @@ -using System.Text; -using SecurityDriven.Inferno.Hash; -using SecurityDriven.Inferno.Mac; -using System.IO; -using System.Security.Cryptography; -using Org.BouncyCastle.Utilities.Encoders; -using Org.BouncyCastle.Bcpg.OpenPgp; -using System; -using System.Collections.Generic; -using System.IO.MemoryMappedFiles; - -namespace Teknik.Utilities -{ - public class MD5 - { - public static string Hash(string value) - { - byte[] valBytes = Encoding.ASCII.GetBytes(value); - System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create(); - byte[] hashBytes = md5.ComputeHash(valBytes); - - StringBuilder sBuilder = new StringBuilder(); - - // Loop through each byte of the hashed data - // and format each one as a hexadecimal string. - for (int i = 0; i < hashBytes.Length; i++) - { - sBuilder.Append(hashBytes[i].ToString("x2")); - } - - // Return the hexadecimal string. - return sBuilder.ToString(); - - } - - public static string FileHash(string filename) - { - try - { - using (var md5 = System.Security.Cryptography.MD5.Create()) - { - using (var stream = File.OpenRead(filename)) - { - return BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToLower(); - } - } - } - catch (Exception) - { - return string.Empty; - } - } - - public static string DataHash(string data) - { - try - { - using (var md5 = System.Security.Cryptography.MD5.Create()) - { - // convert string to stream - byte[] byteArray = Encoding.UTF8.GetBytes(data); - using (MemoryStream stream = new MemoryStream(byteArray)) - { - return BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToLower(); - } - } - } - catch (Exception) - { - return string.Empty; - } - } - } - - public class SHA384 - { - public static byte[] Hash(string key, string value) - { - byte[] keyBytes = Encoding.UTF8.GetBytes(key); - byte[] data = Encoding.UTF8.GetBytes(value); - - byte[] result = new HMAC2(HashFactories.SHA384, keyBytes).ComputeHash(data); - return result; - } - } - - public class SHA256 - { - public static string Hash(string value) - { - byte[] valueBytes = Encoding.Unicode.GetBytes(value); - return Hash(valueBytes); - } - - public static string Hash(byte[] value) - { - HashAlgorithm hash = new SHA256CryptoServiceProvider(); - byte[] hashBytes = hash.ComputeHash(value); - - return Convert.ToBase64String(hashBytes); - } - - public static byte[] Hash(Stream value) - { - HashAlgorithm hash = new SHA256CryptoServiceProvider(); - return hash.ComputeHash(value); - } - - public static string Hash(string value, string salt1, string salt2) - { - SHA256Managed hash = new SHA256Managed(); - SHA1 sha1 = new SHA1Managed(); - // gen salt2 hash - byte[] dataSalt2 = Encoding.UTF8.GetBytes(salt2); - byte[] salt2Bytes = hash.ComputeHash(dataSalt2); - string salt2Str = string.Empty; - foreach (byte x in salt2Bytes) - { - salt2Str += String.Format("{0:x2}", x); - } - string dataStr = salt1 + value + salt2Str; - byte[] dataStrBytes = Encoding.UTF8.GetBytes(dataStr); - byte[] shaBytes = sha1.ComputeHash(dataStrBytes); - string sha1Str = string.Empty; - foreach (byte x in shaBytes) - { - sha1Str += String.Format("{0:x2}", x); - } - byte[] sha1Bytes = Encoding.UTF8.GetBytes(sha1Str); - byte[] valueBytes = hash.ComputeHash(sha1Bytes); - string hashString = string.Empty; - foreach (byte x in valueBytes) - { - hashString += String.Format("{0:x2}", x); - } - return hashString; - } - - public static System.Security.Cryptography.SHA256 CreateHashAlgorithm() - { - if (CryptoConfig.AllowOnlyFipsAlgorithms) - { - return new SHA256CryptoServiceProvider(); - } - - return new SHA256Managed(); - } - } - - public static class PGP - { - public static bool IsPublicKey(string key) - { - bool isValid = false; - - try - { - byte[] byteArray = Encoding.ASCII.GetBytes(key); - using (MemoryStream stream = new MemoryStream(byteArray)) - { - using (Stream decoderStream = PgpUtilities.GetDecoderStream(stream)) - { - PgpPublicKeyRingBundle publicKeyBundle = new PgpPublicKeyRingBundle(decoderStream); - PgpPublicKey foundKey = GetFirstPublicKey(publicKeyBundle); - - if (foundKey != null) - { - isValid = true; - } - } - } - } - catch (Exception ex) - { - isValid = false; - } - return isValid; - } - - public static string GetFingerprint(string key) - { - string hexString = string.Empty; - byte[] byteArray = Encoding.ASCII.GetBytes(key); - using (MemoryStream stream = new MemoryStream(byteArray)) - { - using (Stream decoderStream = PgpUtilities.GetDecoderStream(stream)) - { - PgpPublicKeyRingBundle publicKeyBundle = new PgpPublicKeyRingBundle(decoderStream); - PgpPublicKey foundKey = GetFirstPublicKey(publicKeyBundle); - - if (foundKey != null) - { - byte[] fing = foundKey.GetFingerprint(); - hexString = Hex.ToHexString(fing); - } - } - } - return hexString; - } - public static string GetFingerprint64(string key) - { - string fingerprint = GetFingerprint(key); - if (fingerprint.Length > 16) - fingerprint = fingerprint.Substring(fingerprint.Length - 16); - return fingerprint; - } - - private static PgpPublicKey GetFirstPublicKey(PgpPublicKeyRingBundle publicKeyRingBundle) - { - foreach (PgpPublicKeyRing kRing in publicKeyRingBundle.GetKeyRings()) - { - var keys = kRing.GetPublicKeys(); - foreach (var key in keys) - { - PgpPublicKey foundKey = (PgpPublicKey)key; - //PgpPublicKey key = kRing.GetPublicKeys() - //.Cast() - // .Where(k => k.IsEncryptionKey) - // .FirstOrDefault(); - if (foundKey != null && foundKey.IsEncryptionKey) - return foundKey; - } - } - return null; - } - } -} \ No newline at end of file diff --git a/Utilities/Utilities/Cryptography/AES.cs b/Utilities/Utilities/Cryptography/AesCounterManaged.cs similarity index 95% rename from Utilities/Utilities/Cryptography/AES.cs rename to Utilities/Utilities/Cryptography/AesCounterManaged.cs index e7016dd..82d4dfe 100644 --- a/Utilities/Utilities/Cryptography/AES.cs +++ b/Utilities/Utilities/Cryptography/AesCounterManaged.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; namespace Teknik.Utilities.Cryptography { - public class AES + public class AesCounterManaged { public static byte[] Decrypt(byte[] data, string key, string iv) { @@ -44,7 +44,7 @@ namespace Teknik.Utilities.Cryptography // Make sure the input stream is at the beginning input.Seek(0, SeekOrigin.Begin); - AESCryptoStream cryptoStream = new AESCryptoStream(input, encrypt, key, iv); + AesCounterStream cryptoStream = new AesCounterStream(input, encrypt, key, iv); // Initialize variables byte[] output = new byte[input.Length]; @@ -83,7 +83,7 @@ namespace Teknik.Utilities.Cryptography // Make sure the input stream is at the beginning input.Seek(0, SeekOrigin.Begin); - AESCryptoStream cryptoStream = new AESCryptoStream(input, true, key, iv); + AesCounterStream cryptoStream = new AesCounterStream(input, true, key, iv); using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write)) { diff --git a/Utilities/Utilities/StreamHelper.cs b/Utilities/Utilities/Cryptography/AesCounterStream.cs similarity index 96% rename from Utilities/Utilities/StreamHelper.cs rename to Utilities/Utilities/Cryptography/AesCounterStream.cs index 36e6c0d..8de9af6 100644 --- a/Utilities/Utilities/StreamHelper.cs +++ b/Utilities/Utilities/Cryptography/AesCounterStream.cs @@ -2,14 +2,12 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; -using Teknik.Utilities.Cryptography; -namespace Teknik.Utilities +namespace Teknik.Utilities.Cryptography { - public class AESCryptoStream : Stream + public class AesCounterStream : Stream { private Stream _Inner; private CounterModeCryptoTransform _Cipher; @@ -23,7 +21,7 @@ namespace Teknik.Utilities /// /// /// - public AESCryptoStream(Stream stream, bool encrypt, byte[] key, byte[] iv) + public AesCounterStream(Stream stream, bool encrypt, byte[] key, byte[] iv) { _Inner = stream; diff --git a/Utilities/Utilities/Cryptography/MD5.cs b/Utilities/Utilities/Cryptography/MD5.cs new file mode 100644 index 0000000..66a17e4 --- /dev/null +++ b/Utilities/Utilities/Cryptography/MD5.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Teknik.Utilities.Cryptography +{ + public class MD5 + { + public static string Hash(string value) + { + byte[] valBytes = Encoding.ASCII.GetBytes(value); + System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create(); + byte[] hashBytes = md5.ComputeHash(valBytes); + + StringBuilder sBuilder = new StringBuilder(); + + // Loop through each byte of the hashed data + // and format each one as a hexadecimal string. + for (int i = 0; i < hashBytes.Length; i++) + { + sBuilder.Append(hashBytes[i].ToString("x2")); + } + + // Return the hexadecimal string. + return sBuilder.ToString(); + + } + + public static string FileHash(string filename) + { + try + { + using (var md5 = System.Security.Cryptography.MD5.Create()) + { + using (var stream = File.OpenRead(filename)) + { + return BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToLower(); + } + } + } + catch (Exception) + { + return string.Empty; + } + } + + public static string DataHash(string data) + { + try + { + using (var md5 = System.Security.Cryptography.MD5.Create()) + { + // convert string to stream + byte[] byteArray = Encoding.UTF8.GetBytes(data); + using (MemoryStream stream = new MemoryStream(byteArray)) + { + return BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToLower(); + } + } + } + catch (Exception) + { + return string.Empty; + } + } + } +} diff --git a/Utilities/Utilities/Cryptography/PGP.cs b/Utilities/Utilities/Cryptography/PGP.cs new file mode 100644 index 0000000..4388bd8 --- /dev/null +++ b/Utilities/Utilities/Cryptography/PGP.cs @@ -0,0 +1,90 @@ +using Org.BouncyCastle.Bcpg.OpenPgp; +using Org.BouncyCastle.Utilities.Encoders; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Teknik.Utilities.Cryptography +{ + public static class PGP + { + public static bool IsPublicKey(string key) + { + bool isValid = false; + + try + { + byte[] byteArray = Encoding.ASCII.GetBytes(key); + using (MemoryStream stream = new MemoryStream(byteArray)) + { + using (Stream decoderStream = PgpUtilities.GetDecoderStream(stream)) + { + PgpPublicKeyRingBundle publicKeyBundle = new PgpPublicKeyRingBundle(decoderStream); + PgpPublicKey foundKey = GetFirstPublicKey(publicKeyBundle); + + if (foundKey != null) + { + isValid = true; + } + } + } + } + catch (Exception ex) + { + isValid = false; + } + return isValid; + } + + public static string GetFingerprint(string key) + { + string hexString = string.Empty; + byte[] byteArray = Encoding.ASCII.GetBytes(key); + using (MemoryStream stream = new MemoryStream(byteArray)) + { + using (Stream decoderStream = PgpUtilities.GetDecoderStream(stream)) + { + PgpPublicKeyRingBundle publicKeyBundle = new PgpPublicKeyRingBundle(decoderStream); + PgpPublicKey foundKey = GetFirstPublicKey(publicKeyBundle); + + if (foundKey != null) + { + byte[] fing = foundKey.GetFingerprint(); + hexString = Hex.ToHexString(fing); + } + } + } + return hexString; + } + + public static string GetFingerprint64(string key) + { + string fingerprint = GetFingerprint(key); + if (fingerprint.Length > 16) + fingerprint = fingerprint.Substring(fingerprint.Length - 16); + return fingerprint; + } + + private static PgpPublicKey GetFirstPublicKey(PgpPublicKeyRingBundle publicKeyRingBundle) + { + foreach (PgpPublicKeyRing kRing in publicKeyRingBundle.GetKeyRings()) + { + var keys = kRing.GetPublicKeys(); + foreach (var key in keys) + { + PgpPublicKey foundKey = (PgpPublicKey)key; + //PgpPublicKey key = kRing.GetPublicKeys() + //.Cast() + // .Where(k => k.IsEncryptionKey) + // .FirstOrDefault(); + if (foundKey != null && foundKey.IsEncryptionKey) + return foundKey; + } + } + return null; + } + } +} diff --git a/Utilities/Utilities/Cryptography/SHA256.cs b/Utilities/Utilities/Cryptography/SHA256.cs new file mode 100644 index 0000000..3b54256 --- /dev/null +++ b/Utilities/Utilities/Cryptography/SHA256.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; + +namespace Teknik.Utilities.Cryptography +{ + public class SHA256 + { + public static string Hash(string value) + { + byte[] valueBytes = Encoding.Unicode.GetBytes(value); + return Hash(valueBytes); + } + + public static string Hash(byte[] value) + { + HashAlgorithm hash = new SHA256CryptoServiceProvider(); + byte[] hashBytes = hash.ComputeHash(value); + + return Convert.ToBase64String(hashBytes); + } + + public static byte[] Hash(Stream value) + { + HashAlgorithm hash = new SHA256CryptoServiceProvider(); + return hash.ComputeHash(value); + } + + public static string Hash(string value, string salt1, string salt2) + { + SHA256Managed hash = new SHA256Managed(); + SHA1 sha1 = new SHA1Managed(); + // gen salt2 hash + byte[] dataSalt2 = Encoding.UTF8.GetBytes(salt2); + byte[] salt2Bytes = hash.ComputeHash(dataSalt2); + string salt2Str = string.Empty; + foreach (byte x in salt2Bytes) + { + salt2Str += String.Format("{0:x2}", x); + } + string dataStr = salt1 + value + salt2Str; + byte[] dataStrBytes = Encoding.UTF8.GetBytes(dataStr); + byte[] shaBytes = sha1.ComputeHash(dataStrBytes); + string sha1Str = string.Empty; + foreach (byte x in shaBytes) + { + sha1Str += String.Format("{0:x2}", x); + } + byte[] sha1Bytes = Encoding.UTF8.GetBytes(sha1Str); + byte[] valueBytes = hash.ComputeHash(sha1Bytes); + string hashString = string.Empty; + foreach (byte x in valueBytes) + { + hashString += String.Format("{0:x2}", x); + } + return hashString; + } + + public static System.Security.Cryptography.SHA256 CreateHashAlgorithm() + { + if (CryptoConfig.AllowOnlyFipsAlgorithms) + { + return new SHA256CryptoServiceProvider(); + } + + return new SHA256Managed(); + } + } +} diff --git a/Utilities/Utilities/Cryptography/SHA384.cs b/Utilities/Utilities/Cryptography/SHA384.cs new file mode 100644 index 0000000..20b16c4 --- /dev/null +++ b/Utilities/Utilities/Cryptography/SHA384.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Teknik.Utilities.Cryptography +{ + public class SHA384 + { + public static byte[] Hash(string key, string value) + { + byte[] keyBytes = Encoding.UTF8.GetBytes(key); + byte[] data = Encoding.UTF8.GetBytes(value); + + var cipher = new System.Security.Cryptography.HMACSHA384(keyBytes); + byte[] result = cipher.ComputeHash(data); + + return result; + } + } +} diff --git a/Utilities/Utilities/Utilities.csproj b/Utilities/Utilities/Utilities.csproj index 105a0bb..b3cb670 100644 --- a/Utilities/Utilities/Utilities.csproj +++ b/Utilities/Utilities/Utilities.csproj @@ -56,10 +56,6 @@ ..\..\packages\Newtonsoft.Json.10.0.1\lib\net45\Newtonsoft.Json.dll True - - ..\..\packages\Inferno.1.4.0\lib\net452\SecurityDriven.Inferno.dll - True - @@ -106,8 +102,13 @@ - + + + + + + @@ -117,7 +118,6 @@ - @@ -128,7 +128,6 @@ - diff --git a/Utilities/Utilities/packages.config b/Utilities/Utilities/packages.config index 4efdac2..ea1dad7 100644 --- a/Utilities/Utilities/packages.config +++ b/Utilities/Utilities/packages.config @@ -3,7 +3,6 @@ -