當前位置: 首頁>>代碼示例>>C#>>正文


C# SecureRandom.NextLong方法代碼示例

本文整理匯總了C#中Org.BouncyCastle.Security.SecureRandom.NextLong方法的典型用法代碼示例。如果您正苦於以下問題:C# SecureRandom.NextLong方法的具體用法?C# SecureRandom.NextLong怎麽用?C# SecureRandom.NextLong使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Org.BouncyCastle.Security.SecureRandom的用法示例。


在下文中一共展示了SecureRandom.NextLong方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Bip38Intermediate

        /// <summary>
        /// Create an intermediate from a passphrase or intermediate code
        /// </summary>
        public Bip38Intermediate(string fromstring, Interpretation interpretation, int startingSequenceNumber = 0)
        {
            if (interpretation == Interpretation.IntermediateCode) {
                createFromCode(fromstring);
            } else {
                _ownerentropy = new byte[8];

                // Get 8 random bytes to use as salt
                SecureRandom sr = new SecureRandom();
                sr.NextBytes(_ownerentropy);
                // set lot number between 100000 and 999999, and sequence number to 1
                long x = (sr.NextLong () % 900000L + 100000L) * 4096L + (long)startingSequenceNumber;
                for (int i=7; i>=4; i--) {
                    _ownerentropy[i] = (byte)(x & 0xFF);
                    x >>= 8;
                }
                createFromPassphrase(fromstring, _ownerentropy, true);
            }
        }
開發者ID:Carsten-Bit-Card,項目名稱:Bit-Card-Tool,代碼行數:22,代碼來源:Bip38Intermediate.cs

示例2: Create

        /// <summary>
        /// Creates a new random key pair, using a user-provided string to add entropy to the
        /// SecureRandom generator provided by the .NET Framework.
        /// </summary>
        public static KeyPair Create(string usersalt, bool compressed=false, byte addressType = 0)
        {
            if (usersalt == null) usersalt = "ok, whatever";
            usersalt += DateTime.UtcNow.Ticks.ToString();

            SecureRandom sr = new SecureRandom();

            byte[] poop = Util.ComputeSha256(usersalt + nonce.ToString());
            nonce++;

            byte[] newkey = new byte[32];

            for (int i = 0; i < 32; i++) {
                long x = sr.NextLong() & long.MaxValue;
                x += poop[i];
                newkey[i] = (byte)(x & 0xff);
            }
            return new KeyPair(newkey, compressed: compressed, addressType: addressType);
        }
開發者ID:BitKoot,項目名稱:Bitcoin-Address-Utility,代碼行數:23,代碼來源:KeyPair.cs


注:本文中的Org.BouncyCastle.Security.SecureRandom.NextLong方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。