System.Security.Cryptography.HashAlgorithm.ComputeHash(byte[])

Here are the examples of the csharp api System.Security.Cryptography.HashAlgorithm.ComputeHash(byte[]) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2557 Examples 7

19 View Source File : SHA2.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static string Hash(SHA2Type type, string data)
        {
            byte[] buffer = Encoding.UTF8.GetBytes(data);

            try
            {
                byte[] digest;
                switch (type)
                {
                    case SHA2Type.SHA256:
                        digest = SHA256.Create().ComputeHash(buffer);
                        break;
                    case SHA2Type.SHA512:
                        digest = SHA512.Create().ComputeHash(buffer);
                        break;
                    default:
                        return "";
                }

                return BitConverter.ToString(digest).Replace("-", "").ToLower();
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
                return "";
            }
        }

19 View Source File : MarketingDataAdapter.cs
License : MIT License
Project Creator : Adoxio

public string ConstructSignature(string encodedEmail, string encodedList = "")
		{
			var emailAddress = Decode(encodedEmail);
			var listId = Decode(encodedList);
			var signature = string.IsNullOrEmpty(listId) ? emailAddress : string.Format("{0}/{1}", emailAddress, listId);
			var bytes = Encoding.UTF8.GetBytes(signature);
			var key = Encoding.UTF8.GetBytes(EncryptionKey);
			using (var crypto = new HMACSHA256(key))
			{
				var hash = crypto.ComputeHash(bytes);
				return Encode(hash);
			}
		}

19 View Source File : RSAEncode.cs
License : Apache License 2.0
Project Creator : 91270

public bool GetHash(string m_strSource, ref byte[] HashData)
        {
            //从字符串中取得Hash描述   
            byte[] Buffer;
            HashAlgorithm MD5 = HashAlgorithm.Create("MD5");
            Buffer = Encoding.GetEncoding("GB2312").GetBytes(m_strSource);
            HashData = MD5.ComputeHash(Buffer);

            return true;
        }

19 View Source File : FileChecker.cs
License : Apache License 2.0
Project Creator : AantCoder

private static void GetCheckSum(ModelFileInfo mfi, string fileName, FastComputeHash computeHash)
        {
            try
            {
                if (computeHash.ReadFile != null) computeHash.ReadFile.Wait();

                computeHash.ReadFile = Task.Run(() =>
                {
                    try
                    {
                        if (!File.Exists(fileName)) return null;
                        var fileData = File.ReadAllBytes(fileName);
                        mfi.Size = fileData.Length;
                        return fileData;
                    }
                    catch (Exception exp)
                    {
                        ExceptionUtil.ExceptionLog(exp, "GetCheckSum 2 " + fileName);
                    }
                    return null;
                });
                computeHash.GetHash = computeHash.ReadFile.ContinueWith((task) =>
                {
                    try
                    {
                        if (task.Result == null)
                        {
                            mfi.Hash = null;
                            return;
                        }
                        var sha = SHA512.Create();
                        mfi.Hash = sha.ComputeHash(task.Result);
                    }
                    catch(Exception exp)
                    {
                        ExceptionUtil.ExceptionLog(exp, "GetCheckSum 3 " + fileName);
                    }
                });

                /*
                var sha = SHA512.Create();
                using (var fs = new FileStream(fileName, FileMode.Open))
                {
                    return sha.ComputeHash(fileData);
                }
                */
            }
            catch(Exception exp)
            {
                ExceptionUtil.ExceptionLog(exp, "GetCheckSum 1 " + fileName);
            }
        }

19 View Source File : UI.cs
License : MIT License
Project Creator : aaaddress1

