private byte[] _PasswordToKey(byte[] password, byte[] engineId)
        {
            using (SHA384 sha = SHA384.Create())
            {
                var passwordIndex = 0;
                var count         = 0;
                /* Use while loop until we've done 1 Megabyte */
                var sourceBuffer = new byte[1048576];
                var buf          = new byte[64];
                while (count < 1048576)
                {
                    for (var i = 0; i < 64; ++i)
                    {
                        // Take the next octet of the password, wrapping
                        // to the beginning of the password as necessary.
                        buf[i] = password[passwordIndex++ % password.Length];
                    }

                    Buffer.BlockCopy(buf, 0, sourceBuffer, count, buf.Length);
                    count += 64;
                }

                var digest = sha.ComputeHash(sourceBuffer);

                using (var buffer = new MemoryStream())
                {
                    buffer.Write(digest, 0, digest.Length);
                    buffer.Write(engineId, 0, engineId.Length);
                    buffer.Write(digest, 0, digest.Length);
                    return(sha.ComputeHash(buffer.ToArray()));
                }
            }
        }
Exemplo n.º 2
0
        private static string PasswordCrypt384(string Password, string Salt)
        {
            using (SHA384 Hash = SHA384.Create())
            {
                byte[] sourcePasBytes    = Encoding.Unicode.GetBytes(Password);
                byte[] saltEncodingBytes = Encoding.Unicode.GetBytes(Salt);

                byte[] saltPasBytes = new byte[sourcePasBytes.Length + saltEncodingBytes.Length]; // Резервация
                for (int i = 0; i < sourcePasBytes.Length; i++)
                {
                    saltPasBytes[i] = sourcePasBytes[i]; // Заполнение
                }
                for (int i = 0; i < saltPasBytes.Length - sourcePasBytes.Length; i++)
                {
                    saltPasBytes[sourcePasBytes.Length + i] = saltPasBytes[i]; // Дополнение
                }
                byte[] saltHash = Hash.ComputeHash(saltPasBytes);

                byte[] hashWithSaltBytes = new byte[saltHash.Length + saltEncodingBytes.Length];
                for (int i = 0; i < saltHash.Length; i++)
                {
                    hashWithSaltBytes[i] = saltHash[i];
                }
                for (int i = 0; i < saltEncodingBytes.Length; i++)
                {
                    hashWithSaltBytes[saltHash.Length + i] = saltEncodingBytes[i];
                }

                byte[] finalHash = Hash.ComputeHash(hashWithSaltBytes);

                return(Convert.ToBase64String(finalHash));
            }
        }
Exemplo n.º 3
0
        public static byte[] Hash(User user)
        {
            byte[] salt        = creatSalt(user);
            byte[] hashedInput = user.Pwhash;
            using (SHA512 chippers = SHA512.Create())
            {
                if (hashedInput == null)
                {
                    hashedInput = toByte("a");
                }
                hashedInput = chippers.ComputeHash(hashedInput);
                using (MD5 chippers2 = MD5.Create())
                {
                    salt = chippers2.ComputeHash(salt);

                    using (SHA384 chippers3 = SHA384.Create())
                    {
                        hashedInput = Combine(hashedInput, salt);
                        hashedInput = chippers3.ComputeHash(hashedInput);

                        hashedInput = chippers3.ComputeHash(chippers2.ComputeHash(chippers.ComputeHash(hashedInput)));
                    }
                }
            }
            return(hashedInput);
        }
Exemplo n.º 4
0
        public void NistShaAll_1()
        {
            var data         = ByteExtensions.HexToByteArray("616263"); // "abc"
            var expectedHash = ByteExtensions.HexToByteArray("CB00753F45A35E8BB5A03D699AC65007272C32AB0EDED1631A8B605A43FF5BED8086072BA1E7CC2358BAECA134C825A7");

            var actualHash = _hashAlgorithm.ComputeHash(data);

            Assert.Equal(expectedHash, actualHash);
        }
Exemplo n.º 5
0
        public static string SaltedPassword(string password, string salt)
        {
            SHA384 sha = SHA384.Create();

            byte[] bHash = sha.ComputeHash(Encoding.ASCII.GetBytes(password));
            string hash  = BitConverter.ToString(bHash).Replace("-", "");

            string p1 = salt.Substring(0, 32);
            string p2 = salt.Substring(48, 32);

            byte[] mixed = Encoding.ASCII.GetBytes(p2 + hash + p1);

            return(BitConverter.ToString(sha.ComputeHash(mixed)).Replace("-", ""));
        }
