Inheritance: System.Security.Cryptography.SHA512
        // Add User buttonin logiikka
        private void btn_addUser_Click(object sender, RoutedEventArgs e)
        {
            if (tb_password1.Password == tb_password2.Password && tb_password1.Password != "" && tb_password2.Password != "" && tb_username.Text != "") // Tarkistetaan että kentät on täytetty oikein.
            {

                SHA512 sha512 = new SHA512Managed();                    // SHA512 cryptaus pitäisi riittää.
                UTF8Encoding utf8 = new UTF8Encoding();                 // SHA512 ottaa byte arrayn joten string täytyy muuttaa ennen kryptausta.
                String password = BitConverter.ToString(sha512.ComputeHash(utf8.GetBytes(tb_password1.Password)));  // Aika monimutkainen rivi joka muuttaa string byte arrayksi ja kryptaa sen

                string dbConnectionString = @"Data Source=database.db;Version=3;";               // Määritellään sqlite tietokannan nimeksi database.db ja versioksi 3.
                SQLiteConnection sqliteCon = new SQLiteConnection(dbConnectionString);           // Tehdään yhteys olio sqliteCon jota voidaan käyttää myöhemmin.
                try
                {
                    sqliteCon.Open();                                                            // Avataan sqlite yhteys
                    string Query = "INSERT INTO users (username, password) VALUES('" + this.tb_username.Text + "','" + password + "') ";    // Syötetään uuden käyttäjän tiedot tietokantaan. Huom. kryptattu salasana.
                    SQLiteCommand createCommand = new SQLiteCommand(Query, sqliteCon);           // Tehdään SQlite komento query ja sqlitecon argumenteilla.
                    createCommand.ExecuteNonQuery();                                             // Suoritetaan query.
                    sqliteCon.Close();                                                           // Suljetaan db yhteys.

                    tb_username.Text = "";                                                       // Tyhjennetään kentät ettei vahingossa upita samoja tietoja uudestaan
                    tb_password1.Password = "";
                    tb_password2.Password = "";
                    MessageBox.Show("User added successfully!");                                 // Ilmoitus käyttäjälle onnistumisesta.
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);                                                 // Tai epäonnistumisesta.
                }
            }
            else
            {
                MessageBox.Show("Oops, check the fields.");                                      // Kaikki kentät pitää täyttää, ja vieläpä oikein.
            }
        }
Exemple #2
0
 /// <summary>
 /// SHA512加密,不可逆转
 /// </summary>
 private byte[] SHA512Encrypt(byte[] code)
 {
     System.Security.Cryptography.SHA512 s512 = new System.Security.Cryptography.SHA512Managed();
     byte[] result = s512.ComputeHash(code);
     s512.Clear();
     return(result);
 }
Exemple #3
0
        private static HashAlgorithm GetHashProvider(HashProvider hashAlgorithm)
        {
            HashAlgorithm hash;
            switch (hashAlgorithm)
            {
                case HashProvider.SHA1:
                    hash = new SHA1Managed();
                    break;

                case HashProvider.SHA256:
                    hash = new SHA256Managed();
                    break;

                case HashProvider.SHA384:
                    hash = new SHA384Managed();
                    break;

                case HashProvider.SHA512:
                    hash = new SHA512Managed();
                    break;

                case HashProvider.MD5:
                default:
                    hash = new MD5CryptoServiceProvider();
                    break;
            }

            return hash;
        }
Exemple #4
0
 public static string EncryptOneWay(string data)
 {
     byte[] buf = Encoding.ASCII.GetBytes(data);
     SHA512 sha = new SHA512Managed();
     byte[] enc = sha.ComputeHash(buf);
     return HexEncoding.ToString(enc);
 }
Exemple #5
0
        private byte[] CreateIV(string strPassword)
        {
            // Convert strPassword to an array and store in chrData.
            char[] chrData = strPassword.ToCharArray();
            // Use intLength to get strPassword size.
            int intLength = chrData.GetUpperBound(0);

            // Declare bytDataToHash and make it the same size as chrData.
            byte[] bytDataToHash = new byte[intLength + 1];

            // Use For Next to convert and store chrData into bytDataToHash.
            for (int i = 0; i <= chrData.GetUpperBound(0); i++)
            {
                bytDataToHash[i] = System.Convert.ToByte(Asc(chrData[i]));
            }

            // Declare what hash to use.
            System.Security.Cryptography.SHA512Managed SHA512 = new System.Security.Cryptography.SHA512Managed();
            // Declare bytResult, Hash bytDataToHash and store it in bytResult.
            byte[] bytResult = SHA512.ComputeHash(bytDataToHash);
            // Declare bytIV(15).  It will hold 128 bits.
            byte[] bytIV = new byte[16];

            // Use For Next to put a specific size (128 bits) of bytResult into bytIV.
            // The 0 To 30 for bytKey used the first 256 bits of the hashed password.
            // The 32 To 47 will put the next 128 bits into bytIV.
            for (int i = 32; i <= 47; i++)
            {
                bytIV[i - 32] = bytResult[i];
            }

            return(bytIV); // Return the IV.
        }
 private string GetPasswordHash(string stringPassword)
 {
     using (var sha512 = new SHA512Managed())
     {
         return BitConverter.ToString(sha512.ComputeHash(Encoding.Default.GetBytes(stringPassword)));
     }
 }
        public byte[] CreateHashSha512(string userEnteredPw)
        {
            //userEnteredPw = userEnteredPw.Trim();
            SHA512Managed sha512 = new SHA512Managed();

            return sha512.ComputeHash(Encoding.UTF8.GetBytes(userEnteredPw));
        }