private void compile_Click(object sender, EventArgs e)
        {

            (new System.Threading.Thread(() =>
            {
                this.Invoke((MethodInvoker)delegate () {
                    compile.Enabled = false;
                    logBox.Clear();
                    logMsg(demostr, Color.Blue);
                    this.splitContainer.Panel2Collapsed = false;
                    this.logPanelBtn.Text = "x";
                });
                File.WriteAllText(srcPath, this.fastColoredTextBox.Text);
                File.Delete(exePath);
                File.Delete(asmPath);
                File.Delete(obfAsmPath);

                logMsg(" --- \n", Color.Blue);
                logMsg(string.Format(
                        "[\tInfo\t] current compile info... \n" +
                        " - source: {0}\n" +
                        " - asm path: {1}\n" +
                        " - obfuscated asm path: {2}\n" +
                        " - output exe path: {3}\n", srcPath, asmPath, obfAsmPath, exePath), Color.Blue);

                if (compiler.geneateAsmSource(srcPath, asmPath))
                    logMsg("[\tOK\t] generate replacedembly code of source code.", Color.Green);
                else
                {
                    logMsg("[\tFail\t] generate replacedembly code of sorce code failure ...", Color.Red);
                    this.Invoke((MethodInvoker)delegate () { compile.Enabled = true; });
                    return;
                }

                if (obfuscator.obfuscaAsm(asmPath, obfAsmPath))
                    logMsg("[\tOK\t] generate obfuscated replacedembly code of source code.", Color.Green);
                else
                {
                    logMsg("[\tFail\t] generate obfuscated replacedembly code of sorce code failure ...", Color.Red);
                    this.Invoke((MethodInvoker)delegate () { compile.Enabled = true; });
                    return;
                }
                if (compiler.generateExe(obfAsmPath, exePath))
                {
                    var arr = System.IO.File.ReadAllBytes(exePath);
                    var size = arr.Length;
                    var md5 = BitConverter.ToString(MD5.Create().ComputeHash(arr)).Replace("-", "");
                    var sha256 = BitConverter.ToString(SHA256.Create().ComputeHash(arr)).Replace("-", "");
                    logMsg("[\tInfo\t] exe size: " + size + " bytes", Color.Blue);
                    logMsg("[\tInfo\t] MD5: " + md5, Color.Blue);
                    logMsg("[\tInfo\t] SHA256: " + sha256, Color.Blue);
                    logMsg("[\tOK\t] generate executable file successfully :)", Color.Green);
                }
                else
                    logMsg("[\tFail\t] generate executable file failure ... o___O", Color.Red);
 
                if (Properties.Settings.Default.clnAftCompile)
                {
                    File.Delete(asmPath);
                    File.Delete(obfAsmPath);
                }
                this.Invoke((MethodInvoker)delegate () { compile.Enabled = true; });
            })
            { IsBackground = true }).Start();
        }

19 View Source File : WebhookServer.cs
License : MIT License
Project Creator : 4egod

private string CRC(string consumerSecret, string crcToken)
        {
            byte[] consumerSecretBytes = Encoding.UTF8.GetBytes(consumerSecret);
            byte[] crcTokenBytes = Encoding.UTF8.GetBytes(crcToken);

            HMACSHA256 hmacSHA256Alog = new HMACSHA256(consumerSecretBytes);

            byte[] computedHash = hmacSHA256Alog.ComputeHash(crcTokenBytes);

            return "{\n" +
                $"\"response_token\":\"sha256={Convert.ToBase64String(computedHash)}\"" +
                "\n}";
        }

19 View Source File : PlatformFeatures.cs
License : MIT License
Project Creator : adamfisher

public string HashSha1(string value)
        {
            var hash = (new SHA1Managed()).ComputeHash(Encoding.UTF8.GetBytes(value));
            return string.Join(string.Empty, hash.Select(b => b.ToString("x2")).ToArray());
        }

19 View Source File : MD5Util.cs
License : MIT License
Project Creator : 404Lcc

public static string ComputeMD5(byte[] bytes)
        {
            if (bytes != null)
            {
                //加密结果"x2"结果为32位 "x3"结果为48位 "x4"结果为64位
                MD5 md5 = new MD5CryptoServiceProvider();
                bytes = md5.ComputeHash(bytes);
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < bytes.Length; i++)
                {
                    sb.Append(bytes[i].ToString("x2"));
                }
                return $"{sb}";
            }
            return string.Empty;
        }

19 View Source File : Utility.cs
License : MIT License
Project Creator : Adoxio

public static string ComputeETag(byte[] data)
		{
			using (var sha1 = new SHA1CryptoServiceProvider())
			{
				var hash = Convert.ToBase64String(sha1.ComputeHash(data));
				return hash;
			}
		}

19 View Source File : QQTea.cs
License : MIT License
Project Creator : 499116344

public static byte[] MD5(byte[] data)
        {
            var md5Instance = System.Security.Cryptography.MD5.Create();
            return md5Instance.ComputeHash(data);
        }

19 View Source File : Crypto.cs
License : Apache License 2.0
Project Creator : AantCoder

public byte[] GetHash(byte[] data)
        {
            if (HashSHA == null) HashSHA = new SHA512Managed();
            return HashSHA.ComputeHash(data);
        }

19 View Source File : BitstampApi.cs
License : MIT License
Project Creator : aabiryukov

private static byte[] SignHMACSHA256(String key, byte[] data)
		{
			using (var hashMaker = new HMACSHA256(Encoding.ASCII.GetBytes(key)))
			{
				return hashMaker.ComputeHash(data);
			}
		}

19 View Source File : QQUser.cs
License : MIT License
Project Creator : 499116344

public byte[] Md52()
        {
            var byteBuffer = new BinaryWriter(new MemoryStream());
            byteBuffer.Write(MD51);
            byteBuffer.BeWrite(0);
            byteBuffer.BeWrite(QQ);
            return MD5.Create().ComputeHash(((MemoryStream) byteBuffer.BaseStream).ToArray());
        }

19 View Source File : UsageServiceClient.cs
License : MIT License
Project Creator : ABTSoftware

