Inheritance: HashAlgorithm
コード例 #1
0
        /// <summary>	Construct from base58 bitshares public key </summary>
        ///
        /// <remarks>	Paul, 08/12/2014. </remarks>
        ///
        /// <param name="base58BtsPubKey">	The base 58 bts pub key. </param>
        public BitsharesPubKey(string base58BtsPubKey)
        {
            m_ripe = RIPEMD160.Create();

            if (base58BtsPubKey.Length == 54)
            {
                base58BtsPubKey = base58BtsPubKey.Substring(4, base58BtsPubKey.Length - 4);
            }
            else if (base58BtsPubKey.Length == 53)
            {
                base58BtsPubKey = base58BtsPubKey.Substring(3, base58BtsPubKey.Length - 3);
            }
            else
            {
                throw new NotImplementedException();
            }

            byte[] data = Base58.ToByteArray(base58BtsPubKey);
            Debug.Assert(data.Length == 37);

            byte[] pubkeyCheck = RIPEMD160.Create().ComputeHash(data, 0, 33);

            // check the hash first four bytes are equal to the last four bytes of the pub key
            for (int i = 0; i < 4; i++)
            {
                if (pubkeyCheck[i] != data[i + 33])
                {
                    throw new BadChecksumException();
                }
            }

            m_compressed = new byte[33];
            Array.Copy(data, 0, m_compressed, 0, m_compressed.Length);
        }
コード例 #2
0
        public void Execute()
        {
            Progress(0.5, 1.0);

            if (inputData != null && inputData.Length >= 0)
            {
                System.Security.Cryptography.RIPEMD160 ripeMd160Hash = System.Security.Cryptography.RIPEMD160.Create();
                using (CStreamReader reader = inputData.CreateReader())
                {
                    OutputData = ripeMd160Hash.ComputeHash(reader);
                }

                GuiLogMessage("Hash created.", NotificationLevel.Info);
                Progress(1, 1);
            }
            else
            {
                if (inputData == null)
                {
                    GuiLogMessage("Received null value for CryptoolStream.", NotificationLevel.Warning);
                }
                else
                {
                    GuiLogMessage("No input stream.", NotificationLevel.Warning);
                }
            }

            Progress(1.0, 1.0);
        }
コード例 #3
0
        /// <summary>	Calculates the bitshares address from a bitcoin public key. </summary>
        ///
        /// <remarks>	Paul, 08/12/2014. </remarks>
        ///
        /// <param name="compressedBtcPubKey">	The compressed btc pub key. </param>
        /// <param name="ripe">				  	The ripe. </param>
        ///
        /// <returns>	The calculated bitshares address from btc pub key bytes. </returns>
        public static byte[] ComputeBitsharesAddressFromBtcPubKey(byte[] compressedBtcPubKey, RIPEMD160 ripe)
        {
            byte[] sha512 = Crypto.ComputeSha512(compressedBtcPubKey);
            byte[] addr = ripe.ComputeHash(sha512);
            byte[] check = ripe.ComputeHash(addr);

            byte[] addrFinal = new byte[20 + 4];
            addr.CopyTo(addrFinal, 0);

            Buffer.BlockCopy(check, 0, addrFinal, 20, 4);
            return addrFinal;
        }
コード例 #4
0
 public static byte[] RipeMd160(byte[] text)
 {
     lock (ripeMd160Lock)
     {
         if (ripeMd160Alg == null)
         {
             ripeMd160Alg = RIPEMD160.Create();
         }
         ripeMd160Alg.Initialize();
         return ripeMd160Alg.ComputeHash(text);
     }
 }
コード例 #5
0
        public override string StringHashAlgorithm(string value)
        {
            System.Security.Cryptography.RIPEMD160 md5_160Bit = System.Security.Cryptography.RIPEMD160.Create();
            byte[]        bytes = md5_160Bit.ComputeHash(System.Text.ASCIIEncoding.UTF8.GetBytes(value));
            StringBuilder sb    = new StringBuilder();

            foreach (var b in bytes)
            {
                sb.Append(b.ToString("x2"));
            }
            return(sb.ToString());
        }
コード例 #6
0
 /// <summary>Creates an instance of the default implementation of the <see cref="T:System.Security.Cryptography.RIPEMD160" /> hash algorithm.</summary>
 /// <returns>A new instance of the <see cref="T:System.Security.Cryptography.RIPEMD160" /> hash algorithm.</returns>
 /// <exception cref="T:System.Reflection.TargetInvocationException">The algorithm was used with Federal Information Processing Standards (FIPS) mode enabled, but it is not FIPS-compatible.</exception>
 /// <PermissionSet>
 ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
 /// </PermissionSet>
 public new static RIPEMD160 Create()
 {
     return(RIPEMD160.Create("System.Security.Cryptography.RIPEMD160"));
 }