Exemple #8
0
        public static string GetHash(string text, string type, Encoding enc, string outputType = null)
        {
            type = type.ToLower();

            byte[] message = enc.GetBytes( text );
            HashAlgorithm algo = null;

            switch (type)
            {
            case "md5":
                algo = new MD5CryptoServiceProvider();
                break;
            case "sha1":
                algo = new SHA1Managed();
                break;
            case "sha256":
                algo = new SHA256Managed();
                break;
            case "sha384":
                algo = new SHA384Managed();
                break;
            case "sha512":
                algo = new SHA512Managed();
                break;
            default:
                throw new ArgumentException("Type must be one of ['md5', 'sha1', 'sha256', 'sha384', 'sha512'].", "type");
            }

            return GetOutput( algo.ComputeHash( message ), outputType );
        }
        public void BufferColumnStream()
        {
            var data = new byte[1024];

            var memoryStream = new MemoryStream();

            Api.JetBeginTransaction(this.sesid);
            Api.JetPrepareUpdate(this.sesid, this.tableid, JET_prep.Insert);
            using (var stream = new BufferedStream(new ColumnStream(this.sesid, this.tableid, this.columnidLongText), SystemParameters.LVChunkSizeMost))
            {
                for (int i = 0; i < 10; ++i)
                {
                    stream.Write(data, 0, data.Length);
                    memoryStream.Write(data, 0, data.Length);
                }
            }

            this.UpdateAndGotoBookmark();
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush);

            var hasher = new SHA512Managed();
            memoryStream.Position = 0;
            var expected = hasher.ComputeHash(memoryStream);

            using (var stream = new BufferedStream(new ColumnStream(this.sesid, this.tableid, this.columnidLongText), SystemParameters.LVChunkSizeMost))
            {
                var actual = hasher.ComputeHash(stream);
                CollectionAssert.AreEqual(expected, actual);
            }
        }
Exemple #10
0
 public static string CalculateSha512Hash(string input)
 {
     var inputBytes = Encoding.UTF8.GetBytes(input);
     var hasher = new SHA512Managed();
     var hashBytes = hasher.ComputeHash(inputBytes);
     return BitConverter.ToString(hashBytes).Replace("-", string.Empty).ToLowerInvariant();
 }
Exemple #11
0
 public static byte[] BytesToHash(byte[] byteArray)
 {
     byte[] result;
     SHA512 shaM = new SHA512Managed();
     result = shaM.ComputeHash(byteArray);
     return result;
 }
        public static void VerifySHA512Hash(byte[] bytesA, byte[] bytesB)
        {
            SHA512 shaM = new SHA512Managed();
            byte[] hashA = shaM.ComputeHash(bytesA);
            byte[] hashB = shaM.ComputeHash(bytesB);

            // Create a StringComparer an compare the hashes.
            StringComparer comparer = StringComparer.OrdinalIgnoreCase;

            // Create a new Stringbuilder to collect the bytes
            // and create a string.
            StringBuilder hashAStringBuilder = new StringBuilder();
            StringBuilder hashBStringBuilder = new StringBuilder();

            // Loop through each byte of the hashed data
            // and format each one as a hexadecimal string.
            for (int i = 0; i < hashA.Length; i++)
            {
                hashAStringBuilder.Append(hashA[i].ToString("x2"));
            }

            string inputA = hashAStringBuilder.ToString();

            for (int i = 0; i < hashB.Length; i++)
            {
                hashBStringBuilder.Append(hashB[i].ToString("x2"));
            }

            string inputB = hashBStringBuilder.ToString();

            if (comparer.Compare(inputA, inputB) != 0)
            {
                Assert.Fail("Hash not match! Expected: '{0}', but was '{1}'", inputA, inputB);
            }
        }
Exemple #13
0
        //Generating Hash Value, Combining userpassword and above random salt value
        //public String GenerateSHA256Hash(String input, String salt)
        //{
        //    byte[] bytes = System.Text.Encoding.UTF8.GetBytes(input + salt);
        //    System.Security.Cryptography.SHA256Managed sha256hashstring = new System.Security.Cryptography.SHA256Managed();
        //    byte[] hash = sha256hashstring.ComputeHash(bytes);
        //    return ByteArrayToHexString(hash);
        //}

        public String GenerateSHA256Hash(String input, String salt)
        {
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(input + salt);
            System.Security.Cryptography.SHA512Managed sha512hashstring = new System.Security.Cryptography.SHA512Managed();
            byte[] hash = sha512hashstring.ComputeHash(bytes);
            return(ByteArrayToHexString(hash));
        }