private string GetAuthHeader(string username)
        {
            // Get salt
            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
            byte[] four_bytes = new byte[4];
            rng.GetBytes(four_bytes);
            var salt = BitConverter.ToUInt32(four_bytes, 0).ToString();
            // Get timestamp
            string timestamp = DateTime.UtcNow.ToString("o");
            // create signature
            string rawSig = (username ?? "") + timestamp + salt;
            var encoding = new System.Text.UTF8Encoding();
            byte[] keyByte = encoding.GetBytes(secretKey);
            byte[] messageBytes = encoding.GetBytes(rawSig);
            string signature;
            // hash and base64 encode 
            using (var sha256 = new HMACSHA256(keyByte))
            {
                byte[] hashMessage = sha256.ComputeHash(messageBytes);
                signature = Convert.ToBase64String(hashMessage);
            }
            // build auth header
            return timestamp + "," + salt + "," + signature;
        }

19 View Source File : NTLM.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent

private static byte[] GenerateSignKey(byte[] exportedSessionKey, byte[] constant)
        {
            List<byte> list = new List<byte>();
            list.AddRange(exportedSessionKey);
            list.AddRange(constant);

            return MD5.ComputeHash(list.ToArray());
        }

19 View Source File : AccountExtensions.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

private static string GetPreplacedwordHash(Account account, string preplacedword)
        {
            byte[] preplacedwordBytes = Encoding.UTF8.GetBytes(preplacedword);
            byte[] saltBytes = Convert.FromBase64String(account.PreplacedwordSalt);
            byte[] buffer = preplacedwordBytes.Concat(saltBytes).ToArray();
            byte[] hash;

            using (SHA512Managed hasher = new SHA512Managed())
                hash = hasher.ComputeHash(buffer);

            return Convert.ToBase64String(hash);
        }

19 View Source File : StringExtension.cs
License : GNU Lesser General Public License v3.0
Project Creator : 8720826

public static string ToMd5(this string str)
        {
            byte[] b = Encoding.UTF8.GetBytes(str);
            b = new MD5CryptoServiceProvider().ComputeHash(b);
            string ret = "";
            for (int i = 0; i < b.Length; i++)
            {
                ret = ret + b[i].ToString("x").PadLeft(2, '0');
            }
            return ret;
        }

19 View Source File : PortalTrackingTrace.cs
License : MIT License
Project Creator : Adoxio

private static string ComputeTokenSignature(string uri, string sharedKey, string policyName)
		{
			string signatureStringFormat = "sig={0}",
				expiryStringFormat = "se={0}",
				keyNameStringFormat = "skn={0}",
				resourceStringFormat = "sr={0}",
				tokenFormat = "{0}&{1}&{2}&{3}";

			DateTime epochBaseTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
			DateTime expiry = DateTime.Now.AddYears(1);
			var expiryString = ((long)(expiry - epochBaseTime).TotalSeconds).ToString("D");

			var requestUri = new Uri(uri);
			var resourceUrl = requestUri.Host + HttpUtility.UrlDecode(requestUri.AbsolutePath);

			var fields = new List<string> { HttpUtility.UrlEncode(resourceUrl), expiryString };
			using (var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(sharedKey)))
			{
				var requestString = string.Join("\n", fields);
				var signature = Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(requestString)));

				return string.Format(
					tokenFormat,
					string.Format(signatureStringFormat, HttpUtility.UrlEncode(signature)),
					string.Format(expiryStringFormat, HttpUtility.UrlEncode(expiryString)),
					string.Format(keyNameStringFormat, HttpUtility.UrlEncode(policyName)),
					string.Format(resourceStringFormat, HttpUtility.UrlEncode(resourceUrl)));
			}
		}

19 View Source File : PkgChecker.cs
License : MIT License
Project Creator : 13xforever

private static byte[] GetPs3Hmac(Span<byte> data)
        {
            byte[] sha;
            using (var sha1 = SHA1.Create())
                sha = sha1.ComputeHash(data.ToArray());
            var buf = new byte[0x40];
            Buffer.BlockCopy(sha, 4, buf, 0, 8);
            Buffer.BlockCopy(sha, 4, buf, 8, 8);
            Buffer.BlockCopy(sha, 12, buf, 16, 4);
            buf[20] = sha[16];
            buf[21] = sha[1];
            buf[22] = sha[2];
            buf[23] = sha[3];
            Buffer.BlockCopy(buf, 16, buf, 24, 8);
            using (var sha1 = SHA1.Create())
                sha = sha1.ComputeHash(buf);
            return sha.replacedpan(0, 0x10).ToArray();
        }

19 View Source File : MutexExtensions.cs
License : MIT License
Project Creator : Adoxio

private static string Hash(string text)
		{
			var bytes = Encoding.Unicode.GetBytes(text);

			using (var sha1 = new SHA1CryptoServiceProvider())
			{
				var hash = Convert.ToBase64String(sha1.ComputeHash(bytes));
				return hash;
			}
		}

19 View Source File : PasswordUtil.cs
License : Apache License 2.0
Project Creator : 91270