コード例 #7
0
		public void RIPEMD160_e (string testName, RIPEMD160 hash, byte[] input, byte[] result) 
		{
			byte[] copy = new byte [input.Length];
			for (int i=0; i < input.Length - 1; i++)
				hash.TransformBlock (input, i, 1, copy, i);
			hash.TransformFinalBlock (input, input.Length - 1, 1);
			AssertEquals (testName + ".e", result, hash.Hash);
			// required or next operation will still return old hash
			hash.Initialize ();
		}
コード例 #8
0
		public void RIPEMD160_d (string testName, RIPEMD160 hash, byte[] input, byte[] result) 
		{
			hash.TransformFinalBlock (input, 0, input.Length);
			AssertEquals (testName + ".d", result, hash.Hash);
			// required or next operation will still return old hash
			hash.Initialize ();
		}
コード例 #9
0
		public void RIPEMD160_c (string testName, RIPEMD160 hash, byte[] input, byte[] result) 
		{
			MemoryStream ms = new MemoryStream (input);
			byte[] output = hash.ComputeHash (ms); 
			AssertEquals (testName + ".c.1", result, output);
			AssertEquals (testName + ".c.2", result, hash.Hash);
			// required or next operation will still return old hash
			hash.Initialize ();
		}
コード例 #10
0
		public void RIPEMD160_b (string testName, RIPEMD160 hash, byte[] input, byte[] result) 
		{
			byte[] output = hash.ComputeHash (input, 0, input.Length); 
			AssertEquals (testName + ".b.1", result, output);
			AssertEquals (testName + ".b.2", result, hash.Hash);
			// required or next operation will still return old hash
			hash.Initialize ();
		}
コード例 #11
0
 public AddressAndPubKeyTests()
 {
     m_ripe = RIPEMD160.Create();
 }
コード例 #12
0
 /// <summary>	Construct from compressed public key </summary>
 ///
 /// <remarks>	Paul, 08/12/2014. </remarks>
 ///
 /// <param name="compressed">	The compressed. </param>
 public BitsharesPubKey(byte[] compressed)
 {
     m_compressed = compressed;
     m_ripe = RIPEMD160.Create();
 }
コード例 #13
0
 /// <summary>	Calculates the bitshares pubilc key from bitcoin public key. </summary>
 ///
 /// <remarks>	Paul, 08/12/2014. </remarks>
 ///
 /// <param name="compressedBtcPubKey">	The compressed btc pub key. </param>
 /// <param name="ripe">				  	The ripe. </param>
 ///
 /// <returns>	The calculated bitshares pub key from btc pub key bytes. </returns>
 public static byte[] ComputeBitsharesPubKeyFromBtcPubKey(byte[] compressedBtcPubKey, RIPEMD160 ripe)
 {
     byte[] pubkeyCheck = ripe.ComputeHash(compressedBtcPubKey);
     byte[] pubkeyFinal = new byte[37];
     compressedBtcPubKey.CopyTo(pubkeyFinal, 0);
     Buffer.BlockCopy(pubkeyCheck, 0, pubkeyFinal, 37 - 4, 4);
     return pubkeyFinal;
 }
コード例 #14
0
 /// <summary>	Calculates the bitshares public key from bitcoin public key </summary>
 ///
 /// <remarks>	Paul, 08/12/2014. </remarks>
 ///
 /// <param name="compressedBtcPubKey">	The compressed btc pub key. </param>
 /// <param name="ripe">				  	The ripe. </param>
 ///
 /// <returns>	The calculated bitshares pub key. </returns>
 public static string ComputeBitsharesPubKey(byte[] compressedBtcPubKey, RIPEMD160 ripe)
 {
     return kAddressPrefix + Base58.FromByteArray(ComputeBitsharesPubKeyFromBtcPubKey(compressedBtcPubKey, ripe));
 }
コード例 #15
0
 public BitsharesKeyPair(string wifPrivateKey)
 {
     m_btcKeyPair = new KeyPair(wifPrivateKey);
     m_ripe = System.Security.Cryptography.RIPEMD160.Create();
 }
コード例 #16
0
 public override byte[] ByteHashAlgorithm(string value)
 {
     System.Security.Cryptography.RIPEMD160 md5_160Bit = System.Security.Cryptography.RIPEMD160.Create();
     byte[] bytes = md5_160Bit.ComputeHash(System.Text.ASCIIEncoding.UTF8.GetBytes(value));
     return(bytes);
 }