Exemple #14
0
 public static byte[] Hash(string s)
 {
     using (SHA512 shaM = new SHA512Managed())
     {
         return shaM.ComputeHash(Encoding.UTF8.GetBytes(s));
     }
 }
Exemple #15
0
        private byte[] CreateKey(string strPassword)
        {
            // Convert strPassword to an array and store in chrData.
            char[] chrData = strPassword.ToCharArray();
            // Use intLength to get strPassword size.
            int intLength = chrData.GetUpperBound(0);

            // Declare bytDataToHash and make it the same size as chrData.
            byte[] bytDataToHash = new byte[intLength + 1];

            // Use For Next to convert and store chrData into bytDataToHash.
            for (int i = 0; i <= chrData.GetUpperBound(0); i++)
            {
                bytDataToHash[i] = System.Convert.ToByte(Asc(chrData[i]));
            }

            // Declare what hash to use.
            System.Security.Cryptography.SHA512Managed SHA512 = new System.Security.Cryptography.SHA512Managed();
            // Declare bytResult, Hash bytDataToHash and store it in bytResult.
            byte[] bytResult = SHA512.ComputeHash(bytDataToHash);
            // Declare bytKey(31).  It will hold 256 bits.
            byte[] bytKey = new byte[32];

            // Use For Next to put a specific size (256 bits) of
            // bytResult into bytKey. The 0 To 31 will put the first 256 bits
            // of 512 bits into bytKey.
            for (int i = 0; i <= 31; i++)
            {
                bytKey[i] = bytResult[i];
            }

            return(bytKey); // Return the key.
        }
Exemple #16
0
        private static byte[] CreateKey(string strPassword)
        {
            char[] array = strPassword.ToCharArray ();
            int upperBound = array.GetUpperBound (0);
            byte[] array2 = new byte[upperBound + 1];
            int upperBound2 = array.GetUpperBound (0);

            for (int i = 0; i <= upperBound2; i++)
            {
                array2 [i] = (byte)array [i];
            }

            SHA512Managed sHA512Managed = new SHA512Managed ();
            byte[] array3 = sHA512Managed.ComputeHash (array2);
            byte[] array4 = new byte[32];
            int num = 0;
            do
            {
                array4 [num] = array3 [num];
                num++;
            }
            while (num <= 31);

            return array4;
        }
Exemple #17
0
 private byte[] MakeHash(byte[] data)
 {
     using (var sha512Hash = new SHA512Managed())
     {
         return sha512Hash.ComputeHash(data);
     }
 }
Exemple #18
0
 //Get the file's hash in SHA512
 public string GetFileHash(string file)
 {
     SHA512Managed sha = new SHA512Managed();
     FileStream stream = File.OpenRead(file);
     byte[] hash = sha.ComputeHash(stream);
     return BitConverter.ToString(hash).Replace("-", String.Empty);
 }
Exemple #19
0
        string password_crypt(string password, string setting)
        {
            string _setting = setting.Substring(0, 12);
            if (_setting[0] != '$' || _setting[2] != '$')
                return null;

            int count_log2 = password_get_count_log2(setting);
            string salt = _setting.Substring(4, 8);
            if (salt.Length < 8)
                return null;
            int count = 1 << count_log2;
            SHA512 shaM = new SHA512Managed();
            Encoding unicode = new UnicodeEncoding(true, false);
            byte[] data = unicode.GetBytes(salt + password);
            byte[] pass = unicode.GetBytes(password);
            byte[] hash = shaM.ComputeHash(data);
            for (int c = 0; c < count; c++)
            {
                data = new byte[hash.Length + pass.Length];
                hash.CopyTo(data, 0);
                pass.CopyTo(data, hash.Length);
                hash = shaM.ComputeHash(data);
            }
            string output = setting + custom64(hash);
            return output.Substring(0, hash_length);
        }
Exemple #20
0
        /// <summary>
        /// Encrypts the specified password using the specified hash algoritm
        /// </summary>
        /// <param name="passWord"></param>
        /// <param name="salt"></param>
        /// <param name="hashAlgoritm"></param>
        /// <returns></returns>
        public static string EncryptPassWord(string passWord, string salt, HashAlgoritm hashAlgoritm)
        {
            UTF8Encoding textConverter = new UTF8Encoding();
            HashAlgorithm hash;

            switch (hashAlgoritm)
            {
                case HashAlgoritm.SHA1:
                    hash = new SHA1Managed();
                    break;
                case HashAlgoritm.SHA256:
                    hash = new SHA256Managed();
                    break;
                case HashAlgoritm.SHA384:
                    hash = new SHA384Managed();
                    break;
                case HashAlgoritm.SHA512:
                    hash = new SHA512Managed();
                    break;
                default:
                    hash = new MD5CryptoServiceProvider();
                    break;
            }

            string tmpPassword = string.Format("{0}_{1}", passWord, salt);
            byte[] passBytes = textConverter.GetBytes(tmpPassword);

            return Convert.ToBase64String(hash.ComputeHash(passBytes));
        }
