Exemple #1
0
        // https://github.com/bcgit/bc-csharp/tree/096c4894f62b7f4178ab869ec342e9351bd198dd/crypto/src/crypto/digests
        public static byte[] Keccak(string text)
        {
            byte[] encData = System.Text.Encoding.UTF8.GetBytes(text);
            Org.BouncyCastle.Crypto.Digests.KeccakDigest myHash = new Org.BouncyCastle.Crypto.Digests.KeccakDigest();

            myHash.BlockUpdate(encData, 0, encData.Length);
            byte[] compArr = new byte[myHash.GetDigestSize()];
            myHash.DoFinal(compArr, 0);

            return(compArr);
        } // End Function Keccak
Exemple #2
0
        /// <summary>
        /// Creates a proper GameID from name (calculates proper ID)
        /// </summary>
        /// <param name="symbol">Unique name identifier of the game</param>
        /// <returns>GameID object</returns>
        public static GameID FromName(string symbol)
        {
            var sha3 = new Org.BouncyCastle.Crypto.Digests.KeccakDigest(256);

            byte[] hashb = new byte[sha3.GetDigestSize()];
            byte[] value = System.Text.Encoding.UTF8.GetBytes(symbol);
            sha3.Reset();
            sha3.BlockUpdate(value, 0, value.Length);
            sha3.DoFinal(hashb, 0);
            var v = new System.Numerics.BigInteger(hashb.Reverse().ToArray());

            if (v.Sign < 0)
            {
                v = v + (BigInteger.One << 256);//make it always positive
            }
            GameID game = new GameID(v);

            game.Symbol = symbol;
            return(game);
        }