private static string CreateMD5(string pwd)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            string t2 = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(pwd)));
            t2 = t2.Replace("-", "");
            t2 = t2.ToUpper();
            return t2;
        }

19 View Source File : MD5Encode.cs
License : Apache License 2.0
Project Creator : 91270

public static string MD5Encrypt(string pwd)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            return BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(pwd))).Replace("-", "").ToUpper();
        }

19 View Source File : PkgChecker.cs
License : MIT License
Project Creator : 13xforever

private static byte[] GetSha1Hmac(Span<byte> data, Span<byte> key)
        {
            if (key.Length != 0x40)
                throw new ArgumentException(nameof(key));

            var ipad = new byte[0x40];
            var tmp = new byte[0x40 + 0x14]; // opad + hash(ipad + message)

            for (var i = 0; i < ipad.Length; i++)
            {
                tmp[i] = (byte)(key[i] ^ 0x5c); // opad
                ipad[i] = (byte)(key[i] ^ 0x36);
            }

            using (var sha1 = SHA1.Create())
            {
                sha1.TransformBlock(ipad.ToArray(), 0, ipad.Length, null, 0);
                sha1.TransformFinalBlock(data.ToArray(), 0, data.Length);
                Buffer.BlockCopy(sha1.Hash, 0, tmp, 0x40, 0x14);
            }
            using (var sha1 = SHA1.Create())
                return sha1.ComputeHash(tmp);
        }

19 View Source File : BitfinexAbstractApi.cs
License : MIT License
Project Creator : aabiryukov

protected string GetHexHashSignature(string payload)
        {
            return ByteToString(m_encryptor.ComputeHash(Encoding.ASCII.GetBytes(payload)));
        }

19 View Source File : QQTea.cs
License : MIT License
Project Creator : 499116344

public static string Md5(string text)
        {
            MD5 md5 = new MD5CryptoServiceProvider();
            var buffer = md5.ComputeHash(Encoding.UTF8.GetBytes(text));
            var result = "";
            foreach (var b in buffer)
            {
                result += b.ToString("x2");
            }

            return result;
        }

19 View Source File : FileChecker.cs
License : Apache License 2.0
Project Creator : AantCoder

public static string GetCheckSum(string data)
        {
            var sha = SHA512.Create();
            return Convert.ToBase64String(sha.ComputeHash(Encoding.UTF8.GetBytes(data)));
        }

19 View Source File : WexApi.cs
License : MIT License
Project Creator : aabiryukov

private string InternalQuery(NameValueDictionary args)
	    {
		    lock (m_nonceLock)
		    {
			    args.Add("nonce", GetNonce().ToString(CultureInfo.InvariantCulture));

			    var dataStr = BuildPostData(args);
			    var data = Encoding.ASCII.GetBytes(dataStr);

                using (var httpContent = new FormUrlEncodedContent(args))
                {
                    using (var request = new HttpRequestMessage(HttpMethod.Post, WebApi.RootUrl + "/tapi"))
                    {
                        request.Headers.Add("Key", m_key);
                        request.Headers.Add("Sign", ByteArrayToString(m_hashMaker.ComputeHash(data)).ToLowerInvariant());
                        request.Content = httpContent;

                        var response = WebApi.Client.SendAsync(request).Result;
                        var resultString = response.Content.ReadreplacedtringAsync().Result;
                        return resultString;
                    }
                }
		    }
	    }

19 View Source File : BaseApiClient.cs
License : MIT License
Project Creator : 4egod

protected string GetSignature(string signatureBaseString)
        {
            byte[] key = Encoding.ASCII.GetBytes(string.Concat(Uri.EscapeDataString(ConsumerSecret), "&", Uri.EscapeDataString(AccessTokenSecret)));

            string signature;
            using (HMACSHA1 hasher = new HMACSHA1(key))
            {
                signature = Convert.ToBase64String(hasher.ComputeHash(Encoding.ASCII.GetBytes(signatureBaseString)));
            }

            return signature;
        }

19 View Source File : Crypto.cs
License : Apache License 2.0
Project Creator : AantCoder

public string GetHash(string data)
        {
            if (HashSHA == null) HashSHA = new SHA512Managed();
            return KeyEncoding.GetString(HashSHA.ComputeHash(KeyEncoding.GetBytes(data)));
        }

19 View Source File : NTLM.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : 3gstudent

private static byte[] GenerateSealKey(byte[] exportedSessionKey, byte[] constant)
        {
            List<byte> list = new List<byte>();
            list.AddRange(exportedSessionKey);
            list.AddRange(constant);

            return MD5.ComputeHash(list.ToArray());
        }

19 View Source File : PwnedPasswords.cs
License : MIT License
Project Creator : abergs