Exemple #21
0
        public static string GetHash(string text, HashType hashType = HashType.SHA512)
        {
            HashAlgorithm hashAlgorithm = null;

            switch (hashType)
            {
                case HashType.MD5:
                    hashAlgorithm = new MD5CryptoServiceProvider();
                    break;

                case HashType.SHA1:
                    hashAlgorithm = new SHA1Managed();
                    break;

                case HashType.SHA256:
                    hashAlgorithm = new SHA256Managed();
                    break;

                case HashType.SHA512:
                    hashAlgorithm = new SHA512Managed();
                    break;
            }

            return ComputeHash(text, hashAlgorithm);
        }
Exemple #22
0
        /// <summary>
        /// 哈希加密一个字符串
        /// </summary>
        /// <param name="Security"></param>
        /// <returns></returns>
        public static string HashEncoding(string Security)
        {
            byte[] Value;
            SHA512Managed Arithmetic = null;
            try
            {
                UnicodeEncoding Code = new UnicodeEncoding();
                byte[] Message = Code.GetBytes(Security);

                Arithmetic = new SHA512Managed();
                Value = Arithmetic.ComputeHash(Message);
                Security = "";
                foreach (byte o in Value)
                {
                    Security += (int)o + "O";
                }

                return Security;
            }
            catch (Exception ex)
            {

                throw ex;
            }
            finally
            {
                if (Arithmetic!=null)
                {
                    Arithmetic.Clear();
                }
            }
        }
Exemple #23
0
 public static string sha512encrypt(string phrase)
 {
     UTF8Encoding encoder = new UTF8Encoding();
     SHA512Managed sha512hasher = new SHA512Managed();
     byte[] hashedDataBytes = sha512hasher.ComputeHash(encoder.GetBytes(phrase));
     return byteArrayToString(hashedDataBytes);
 }
        public static byte[] GenerateHash(HashingStrategy strategy, string password, byte[] salt, int iterations = 1000)
        {
            var bytes = Encoding.UTF8.GetBytes(password).Concat(salt);

            switch (strategy)
            {
                case HashingStrategy.SHA256:
                    using (var sha256 = new SHA256Managed())
                    {
                        return sha256.ComputeHash(bytes.ToArray());
                    }

                case HashingStrategy.SHA512:
                    using (var sha512 = new SHA512Managed())
                    {
                        return sha512.ComputeHash(bytes.ToArray());
                    }
                case HashingStrategy.PBKDF2:
                    using (var pbkdf2 = new Rfc2898DeriveBytes(password, salt) { IterationCount = iterations })
                    {
                        return pbkdf2.GetBytes(salt.Length);
                    }
            }

            throw new NotImplementedException();
        }
 public void Encryption2()
 {
     byte[] data = new byte[2];
     byte[] result;
     SHA512 shaM = new SHA512Managed();
     result = shaM.ComputeHash(data);
 }
 // Method that combines two different salts with the
 // password in between + hashing and returning the hash
 public string GetHashedPassword(string a_salt1, string a_password, string a_salt2)
 {
     SHA512Managed hsh = new SHA512Managed();
     byte[] combinedPswdHsh = hsh.ComputeHash(Encoding.UTF8.GetBytes
         (a_salt1 + a_password.Trim() + a_salt2));
     return Convert.ToBase64String(combinedPswdHsh).Trim();
 }
Exemple #27
0
        public HttpResponseMessage Register(User user)
        {
            if (!_validator.Validate(user.Password))
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            using (SHA512 sha = new SHA512Managed())
            {
                user.Password = BitConverter.ToString(sha.ComputeHash(Encoding.UTF8.GetBytes(user.Password))).Replace("-", string.Empty);
            }

            _db.Users.Add(user);
            if(_db.GetValidationErrors().Any())
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            try
            {
                _db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                return Request.CreateResponse(HttpStatusCode.Conflict);
            }

            return Request.CreateResponse(HttpStatusCode.Created);
        }
Exemple #28
0
 /// <summary>
 /// Every time is created new instance of class to guarantee thread safety
 /// </summary>
 /// <param name="function"></param>
 /// <returns></returns>
 private HashAlgorithm GetAlgorithmByFunctionName(string function)
 {
     HashAlgorithm a;
     switch (Util.Convertion.EnumNameToValue<HashFunction>(function))
     {
         case HashFunction.MD5:
             a = new MD5CryptoServiceProvider();
             break;
         case HashFunction.SHA1:
             a = new SHA1Managed();
             break;
         case HashFunction.SHA256:
             a = new SHA256Managed();
             break;
         case HashFunction.SHA384:
             a = new SHA384Managed();
             break;
         case HashFunction.SHA512:
             a = new SHA512Managed();
             break;
         default:
             throw new ArgumentException("Unknown function", "function");
     }
     return a;
 }
        private static string Sha512(string text)
        {
            var textBytes = new UnicodeEncoding().GetBytes(text);
            var hashValue = new SHA512Managed().ComputeHash(textBytes);

            return hashValue.Aggregate("", (current, x) => current + String.Format("{0:x2}", x));
        }
