当前位置: 首页>>代码示例>>C#>>正文


C# Cryptography.SHA512Managed类代码示例

本文整理汇总了C#中System.Security.Cryptography.SHA512Managed的典型用法代码示例。如果您正苦于以下问题:C# SHA512Managed类的具体用法?C# SHA512Managed怎么用?C# SHA512Managed使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SHA512Managed类属于System.Security.Cryptography命名空间,在下文中一共展示了SHA512Managed类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Encryption2

 public void Encryption2()
 {
     byte[] data = new byte[2];
     byte[] result;
     SHA512 shaM = new SHA512Managed();
     result = shaM.ComputeHash(data);
 }
开发者ID:BenanHamid,项目名称:course_work,代码行数:7,代码来源:CreateNewAccount.cs

示例2: MakeHash

 private byte[] MakeHash(byte[] data)
 {
     using (var sha512Hash = new SHA512Managed())
     {
         return sha512Hash.ComputeHash(data);
     }
 }
开发者ID:0xporky,项目名称:V8Commit,代码行数:7,代码来源:Sha512HashService.cs

示例3: EncryptOneWay

 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);
 }
开发者ID:priaonehaha,项目名称:sprocketcms,代码行数:7,代码来源:Crypto.cs

示例4: sha512encrypt

 public static string sha512encrypt(string phrase)
 {
     UTF8Encoding encoder = new UTF8Encoding();
     SHA512Managed sha512hasher = new SHA512Managed();
     byte[] hashedDataBytes = sha512hasher.ComputeHash(encoder.GetBytes(phrase));
     return byteArrayToString(hashedDataBytes);
 }
开发者ID:Ranentil,项目名称:diamonds,代码行数:7,代码来源:Crypto.cs

示例5: CreateUser

        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);
            }
        }
开发者ID:BrandonClapp,项目名称:babble,代码行数:31,代码来源:UserService.cs

示例6: btn_addUser_Click

        // 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.
            }
        }
开发者ID:paulyv,项目名称:Product-Stock-Manager,代码行数:35,代码来源:CatalogWindow.xaml.cs

示例7: GetHash

        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);
        }
开发者ID:sbarski,项目名称:transit,代码行数:25,代码来源:HashHelper.cs

示例8: GetPasswordHash

 private string GetPasswordHash(string stringPassword)
 {
     using (var sha512 = new SHA512Managed())
     {
         return BitConverter.ToString(sha512.ComputeHash(Encoding.Default.GetBytes(stringPassword)));
     }
 }
开发者ID:vvboborykin,项目名称:MicroSpy,代码行数:7,代码来源:AudioManagerOptions.cs

示例9: CreateHashSha512

        public byte[] CreateHashSha512(string userEnteredPw)
        {
            //userEnteredPw = userEnteredPw.Trim();
            SHA512Managed sha512 = new SHA512Managed();

            return sha512.ComputeHash(Encoding.UTF8.GetBytes(userEnteredPw));
        }
开发者ID:tsnyder569,项目名称:PLuvMiddleTier,代码行数:7,代码来源:CryptoHelper.cs

示例10: GetHash

        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 );
        }
开发者ID:REMSLogic,项目名称:REMSLogic,代码行数:30,代码来源:Hash.cs

示例11: BufferColumnStream

        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);
            }
        }
开发者ID:ayende,项目名称:managed-esent,代码行数:30,代码来源:ColumnStreamTests.cs

示例12: CalculateSha512Hash

 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();
 }
开发者ID:boinst,项目名称:boinst-nant,代码行数:7,代码来源:HashFunctions.cs

示例13: VerifySHA512Hash

        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);
            }
        }
开发者ID:aliaksandr-trush,项目名称:csharp-automaton,代码行数:35,代码来源:Utility.cs

示例14: Hash

 public static byte[] Hash(string s)
 {
     using (SHA512 shaM = new SHA512Managed())
     {
         return shaM.ComputeHash(Encoding.UTF8.GetBytes(s));
     }
 }
开发者ID:ikkeboe,项目名称:SideCastle,代码行数:7,代码来源:WebClass.cs

示例15: Proof

        /// <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;
        }
开发者ID:dbrgn,项目名称:pi-vote,代码行数:37,代码来源:Proof.cs


注:本文中的System.Security.Cryptography.SHA512Managed类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。