Exemplo n.º 6
0
 private static byte[] Sha384Hash(FileStream stream)
 {
     using (SHA384 sha384 = SHA384.Create())
     {
         return(sha384.ComputeHash(stream));
     }
 }
        public string CreateSHA384(string keydata)
        {
            SHA384 sha = SHA384.Create();

            byte [] sha384 = sha.ComputeHash(Encoding.Default.GetBytes(keydata));//ASCIIEncoding.ASCII.GetBytes
            return(Convert.ToBase64String(sha384));
        }
Exemplo n.º 8
0
 public static byte[] Sha384(byte[] text)
 {
     using (SHA384 sha = SHA384.Create())
     {
         return(sha.ComputeHash(text));
     }
 }
Exemplo n.º 9
0
        //
        // Calcul SHA384
        //
        public static string SHA384HashFile(string Filename)
        {
            byte[] HashValue;
            string HashString = string.Empty;
            SHA384 MySHA384   = SHA384Managed.Create();

            try
            {
                Stream MyStream = File.OpenRead(Filename);
                HashValue = MySHA384.ComputeHash(MyStream);
                StringBuilder output = new StringBuilder(2 + (HashValue.Length * 2));
                foreach (byte b in HashValue)
                {
                    output.Append(b.ToString("x2"));
                }
                HashString = output.ToString().ToUpper();
                MyStream.Close();

                return(HashString);
            }
            catch (Exception e4)
            {
                return(e4.Message);
            }
        }
Exemplo n.º 10
0
 private byte[] CalcSha384(string filename)
 {
     using (FileStream stream = File.OpenRead(filename))
     {
         return(Sha384.ComputeHash(stream));
     }
 }
Exemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Text"></param>
        /// <param name="Uppercase"></param>
        /// <param name="Error"></param>
        /// <returns></returns>
        public static string TEXTtoSHA384(string Text, bool Uppercase = false, string Error = Constants.ErrorMessage)
        {
            try
            {
                if (Text.Length <= Constants.TextLength && Cores.UseCheck(Text, true))
                {
                    using SHA384 SHA384 = SHA384.Create();
                    byte[]        Result  = SHA384.ComputeHash(ASCIIEncoding.ASCII.GetBytes(Text));
                    StringBuilder Builder = new();
                    for (int i = 0; i < Result.Length; i++)
                    {
                        Builder.Append(Result[i].ToString("x2"));
                    }

                    return(Uppercase == false?Builder.ToString().ToLowerInvariant() : Builder.ToString().ToUpperInvariant());
                }
                else
                {
                    return(Error);
                }
            }
            catch
            {
                return(Error + Constants.ErrorTitle + "CY-TTS3!)");
            }
        }
Exemplo n.º 12
0
        private void button1_Click(object sender, EventArgs e)
        {
            // Encriptação da string digitada pelo utilizador
            SHA384 sha384 = SHA384Managed.Create();

            byte[] bytes = Encoding.UTF8.GetBytes(PasswordText.Text);
            byte[] hash  = sha384.ComputeHash(bytes);

            //Pesquisa na Base de dados o utilizador
            ListaUser = db.SearchUserBd(UserText.Text, getStringFromHash(hash)); //GetStringFromHash é o metodo que retorna a string da chave encriptada

            if ((ListaUser.Count).Equals(1))
            {
                //Invoca uma nova janela
                this.Hide();
                MainPainel janela = new MainPainel();
                janela.Closed += (s, args) => this.Close();
                janela.Show();
            }
            else
            {
                DialogResult dialogCredenciais = MessageBox.Show("Credênciais erradas, Tente Novamente",
                                                                 "Erro - Credênciais", MessageBoxButtons.OK, MessageBoxIcon.Error);
                PasswordText.Text = "";
            }
        }
Exemplo n.º 13
0
        internal static string TypeToHash(Type type)
        {
            string result = string.Empty;
            string input  = type.FullName;

            using (SHA384 hashGenerator = SHA384.Create())
            {
                var hash      = hashGenerator.ComputeHash(Encoding.Default.GetBytes(input));
                var shortHash = new byte[16];
                for (int i = 0, j = 0; i < hash.Length; ++i, ++j)
                {
                    if (j >= shortHash.Length)
                    {
                        j = 0;
                    }
                    unchecked
                    {
                        shortHash[j] += hash[i];
                    }
                }
                result = BitConverter.ToString(shortHash);
                result = result.Replace("-", string.Empty);
            }
            return(result);
        }