Exemple #30
0
        /// <summary>
        /// Retorna el hash en format string de l'string paràmetre
        /// </summary>
        /// <param name="textIn"> és el text del qual volem calcular el hash</param>
        /// <returns> retorna un string amb el hash resultat o null si hi ha error</returns>
        static string CalculaHash(string textIn)
        {
            try
            {
                // Convertim l'string a un array de bytes
                byte[] bytesIn = UTF8Encoding.UTF8.GetBytes(textIn);
                // Instanciar classe per fer hash
                SHA512Managed SHA512 = new SHA512Managed();
                // Calcular hash
                byte[] hashResult = SHA512.ComputeHash(bytesIn);

                // Si volem mostrar el hash per pantalla o guardar-lo en un arxiu de text
                // cal convertir-lo a un string

                String textOut = BitConverter.ToString(hashResult, 0);

                // Eliminem la classe instanciada
                SHA512.Dispose();
                return textOut;
            }
            catch (Exception)
            {
                Console.WriteLine("Error calculant el hash");
                Console.ReadKey(true);
                return null;
            }
        }
Exemple #31
0
 // encrypt user IP (one-way) before storing it in database
 public static string CreateHash(string ip)
 {
     using (SHA512 shaM = new SHA512Managed())
     {
         return Convert.ToBase64String(shaM.ComputeHash(Encoding.UTF8.GetBytes(ip)));
     }
 }
Exemple #32
0
        /// <summary>
        /// Creates a new sum proof.
        /// </summary>
        /// <param name="r">The randomness used to encrypt the vote.</param>
        /// <param name="voteSum">The sum of all votes for which to generate a proof.</param>
        /// <param name="publicKey">The public key with which the vote was encrypted.</param>
        /// <param name="parameters">Cryptographic Parameters.</param>
        public Proof(BigInt r, Vote voteSum, BigInt publicKey, BaseParameters parameters)
        {
            if (r == null)
            throw new ArgumentNullException("r");
              if (voteSum == null)
            throw new ArgumentNullException("vote");
              if (publicKey == null)
            throw new ArgumentNullException("publicKey");
              if (parameters == null)
            throw new ArgumentNullException("parameters");

              BigInt r0 = parameters.Random();

              T0 = publicKey.PowerMod(r0, parameters.P);

              MemoryStream serializeStream = new MemoryStream();
              SerializeContext serializer = new SerializeContext(serializeStream);
              serializer.Write(voteSum.Ciphertext);
              serializer.Write(voteSum.HalfKey);
              serializer.Write(publicKey);
              serializer.Write(T0);
              serializer.Close();
              serializeStream.Close();

              SHA512Managed sha512 = new SHA512Managed();
              byte[] hash = sha512.ComputeHash(serializeStream.ToArray());
              C0 = hash[0] | (hash[1] << 8);

              S0 = r0 + r * C0;
        }
Exemple #33
0
 /// <summary>
 /// Creates a SHA512 hash of a string
 /// </summary>
 /// <param name="text"></param>
 /// <param name="salt"></param>
 /// <param name="extraHashKey"></param>
 /// <returns></returns>
 public static string HashSha512(string text, string salt, string extraHashKey = "")
 {
     using (SHA512 shaM = new SHA512Managed())
     {
         return Convert.ToBase64String(shaM.ComputeHash(System.Text.Encoding.UTF8.GetBytes(text + extraHashKey + salt)));
     }
 }
 public static string CreateSHAHash(string PasswordSHA512)
 {
     System.Security.Cryptography.SHA512Managed sha512 = new System.Security.Cryptography.SHA512Managed();
     Byte[] EncryptedSHA512 = sha512.ComputeHash(System.Text.Encoding.UTF8.GetBytes(PasswordSHA512));
     sha512.Clear();
     return(Convert.ToBase64String(EncryptedSHA512));
 }
Exemple #35
0
        public void CreateUser(UserInfo userInfo)
        {
            if (userInfo == null)
            {
                throw new ArgumentNullException(nameof(userInfo));
            }
            if (string.IsNullOrWhiteSpace(userInfo.Username))
            {
                throw new ArgumentNullException(nameof(userInfo.Username));
            }

            if (string.IsNullOrWhiteSpace(userInfo.Password))
            {
                throw new ArgumentNullException(nameof(userInfo.Password));
            }

            if (UsernameExists(userInfo.Username))
            {
                throw new Exception("Username already exists, please enter a different username");
            }

            using (var shazam = new SHA512Managed())
            {
                var salt = GenerateSaltValue();
                var passwordAndSalt = userInfo.Password + salt;
                var hashedPassword = Encoding.UTF8.GetString(shazam.ComputeHash(Encoding.UTF8.GetBytes(passwordAndSalt)));
                userInfo.Password = hashedPassword;
                userInfo.Salt = salt;
                userDal.CreateUser(userInfo);
            }
        }
 public string getSha512(string Password)
 {
     System.Security.Cryptography.SHA512Managed HashTool = new System.Security.Cryptography.SHA512Managed();
     Byte[] PasswordAsByte = System.Text.Encoding.UTF8.GetBytes(Password);
     Byte[] EncryptedBytes = HashTool.ComputeHash(PasswordAsByte);
     HashTool.Clear();
     return(Convert.ToBase64String(EncryptedBytes));
 }