public async static Task<bool> IsPreplacedwordPwned(string preplacedword, CancellationToken cancellationToken, HttpClient httpClient = null)
        {
            if (preplacedword == null) return false;

            byte[] byteString = Encoding.UTF8.GetBytes(preplacedword);
            byte[] hashBytes = null;
            var hashString = string.Empty;

            using (var sha1 = SHA1.Create())
            {
                hashBytes = sha1.ComputeHash(byteString);
            }            

            var sb = new StringBuilder();
            foreach (byte b in hashBytes)
            {
                sb.Append(b.ToString("X2"));
            }
            hashString = sb.ToString();

            string hashFirstFive = hashString.Substring(0, 5);
            string hashLeftover = hashString.Substring(5, hashString.Length - 5);

            HttpClient client = httpClient;
            if (httpClient == null)
            {
                client = _fallbackClient.Value;
            }

            try
            {
                var response = await client.GetStringAsync($"https://api.pwnedpreplacedwords.com/range/{hashFirstFive}");
                var isPwned = response.Contains(hashLeftover);

                return isPwned;
            }
            catch (Exception)
            {
                // todo: Log exceptions
                return false;
            }
        }

19 View Source File : WebhookServer.cs
License : MIT License
Project Creator : 4egod

private bool VerifySignature(string signature, byte[] body)
        {
            using (var crypto = new HMACSHA1(Encoding.UTF8.GetBytes(AppSecret)))
            {
                var hash = crypto.ComputeHash(body).ToHex();
                return hash.ToLower() == signature.Replace("sha1=", "").ToLower();
            }
        }

19 View Source File : Utils.cs
License : Apache License 2.0
Project Creator : ac87

public static byte[] Sha256(string inputStirng)
        {
            byte[] bytes = Encoding.ASCII.GetBytes(inputStirng);
            SHA256Managed sha256 = new SHA256Managed();
            return sha256.ComputeHash(bytes);
        }

19 View Source File : ICachingKeyGenerator.Default.cs
License : MIT License
Project Creator : 1100100

private string MD5(byte[] bytes)
        {
            using (MD5 md5 = new MD5CryptoServiceProvider())
            {
                var hash = md5.ComputeHash(bytes);
                md5.Clear();
                return BitConverter.ToString(hash).Replace("-", "").ToLower();
            }
        }

19 View Source File : SecureExtensions.cs
License : MIT License
Project Creator : Accelerider

public static string ToMd5(this string text)
        {
            return BitConverter.ToString(Md5Algorithm.ComputeHash(Encoding.UTF8.GetBytes(text))).Replace("-", string.Empty).ToLower();
        }

19 View Source File : WebhookServer.cs
License : MIT License
Project Creator : 4egod

private bool VerifySignature(string signature, byte[] body)
        {
            using (var crypto = new HMACSHA256(Encoding.UTF8.GetBytes(ConsumerSecret)))
            {
                var hash = Convert.ToBase64String(crypto.ComputeHash(body));
                return hash == signature.Replace("sha256=", "");
            }
        }

19 View Source File : IOUtil.cs
License : MIT License
Project Creator : actions

public static string GetSha256Hash(string path)
        {
            string hashString = path.ToLowerInvariant();
            using (SHA256 sha256hash = SHA256.Create())
            {
                byte[] data = sha256hash.ComputeHash(Encoding.UTF8.GetBytes(hashString));
                StringBuilder sBuilder = new StringBuilder();
                for (int i = 0; i < data.Length; i++)
                {
                    sBuilder.Append(data[i].ToString("x2"));
                }

                string hash = sBuilder.ToString();
                return hash;
            }
        }

19 View Source File : Program.cs
License : GNU General Public License v3.0
Project Creator : 3xpl01tc0d3r