Exemplo n.º 14
0
        public ActionResult Uebersicht(long kontonummer, string passwort)
        {
            Kunde         kunde;
            List <Umsatz> umsaetze = new List <Umsatz>();
            Dictionary <Kunde, List <Umsatz> > data = new Dictionary <Kunde, List <Umsatz> >();

            using (SHA384 sha = SHA384Managed.Create())
                using (DeltaContext db = new DeltaContext())
                {
                    byte[] b = sha.ComputeHash(Encoding.UTF8.GetBytes(passwort));
                    string p = BitConverter.ToString(b).Replace("-", string.Empty).ToLower();

                    kunde       = db.Kunden.FirstOrDefault <Kunde>(k => k.Konto.Kontonummer == kontonummer && (k.PIN == p || k.Passwort == p)) ?? new Kunde();
                    kunde.Konto = db.Konten.FirstOrDefault <Konto>(k => k.Kontonummer == kontonummer && k.Kunde.KundeId == kunde.KundeId);

                    umsaetze.AddRange((from u in db.Umsaetze
                                       where u.Kunde.KundeId == kunde.KundeId
                                       orderby u.Wertstellung descending
                                       select u) ?? new List <Umsatz>().AsQueryable <Umsatz>());

                    data.Add(kunde, umsaetze);
                }

            return(View(data));
        }
Exemplo n.º 15
0
 public static byte[] SHA358H(Stream block)
 {
     using (SHA384 hash = SHA384.Create())
     {
         return(hash.ComputeHash(block));
     }
 }
Exemplo n.º 16
0
 public static string SHA384(string input)
 {
     using (SHA384 hash = System.Security.Cryptography.SHA384.Create())
     {
         return(string.Join("", hash.ComputeHash(Encoding.UTF8.GetBytes(input)).Select(item => item.ToString("x2"))));
     }
 }
Exemplo n.º 17
0
 public void FIPS186_b(string testName, SHA384 hash, byte[] input, byte[] result)
 {
     byte[] output = hash.ComputeHash(input, 0, input.Length);
     Assert.AreEqual(result, output, testName + ".b.1");
     Assert.AreEqual(result, hash.Hash, testName + ".b.2");
     // required or next operation will still return old hash
     hash.Initialize();
 }
Exemplo n.º 18
0
        public static TIdType GetSHA384 <TIdType>(byte[] buffer, int offset, int count)
        {
            Check <TIdType>();
            SHA384 mySHA384  = SHA384Managed.Create();
            var    hashValue = mySHA384.ComputeHash(buffer, offset, count);

            return(GetHashAlgorithm <TIdType>(hashValue));
        }
Exemplo n.º 19
0
        // ma hoa 384bit
        public static string stringTo384(string inputString)
        {
            SHA384 sha384 = SHA384Managed.Create();

            byte[] bytes = Encoding.UTF8.GetBytes(inputString);
            byte[] hash  = sha384.ComputeHash(bytes);
            return(GetStringFromHash(hash));
        }
Exemplo n.º 20
0
        public async Task <string> GetStyleHash()
        {
            string css = await GetStyle();

            byte[] data = Encoding.UTF8.GetBytes(css);
            byte[] hash = hasher.ComputeHash(data);
            return($"sha384-{Convert.ToBase64String(hash)}");
        }
Exemplo n.º 21
0
 public void CalculateHash(string input)
 {
     sw     = Stopwatch.StartNew();
     sha384 = SHA384.Create();
     byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
     byte[] hash       = sha384.ComputeHash(inputBytes);
     ElapseTime += sw.Elapsed;
     sw.Stop();
 }
 public String ComputeSHA384Hash()
 {
     using (SHA384 shaHash = SHA384.Create())
     {
         byte[]        bytes   = shaHash.ComputeHash(Encoding.UTF8.GetBytes(InputOne));
         StringBuilder builder = bytesToStringBuilder(bytes);
         return(builder.ToString());
     }
 }
Exemplo n.º 23
0
 /// <summary>
 /// CheckSum384 method implementation
 /// </summary>
 public static byte[] CheckSum384(string value)
 {
     byte[] hash = null;
     using (SHA384 sha384 = SHA384Managed.Create())
     {
         hash = sha384.ComputeHash(Encoding.UTF8.GetBytes(value));
     }
     return(hash);
 }