Exemple #37
0
         /// <summary>
         /// SHA512加密,不可逆转
         /// </summary>
         /// <param name="str">string str:被加密的字符串</param>
         /// <returns>返回加密后的字符串</returns>
         private static string SHA512Encrypt(string str)
 {
     System.Security.Cryptography.SHA512 s512 = new System.Security.Cryptography.SHA512Managed();
     byte[] byte1;
     byte1 = s512.ComputeHash(Encoding.Default.GetBytes(str));
     s512.Clear();
     return(Convert.ToBase64String(byte1));
 }
 /// <summary>
 /// Genera el hash de la familia SHA2, SHA512 de la password en todo proceso de registro o logeo. El parámetro salt se suele dejar vacio, pues no se usa sal en esta aplicación.
 /// </summary>
 /// <param name="password"></param>
 /// <param name="salt"></param>
 /// <returns></returns>
 public static string GetSHA512(string password, string salt)
 {
     System.Security.Cryptography.SHA512Managed HashTool = new System.Security.Cryptography.SHA512Managed();
     Byte[] PasswordAsByte = System.Text.Encoding.UTF8.GetBytes(string.Concat(password, salt));
     Byte[] EncryptedBytes = HashTool.ComputeHash(PasswordAsByte);
     HashTool.Clear();
     return(BitConverter.ToString(EncryptedBytes));
 }
Exemple #39
0
 internal static string CreateSHAHash(string password, string salt)
 {
     System.Security.Cryptography.SHA512Managed HashTool = new System.Security.Cryptography.SHA512Managed();
     Byte[] PasswordAsByte = System.Text.Encoding.UTF8.GetBytes(string.Concat(password, salt));
     Byte[] EncryptedBytes = HashTool.ComputeHash(PasswordAsByte);
     HashTool.Clear();
     return(Convert.ToBase64String(EncryptedBytes));
 }
Exemple #40
0
        public static string Encrypt(string password, string salt)
        {
            var saltedPassword = salt + password;
            var saltedBytes    = Encoding.Default.GetBytes(saltedPassword);
            var algorithm      = new CR.SHA512Managed();
            var hashBytes      = algorithm.ComputeHash(saltedBytes);

            return(Convert.ToBase64String(hashBytes));
        }
        public String GenerateSHA512Hash(String input, String salt)
        {
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(input + salt);
            System.Security.Cryptography.SHA512Managed sha512 =
                new System.Security.Cryptography.SHA512Managed();
            byte[] hash = sha512.ComputeHash(bytes);

            return(BitConverter.ToString(hash).Replace("-", ""));
        }
Exemple #42
0
        public static string GTBSHA512(string hash_string)
        {
            System.Security.Cryptography.SHA512Managed sha512 = new System.Security.Cryptography.SHA512Managed();
            Byte[] EncryptedSHA512 = sha512.ComputeHash(System.Text.Encoding.UTF8.GetBytes(hash_string));
            sha512.Clear();
            string hashed = BitConverter.ToString(EncryptedSHA512).Replace("-", "").ToLower();

            return(hashed);
        }
Exemple #43
0
        public static string EncriptarSHA512(string cad)
        {
            byte[] data = System.Text.Encoding.ASCII.GetBytes(cad);
            byte[] result;

            SHA512Managed shaM = new System.Security.Cryptography.SHA512Managed();

            result = shaM.ComputeHash(data);
            return(BitConverter.ToString(result).Replace("-", string.Empty));
        }
Exemple #44
0
    public string Hash(string data)
    {
        var bytes = new UTF8Encoding().GetBytes(data);

        byte[] hashBytes;
        using (var algorithm = new System.Security.Cryptography.SHA512Managed()) {
            hashBytes = algorithm.ComputeHash(bytes);
        }
        return(Convert.ToBase64String(hashBytes));
    }
        public string CreateSHAHash(string User, string Password, string Salt) //Hash and Salt -- Hash SHA512.
        {
            String Text = User + Password;

            System.Security.Cryptography.SHA512Managed HashTool = new System.Security.Cryptography.SHA512Managed();
            Byte[] HashAsByte     = System.Text.Encoding.UTF8.GetBytes(string.Concat(Text, Salt));
            Byte[] EncryptedBytes = HashTool.ComputeHash(HashAsByte);
            HashTool.Clear();
            return(Convert.ToBase64String(EncryptedBytes));
        }