static void Main(string[] args)
        {
            try
            {
                logo();
                // https://github.com/GhostPack/Rubeus/blob/master/Rubeus/Domain/ArgumentParser.cs#L10

                var arguments = new Dictionary<string, string>();
                foreach (var argument in args)
                {
                    var idx = argument.IndexOf(':');
                    if (idx > 0)
                        arguments[argument.Substring(0, idx)] = argument.Substring(idx + 1);
                    else
                        arguments[argument] = string.Empty;
                }

                WindowsIdenreplacedy idenreplacedy = WindowsIdenreplacedy.GetCurrent();
                WindowsPrincipal principal = new WindowsPrincipal(idenreplacedy);
                if (principal.IsInRole(WindowsBuiltInRole.Administrator))
                {
                    Console.WriteLine($"[+] Process running with {principal.Idenreplacedy.Name} privileges with HIGH integrity.");
                }
                else
                {
                    Console.WriteLine($"[+] Process running with {principal.Idenreplacedy.Name} privileges with MEDIUM / LOW integrity.");
                }

                if (arguments.Count == 0)
                {
                    PrintError("[-] No arguments specified. Please refer the help section for more details.");
                    help();
                }
                else if (arguments.ContainsKey("/help"))
                {
                    help();
                }
                else if (arguments.Count < 3)
                {
                    PrintError("[-] Some arguments are missing. Please refer the help section for more details.");
                    help();
                }
                else if (arguments.Count >= 3)
                {
                    string key = "SuperStrongKey";
                    string shellcode = null;
                    byte[] rawshellcode = new byte[] { };
                    if (arguments.ContainsKey("/path") && System.IO.File.Exists(arguments["/path"]))
                    {
                        if (arguments["/f"] == "raw")
                        {
                            rawshellcode = System.IO.File.ReadAllBytes(arguments["/path"]);
                        }
                        else
                        {
                            shellcode = System.IO.File.ReadAllText(arguments["/path"]);
                        }

                    }
                    else if (arguments.ContainsKey("/url"))
                    {
                        if (arguments["/f"] == "raw")
                        {
                            rawshellcode = GetRawShellcode(arguments["/url"]);
                        }
                        else
                        {
                            shellcode = GetShellcode(arguments["/url"]);
                        }
                    }

                    if (shellcode != null || rawshellcode.Length > 0)
                    {

                        byte[] buf = new byte[] { };

                        if (arguments.ContainsKey("/key"))
                        {
                            key = (arguments["/key"]);
                        }
                        PrintInfo($"[!] Shellcode will be encrypted using '{key}' key");
                        if (arguments["/enc"] == "xor")
                        {
                            byte[] xorshellcode = new byte[] { };
                            if (arguments["/f"] == "base64")
                            {
                                buf = Convert.FromBase64String(shellcode);
                                xorshellcode = XOR(buf, Encoding.ASCII.GetBytes(key));
                                PrintSuccess("[+] Shellcode encrypted successfully.");
                                //Console.WriteLine(Convert.ToBase64String(xorshellcode));
                                if (arguments.ContainsKey("/o"))
                                {
                                    System.IO.File.WriteAllText(arguments["/o"], Convert.ToBase64String(xorshellcode));
                                    PrintSuccess($"[+] Output saved in '{arguments["/o"]}' file.");
                                }
                                else
                                {
                                    System.IO.File.WriteAllText("output.bin", Convert.ToBase64String(xorshellcode));
                                    PrintSuccess($"[+] Output saved in 'output.bin' file.");
                                }
                            }
                            else if (arguments["/f"] == "hex")
                            {
                                buf = StringToByteArray(shellcode);
                                xorshellcode = XOR(buf, Encoding.ASCII.GetBytes(key));
                                PrintSuccess("[+] Shellcode encrypted successfully.");
                                //Console.WriteLine(ByteArrayToString(xorshellcode));
                                if (arguments.ContainsKey("/o"))
                                {
                                    System.IO.File.WriteAllText(arguments["/o"], ByteArrayToString(xorshellcode));
                                    PrintSuccess($"[+] Output saved in '{arguments["/o"]}' file.");
                                }
                                else
                                {
                                    System.IO.File.WriteAllText("output.bin", ByteArrayToString(xorshellcode));
                                    PrintSuccess($"[+] Output saved in 'output.bin' file.");
                                }
                            }
                            else if (arguments["/f"] == "c")
                            {
                                buf = convertfromc(shellcode);
                                xorshellcode = XOR(buf, Encoding.ASCII.GetBytes(key));
                                StringBuilder newshellcode = new StringBuilder();
                                for (int i = 0; i < xorshellcode.Length; i++)
                                {
                                    newshellcode.Append("\\x");
                                    newshellcode.AppendFormat("{0:x2}", xorshellcode[i]);
                                }
                                PrintSuccess("[+] Shellcode encrypted successfully.");
                                //Console.WriteLine(newshellcode);
                                if (arguments.ContainsKey("/o"))
                                {
                                    System.IO.File.WriteAllText(arguments["/o"], newshellcode.ToString());
                                    PrintSuccess($"[+] Output saved in '{arguments["/o"]}' file.");
                                }
                                else
                                {
                                    System.IO.File.WriteAllText("output.bin", newshellcode.ToString());
                                    PrintSuccess($"[+] Output saved in 'output.bin' file.");
                                }
                            }
                            else if (arguments["/f"] == "raw")
                            {
                                xorshellcode = XOR(rawshellcode, Encoding.ASCII.GetBytes(key));
                                PrintSuccess("[+] Shellcode encrypted successfully.");
                                if (arguments.ContainsKey("/o"))
                                {
                                    System.IO.File.WriteAllBytes(arguments["/o"], xorshellcode);
                                    PrintSuccess($"[+] Output saved in '{arguments["/o"]}' file.");
                                }
                                else
                                {
                                    System.IO.File.WriteAllBytes("output.bin", xorshellcode);
                                    PrintSuccess($"[+] Output saved in 'output.bin' file.");
                                }
                            }
                            else
                            {
                                PrintError("[-] Please specify correct shellcode format.");
                            }
                        }
                        else if (arguments["/enc"] == "aes")
                        {
                            byte[] preplacedwordBytes = Encoding.UTF8.GetBytes(key);
                            preplacedwordBytes = SHA256.Create().ComputeHash(preplacedwordBytes);
                            byte[] bytesEncrypted = new byte[] { };
                            if (arguments["/f"] == "base64")
                            {
                                buf = Convert.FromBase64String(shellcode);
                                bytesEncrypted = AES_Encrypt(buf, preplacedwordBytes);
                                PrintSuccess("[+] Shellcode encrypted successfully.");
                                //Console.WriteLine(Convert.ToBase64String(bytesEncrypted));
                                if (arguments.ContainsKey("/o"))
                                {
                                    System.IO.File.WriteAllText(arguments["/o"], Convert.ToBase64String(bytesEncrypted));
                                    PrintSuccess($"[+] Output saved in '{arguments["/o"]}' file.");
                                }
                                else
                                {
                                    System.IO.File.WriteAllText("output.bin", Convert.ToBase64String(bytesEncrypted));
                                    PrintSuccess($"[+] Output saved in 'output.bin' file.");
                                }
                            }
                            else if (arguments["/f"] == "hex")
                            {
                                buf = StringToByteArray(shellcode);
                                bytesEncrypted = AES_Encrypt(buf, preplacedwordBytes);
                                PrintSuccess("[+] Shellcode encrypted successfully.");
                                //Console.WriteLine(ByteArrayToString(bytesEncrypted));
                                if (arguments.ContainsKey("/o"))
                                {
                                    System.IO.File.WriteAllText(arguments["/o"], ByteArrayToString(bytesEncrypted));
                                    PrintSuccess($"[+] Output saved in '{arguments["/o"]}' file.");
                                }
                                else
                                {
                                    System.IO.File.WriteAllText("output.bin", ByteArrayToString(bytesEncrypted));
                                    PrintSuccess($"[+] Output saved in 'output.bin' file.");
                                }
                            }
                            else if (arguments["/f"] == "c")
                            {
                                buf = convertfromc(shellcode);
                                bytesEncrypted = AES_Encrypt(buf, preplacedwordBytes);
                                StringBuilder newshellcode = new StringBuilder();
                                for (int i = 0; i < bytesEncrypted.Length; i++)
                                {
                                    newshellcode.Append("\\x");
                                    newshellcode.AppendFormat("{0:x2}", bytesEncrypted[i]);
                                }
                                PrintSuccess("[+] Shellcode encrypted successfully.");
                                //Console.WriteLine(newshellcode);
                                if (arguments.ContainsKey("/o"))
                                {
                                    System.IO.File.WriteAllText(arguments["/o"], newshellcode.ToString());
                                    PrintSuccess($"[+] Output saved in '{arguments["/o"]}' file.");
                                }
                                else
                                {
                                    System.IO.File.WriteAllText("output.bin", newshellcode.ToString());
                                    PrintSuccess($"[+] Output saved in 'output.bin' file.");
                                }
                            }
                            else if (arguments["/f"] == "raw")
                            {
                                bytesEncrypted = AES_Encrypt(rawshellcode, preplacedwordBytes);
                                if (arguments.ContainsKey("/o"))
                                {
                                    System.IO.File.WriteAllBytes(arguments["/o"], bytesEncrypted);
                                    PrintSuccess($"[+] Output saved in '{arguments["/o"]}' file.");
                                }
                                else
                                {
                                    System.IO.File.WriteAllBytes("output.bin", bytesEncrypted);
                                    PrintSuccess($"[+] Output saved in 'output.bin' file.");
                                }
                            }
                            else
                            {
                                PrintError("[-] Please specify correct shellcode format.");
                            }
                        }
                        else
                        {
                            PrintError("[-] Please specify correct encryption type.");
                        }
                    }
                    else
                    {
                        PrintError("[-] Please check the specified file path or the URL.");
                    }
                }
                else
                {
                    PrintError("[-] File doesn't exists. Please check the specified file path.");
                }
            }
            catch (Exception ex)
            {
                PrintError(ex.Message);
            }
        }