Exemplo n.º 24
0
 /// <summary>
 /// CheckSum384 method implementation
 /// </summary>
 public static byte[] CheckSum384(byte[] value)
 {
     byte[] hash = null;
     using (SHA384 sha384 = SHA384Cng.Create())
     {
         hash = sha384.ComputeHash(value);
     }
     return(hash);
 }
Exemplo n.º 25
0
        /// <summary>
        /// SHA384 哈希计算。
        /// </summary>
        /// <param name="plainBytes">待哈希的字节数组。</param>
        /// <returns>信息摘要的字节数组。</returns>
        public static byte[] SHA384Compute(byte[] plainBytes)
        {
            Guard.CheckArgumentNotNull(plainBytes, nameof(plainBytes));

            using (SHA384 sha = SHA384.Create())
            {
                return(sha.ComputeHash(plainBytes));
            }
        }
Exemplo n.º 26
0
        /// <summary>
        ///     Gets the hash of a file
        /// </summary>
        /// <param name="filename">File path.</param>
        public static byte[] File(string filename)
        {
            SHA384     localSha384Provider = SHA384.Create();
            FileStream fileStream          = new FileStream(filename, FileMode.Open);

            byte[] result = localSha384Provider.ComputeHash(fileStream);
            fileStream.Close();
            return(result);
        }
Exemplo n.º 27
0
        public static string CalculateSHA384(string value, Encoding encoding)
        {
            SHA384 sha384 = SHA384.Create();

            byte[] valueBytes = encoding.GetBytes(value);
            valueBytes = sha384.ComputeHash(valueBytes);

            return(valueBytes.ConvertToString());
        }
Exemplo n.º 28
0
        // функция для хэширования массива байт заданным алгоритмом, на выходе 16-ричная строка
        // аргументы: входные байты сообщения, алгоритм хэширования
        public static string HeshAlg(Byte[] arrayByte_in, string selectedAlgHesh)
        {
            byte[] arrayByte_out = new byte[0]; // Выходная последовательность байт после хеширования
            string heshString    = "";          // Хеш строка (16 ричный вид)

            try
            {
                switch (selectedAlgHesh) // Получение хеша определенным алгоритмом
                {
                case "MD5":
                    MD5 md5 = MD5.Create();
                    arrayByte_out = md5.ComputeHash(arrayByte_in);
                    md5.Dispose();
                    break;

                case "RIPEMD160":
                    RIPEMD160 ripemd160 = RIPEMD160.Create();
                    arrayByte_out = ripemd160.ComputeHash(arrayByte_in);
                    ripemd160.Dispose();
                    break;

                case "SHA1":
                    SHA1 sha1 = SHA1.Create();
                    arrayByte_out = sha1.ComputeHash(arrayByte_in);
                    sha1.Dispose();
                    break;

                case "SHA256":
                    SHA256 sha256 = SHA256.Create();
                    arrayByte_out = sha256.ComputeHash(arrayByte_in);
                    sha256.Dispose();
                    break;

                case "SHA384":
                    SHA384 sha384 = SHA384.Create();
                    arrayByte_out = sha384.ComputeHash(arrayByte_in);
                    sha384.Dispose();
                    break;

                case "SHA512":
                    SHA512 sha512 = SHA512.Create();
                    arrayByte_out = sha512.ComputeHash(arrayByte_in);
                    sha512.Dispose();
                    break;

                default: break;
                }
                heshString = BitConverter.ToString(arrayByte_out).Replace("-", "");
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message, "НЕПРЕДВИДЕННАЯ ОШИБКА", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(heshString);
        }
Exemplo n.º 29
0
        public static string GetSHA384(string input)
        {
            SHA384 sha384 = SHA384.Create();

            byte[] data = sha384.ComputeHash(Encoding.UTF8.GetBytes(input));

            sha384.Dispose();

            return(BytesToHash(data));
        }
Exemplo n.º 30
0
        public override string Hash(BufferedStream stream)
        {
            byte[] checksum = null;
            SHA384 sha      = SHA384.Create();

            checksum = sha.ComputeHash(stream);
            string hashResult = BitConverter.ToString(checksum).Replace("-", String.Empty);

            return(hashResult);
        }