Exemple #46
0
 public static string HashPassword(this string password, string salt)
 {
     byte[] bytes = new UTF8Encoding().GetBytes(salt + password);
     byte[] hashBytes;
     using (Security.Cryptography.SHA512Managed algorithm = new Security.Cryptography.SHA512Managed())
     {
         hashBytes = algorithm.ComputeHash(bytes);
     }
     return(Convert.ToBase64String(hashBytes));
 }
    public byte[] Sha512Sum(string strToEncrypt)
    {
        System.Text.UTF8Encoding ue = new System.Text.UTF8Encoding();
        byte[] bytes = ue.GetBytes(text);

        // encrypt bytes
        System.Security.Cryptography.SHA512 sha512 = new System.Security.Cryptography.SHA512Managed();
        byte[] hashBytes = sha512.ComputeHash(bytes);

        return(hashBytes);
    }
Exemple #48
0
        // Función que encripta la contraseña mediante SHA512(Se puede cambiar SHA256) utilizando un salt generado previamente.
        private string encriptarSHA512(String argPassword, string salt)
        {
            // Encriptando
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(argPassword + salt);
            System.Security.Cryptography.SHA512Managed sha256hashstring =
                new System.Security.Cryptography.SHA512Managed();
            byte[] hash         = sha256hashstring.ComputeHash(bytes);
            var    passwordCryp = Convert.ToBase64String(hash);

            return(passwordCryp);
        }
Exemple #49
0
        public static string Encrypt(string text)
        {
            SHA512 hash = new System.Security.Cryptography.SHA512Managed();

            byte[] textBytes = System.Text.Encoding.Default.GetBytes(text);
            byte[] hashBytes = hash.ComputeHash(textBytes);
            string result    = string.Empty;

            for (int i = 0; i < hashBytes.Length; i++)
            {
                result += hashBytes[i].ToString("X");
            }

            return(result);
        }
 public JsonResult GenerateSHA512StringFors2s(string inputString)
 {
     using (SHA512 sha512Hash = SHA512.Create())
     {
         //From String to byte array
         byte[] sourceBytes = Encoding.UTF8.GetBytes(inputString);
         byte[] hashBytes   = sha512Hash.ComputeHash(sourceBytes);
         string hash        = BitConverter.ToString(hashBytes).Replace("-", String.Empty);
         System.Security.Cryptography.SHA512Managed sha512 = new System.Security.Cryptography.SHA512Managed();
         Byte[] EncryptedSHA512 = sha512.ComputeHash(System.Text.Encoding.UTF8.GetBytes(hash));
         sha512.Clear();
         var bts = Convert.ToBase64String(EncryptedSHA512);
         return(Json(hash, JsonRequestBehavior.AllowGet));
     }
 }
Exemple #51
0
 public static string HashEncoding(string Security)
 {
     System.Text.UnicodeEncoding unicodeEncoding = new System.Text.UnicodeEncoding();
     byte[] bytes = unicodeEncoding.GetBytes(Security);
     System.Security.Cryptography.SHA512Managed sHA512Managed = new System.Security.Cryptography.SHA512Managed();
     byte[] array = sHA512Managed.ComputeHash(bytes);
     Security = "";
     byte[] array2 = array;
     for (int i = 0; i < array2.Length; i++)
     {
         byte b = array2[i];
         Security = Security + (int)b + "O";
     }
     return(Security);
 }
        public static string SHA512Encode(string input)
        {
            using (System.Security.Cryptography.SHA512Managed sha1 = new System.Security.Cryptography.SHA512Managed())
            {
                var           hash   = sha1.ComputeHash(Encoding.UTF8.GetBytes(input));
                StringBuilder result = new StringBuilder(hash.Length * 2);

                foreach (byte b in hash)
                {
                    result.Append(b.ToString("X2"));
                }

                return(result.ToString());
            }
        }
Exemple #53
0
        public string obtenerHash(string pCadena)
        {
            string textoPlano = pCadena;
            string hashkey    = "*hg849gh84th==3tg7-534d=_";

            System.Security.Cryptography.SHA512Managed HashTool = new System.Security.Cryptography.SHA512Managed();
            Byte[] HashAsByte     = System.Text.Encoding.UTF8.GetBytes(string.Concat(textoPlano, hashkey));
            Byte[] EncryptedBytes = HashTool.ComputeHash(HashAsByte);
            HashTool.Clear();

            string resultado = Convert.ToBase64String(EncryptedBytes);

            resultado = resultado.Substring(0, 50);

            return(resultado);
        }
Exemple #54
0
        public static string GetSHA512(string text)
        {
            System.Text.UnicodeEncoding UE = new System.Text.UnicodeEncoding();
            byte[] hashValue;
            byte[] message = UE.GetBytes(text);

            System.Security.Cryptography.SHA512Managed hashString = new System.Security.Cryptography.SHA512Managed();
            string hex = "";

            hashValue = hashString.ComputeHash(message);

            foreach (byte x in hashValue)
            {
                hex += String.Format("{0:x2}", x);
            }
            return(hex);
        }