19 View Source File : Extensions.cs
License : MIT License
Project Creator : Adoxio

private static JObject DecodeSignedRequest(string signedRequest, string secret)
		{
			var parts = signedRequest.Split('.');

			if (parts.Length != 2) return null;
			
			var encodedSig = parts[0];
			var payload = parts[1];

			if (string.IsNullOrWhiteSpace(encodedSig) || string.IsNullOrWhiteSpace(payload)) return null;

			// verify the signature by hashing the payload with the secret

			var key = Encoding.UTF8.GetBytes(secret);
			var buffer = Encoding.UTF8.GetBytes(payload);

			using (var crypto = new HMACSHA256(key))
			{
				var hash = crypto.ComputeHash(buffer);
				var decodedSig = Decode(encodedSig);

				if (hash.Length != decodedSig.Length || !hash.SequenceEqual(decodedSig)) return null;

				var decodedPayload = Decode(payload);
				var json = Encoding.UTF8.GetString(decodedPayload);
				var token = JObject.Parse(json);

				return token;
			}
		}

19 View Source File : HashEncode.cs
License : Apache License 2.0
Project Creator : 91270

public static string HashEncoding(string Security)
        {
            byte[] Value;
            UnicodeEncoding Code = new UnicodeEncoding();
            byte[] Message = Code.GetBytes(Security);
            SHA512Managed Arithmetic = new SHA512Managed();
            Value = Arithmetic.ComputeHash(Message);
            Security = "";
            foreach (byte o in Value)
            {
                Security += (int)o + "O";
            }
            return Security;
        }

