Exemple #1
0
        private void computeHash()
        {
            var sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();

            this.datahash = string.Concat(sha1.ComputeHash(data).Select(x => x.ToString("X2")));
            sha1.Dispose();
        }
Exemple #2
0
 private string SHA1_Hash(string str)
 {
     System.Security.Cryptography.SHA1CryptoServiceProvider osha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
     byte[] retVal = osha1.ComputeHash(Encoding.ASCII.GetBytes(str));
     osha1.Dispose();
     return(BitConverter.ToString(retVal).Replace("-", "").ToLower());
 }
Exemple #3
0
        public static string Generate()
        {
            // Generate random
            var rnd = new System.Security.Cryptography.RNGCryptoServiceProvider();
            var entropy = new byte[bytes - 4];
            try {
                rnd.GetBytes(entropy);
            } finally {
                rnd.Dispose();
            }

            // Hash
            var sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            byte[] hash;
            try {
                hash = sha.ComputeHash(entropy);
            } finally {
                sha.Dispose();
            }

            // Compute output
            var raw = new byte[bytes];
            Array.Copy(entropy, 0, raw, 0, bytes - 4);
            Array.Copy(hash, 0, raw, bytes - 4, 4);

            // Convert to Base64
            return Convert.ToBase64String(raw).Replace('+', '!').Replace('/', '~');
        }
Exemple #4
0
        public static string prefs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/krypton-project/scale/legal/"; // legal folder

        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                if (args[0] == "-v")
                {
                    Console.WriteLine("asdasd");
                    if (File.Exists(prefs + "/gkey"))
                    {
                        using (System.IO.StreamReader sr = new System.IO.StreamReader(prefs + "/gkey"))
                        {
                            string   data = sr.ReadToEnd();
                            string[] f    = data.Split('\n');
                            sr.Dispose();
                            if (f[0] == "accepted")
                            {
                                string HASH = f[1].ToString();
                                using (System.Security.Cryptography.SHA1CryptoServiceProvider sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider())
                                {
                                    string hashsum = string.Empty;                                                 // Empty storage allocator
                                    byte[] da      = sha1.ComputeHash(Encoding.Unicode.GetBytes(prefs + "/gkey")); // byte array
                                    foreach (byte by in data)
                                    {
                                        hashsum += String.Format("{0,2:X2}", by);            // :-)
                                    }

                                    if (hashsum.ToString() != HASH.ToString())
                                    {
                                        Console.ForegroundColor = ConsoleColor.Red;
                                        Console.Write("SECURITY COMPROMISED!\n\nSHA1 HASH MODIFIED!\nRECORD DOES NOT MATCH G_KEY!\n\nCACHE WILL BE DELETED FOR SECURITY.");
                                        Console.Read();
                                    }

                                    else
                                    {
                                        ;
                                    }
                                    sha1.Dispose();

                                    try
                                    {
                                        Directory.Delete(prefs);
                                    }

                                    catch {; }
                                }
                            }
                        }
                    }
                }
            }

            else
            {
                Console.Write("This is not a standalone application.");
            }
        }
Exemple #5
0
        public static bool Validate(string sid)
        {
            // Basic sanity checks
            if (null == sid) return false;
            if (sid.Length != 32) return false;

            // Decode Base64
            byte[] raw;
            try {
                raw = Convert.FromBase64String(sid.Replace('!', '+').Replace('~', '/'));
            } catch (FormatException) {
                return false; // Not valid Base64
            }

            // Break into components
            var entropy = new byte[bytes - 4];
            var hash = new byte[4];
            Array.Copy(raw, 0, entropy, 0, bytes - 4);
            Array.Copy(raw, bytes - 4, hash, 0, 4);

            // Hash
            var sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
            byte[] buffer;
            try {
                buffer = sha.ComputeHash(entropy);
            } finally {
                sha.Dispose();
            }
            var checkhash = new byte[4];
            Array.Copy(buffer, 0, checkhash, 0, 4);

            // Check hash
            if (!hash.ByteArraysEqual(checkhash)) return false;

            return true;
        }
Exemple #6
0
        public static string root = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); // string root points to MyDocuments

        #endregion Fields

        #region Methods

        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                if (args[0] == "-v")
                {
                    Console.WriteLine("asdasd");
                    if (File.Exists(prefs + "/gkey"))
                    {
                            using (System.IO.StreamReader sr = new System.IO.StreamReader(prefs + "/gkey"))
                            {
                                string data = sr.ReadToEnd();
                                string[] f = data.Split('\n');
                                sr.Dispose();
                                if (f[0] == "accepted")
                                {
                                    string HASH = f[1].ToString();
                                    using (System.Security.Cryptography.SHA1CryptoServiceProvider sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider())
                                    {
                                        string hashsum = string.Empty;                  // Empty storage allocator
                                        byte[] da = sha1.ComputeHash(Encoding.Unicode.GetBytes(prefs + "/gkey"));       // byte array
                                        foreach (byte by in data)
                                        {
                                            hashsum += String.Format("{0,2:X2}", by);        // :-)
                                        }

                                        if (hashsum.ToString() != HASH.ToString())
                                        {
                                            Console.ForegroundColor = ConsoleColor.Red;
                                            Console.Write("SECURITY COMPROMISED!\n\nSHA1 HASH MODIFIED!\nRECORD DOES NOT MATCH G_KEY!\n\nCACHE WILL BE DELETED FOR SECURITY.");
                                            Console.Read();

                                        }

                                        else ;
                                        sha1.Dispose();

                                        try
                                        {
                                            Directory.Delete(prefs);
                                        }

                                        catch { ; }
                                    }
                                }

                            }

                    }
                }

            }

            else
            {
                Console.Write("This is not a standalone application.");
            }
        }