Exemple #55
0
		public static string MD5Hash(string _password)
		{
			SHA512 sha512 = new System.Security.Cryptography.SHA512Managed();

			byte[] sha512Bytes = System.Text.Encoding.Default.GetBytes(_password);

			byte[] cryString = sha512.ComputeHash(sha512Bytes);

			string hashedPwd = string.Empty;

			for (int i = 0; i < cryString.Length; i++)
			{
				hashedPwd += cryString[i].ToString("X2");
			}

			return hashedPwd;
		}
Exemple #56
0
 public static string HashPassword(this string str)
 {
     try
     {
         var    bytes = new UTF8Encoding().GetBytes(str);
         byte[] hashBytes;
         using (var algorithm = new System.Security.Cryptography.SHA512Managed())
         {
             hashBytes = algorithm.ComputeHash(bytes);
             return(Convert.ToBase64String(hashBytes));
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemple #57
0
        public static string Hash(string password)
        {
            var bytes = new UTF8Encoding().GetBytes(password);

            byte[] hashBytes;
            try
            {
                using (var algorithm = new System.Security.Cryptography.SHA512Managed())
                {
                    hashBytes = algorithm.ComputeHash(bytes);
                }
                return(Convert.ToBase64String(hashBytes));
            }
            finally
            {
                Log.Error("Problem With Encrypt");
            }
        }
Exemple #58
0
        }  // END public String GetHash(String ValueToHash, String ValueLocale, String SaltToUse)

        /// <summary>
        /// This function takes a value you want hashed, uses SHA-512 for strength, and includes a locale extender such as a computer name,
        /// and a salt value that has no intrinsic meaning.  The value returned is the hash string in Base 64.
        /// </summary>
        /// <param name="ValueToHash">This is the value, such as a password.  It will usually be the same over a number of instances on multiple machines.</param>
        /// <param name="ValueLocale">This is a value specific to the machine, such as machine name.  It should be deterministic on every use.</param>
        /// <param name="SaltToUse">This is a value that extends the hash for security.</param>
        /// <returns>The value returned is the hash string in Base 64</returns>
        public String GetHash(String ValueToHash, String ValueLocale, String SaltToUse)
        {
            DateTime dtmMethodStart = DateTime.Now;

            String ReturnValue = "";

            SHA512Managed Hasher = null;

            try
            {
                Hasher = new System.Security.Cryptography.SHA512Managed();

                Byte[] Text2Hash = System.Text.Encoding.UTF8.GetBytes(String.Concat(ValueToHash.Trim(),
                                                                                    ValueLocale.ToUpper(),
                                                                                    SaltToUse.Trim()));

                Byte[] PlateOfHash = Hasher.ComputeHash(Text2Hash);

                ReturnValue = Convert.ToBase64String(PlateOfHash);
            }
            catch (Exception exUnhandled)
            {
                exUnhandled.Data.Add("ValueToHash", ValueToHash ?? "");
                exUnhandled.Data.Add("ValueLocale", ValueLocale ?? "");
                exUnhandled.Data.Add("SaltToUse", SaltToUse ?? "");

                throw;
            } // END catch
            finally
            {
                if (Hasher != null)
                {
                    Hasher.Clear();

                    Hasher.Dispose();

                    Hasher = null;
                }
            }

            return(ReturnValue);
        } // END public  String GetHash(String ValueToHash, String ValueLocale, String SaltToUse)
Exemple #59
0
        /*Kóðinn í CreatePasswordHash er tekinn af http://stackoverflow.com/questions/12592036/taking-a-c-sharp-sha512-hash-and-compare-it-in-php
         * og aðlagaður*/
        public static string CreatePasswordHash(string password)
        {
            string Pwd    = password;
            SHA512 sha512 = new System.Security.Cryptography.SHA512Managed(); //Nær í afrit af klasanum SHA512Managed til að við getum hashað

            byte[] sha512Bytes = System.Text.Encoding.UTF8.GetBytes(Pwd);     //Þarna fáum við út byte-in og encodum þau í UTF8 og geymum
            //þessi byte í byte array.

            byte[] cryString = sha512.ComputeHash(sha512Bytes);//Hér er hvert og eitt hash byte reiknað út

            string hashedPwd = null;

            //Svo bara lúppum við í gegnum cryString sem inniheldur hashana. Við setjum þá saman í streng með þessari lúppu:
            for (int i = 0; i < cryString.Length; i++)
            {
                hashedPwd += cryString[i].ToString();
            }

            return(hashedPwd);
        }
Exemple #60
0
        public static string CreatePasswordHash(string _password, string _salt)
        {
            string saltAndPwd = String.Concat(_password, _salt);
            SHA512 sha512     = new System.Security.Cryptography.SHA512Managed();

            byte[] sha512Bytes = System.Text.Encoding.Default.GetBytes(saltAndPwd);

            byte[] cryString = sha512.ComputeHash(sha512Bytes);

            string hashedPwd = string.Empty;

            for (int i = 0; i < cryString.Length; i++)
            {
                hashedPwd += cryString[i].ToString("X");
            }

            sha512.Clear();
            sha512.Dispose();

            return(hashedPwd);
        }