19 View Source File : HashPII.cs
License : MIT License
Project Creator : Adoxio

public static byte[] ComputeHashPiiSha256(byte[] piiToBeHashed)
		{
			using (var sha256 = SHA256.Create())
			{
				return sha256.ComputeHash(piiToBeHashed);
			}
		}

19 View Source File : Program.cs
License : MIT License
Project Creator : 0xDivyanshu

public static string CreateMD5(string input)
        {
            // Use input string to calculate MD5 hash
            using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
            {
                byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
                byte[] hashBytes = md5.ComputeHash(inputBytes);

                // Convert the byte array to hexadecimal string
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < hashBytes.Length; i++)
                {
                    sb.Append(hashBytes[i].ToString("X2"));
                }
                return sb.ToString();
            }
        }

19 View Source File : Utility.cs
License : MIT License
Project Creator : Adoxio

public static string ComputeETag(byte[] data)
		{
			using (var sha256 = new SHA256CryptoServiceProvider())
			{
				var hash = Convert.ToBase64String(sha256.ComputeHash(data));
				return hash;
			}
		}

19 View Source File : RSAEncode.cs
License : Apache License 2.0
Project Creator : 91270

public bool GetHash(string m_strSource, ref string strHashData)
        {

            //从字符串中取得Hash描述   
            byte[] Buffer;
            byte[] HashData;
            HashAlgorithm MD5 = HashAlgorithm.Create("MD5");
            Buffer = Encoding.GetEncoding("GB2312").GetBytes(m_strSource);
            HashData = MD5.ComputeHash(Buffer);

            strHashData = Convert.ToBase64String(HashData);
            return true;

        }

19 View Source File : MD5Util.cs
License : MIT License
Project Creator : 404Lcc

public static string ComputeMD5(string s)
        {
            if (!string.IsNullOrEmpty(s))
            {
                //加密结果"x2"结果为32位 "x3"结果为48位 "x4"结果为64位
                MD5 md5 = new MD5CryptoServiceProvider();
                byte[] bytes = s.GetBytes();
                bytes = md5.ComputeHash(bytes);
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < bytes.Length; i++)
                {
                    sb.Append(bytes[i].ToString("x2"));
                }
                return $"{sb}";
            }
            return string.Empty;
        }

19 View Source File : Helper.cs
License : MIT License
Project Creator : 0ffffffffh

private static string HashWith(HashAlgorithm algo,string v)
        {
            string hash;
            StringBuilder sb = new StringBuilder();
            byte[] bytes = Encoding.ASCII.GetBytes(v);

            bytes = algo.ComputeHash(bytes);
            algo.Dispose();

            for (int i = 0; i < bytes.Length; i++)
                sb.Append(bytes[i].ToString("X2"));

            hash = sb.ToString();
            sb.Clear();
            sb = null;
            
            return hash;
        }

19 View Source File : DefaultCacheKeyBuilder.cs
License : MIT License
Project Creator : 1100100

private static string HashCacheKey(string source)
        {
            if (string.IsNullOrWhiteSpace(source))
                return string.Empty;

            _md5Hasher ??= MD5.Create();
            var bytes = Encoding.UTF8.GetBytes(source);
            var hash = _md5Hasher.ComputeHash(bytes);
            return ToString(hash);
        }

19 View Source File : StringExtension.cs
License : MIT License
Project Creator : 3F

public static Guid Guid(this string str)
        {
            if(System.Guid.TryParse(str, out Guid res)) {
                return res;
            }

            if(str == null) {
                str = String.Empty;
            }

            using(MD5 md5 = MD5.Create()) {
                return new Guid(md5.ComputeHash(Encoding.UTF8.GetBytes(str)));
            }
        }

19 View Source File : TeaCrypter.cs
License : MIT License
Project Creator : 499116344

public byte[] MD5(byte[] data)
        {
            return System.Security.Cryptography.MD5.Create().ComputeHash(data);
        }

19 View Source File : HuobiAPI.cs
License : MIT License
Project Creator : aabiryukov

[System.Diagnostics.Codereplacedysis.SuppressMessage("Microsoft.Globalization", "CA1304:SpecifyCultureInfo", MessageId = "System.String.ToLower")]
        private static string GetSignature(IEnumerable<KeyValuePair<string, string>> args)
	    {
	        var input = string.Join("&", args.Select(arg => arg.Key + "=" + arg.Value));
            var asciiBytes = Encoding.ASCII.GetBytes(input);
	        using (var md5 = MD5.Create())
	        {
	            var hashedBytes = md5.ComputeHash(asciiBytes);
	            var hashedString = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
	            return hashedString;
	        }
	    }

See More Examples