示例#1
0
        /// <summary>	Decrypts./ </summary>
        ///
        ///		auto secret = priv.get_shared_secret(pub);
        ///      auto nonce_plus_secret = fc::sha512::hash(fc::to_string(nonce) + secret.str());
        ///      auto plain_text = fc::aes_decrypt( nonce_plus_secret, message );
        ///      auto result = memo_message::deserialize(string(plain_text.begin(), plain_text.end()));
        ///      FC_ASSERT( result.checksum == uint32_t(digest_type::hash(result.text)._hash[0]) );
        ///      return result.text;
        /// 
        /// <remarks>	Paul, 26/10/2015. </remarks>
        ///
        /// <param name="memo">				 	The memo. </param>
        /// <param name="receiverPrivateKey">	The receiver private key. </param>
        /// <param name="senderPublicKey">   	The sender public key. </param>
        ///
        /// <returns>	A string. </returns>
        public static string Decrypt(GrapheneMemo memo, KeyPair receiverKeyPair)
        {
            PublicKey pub = new BitsharesPubKey(memo.from).GetBitcoinPubKey();
            byte[] sharedSecret = GetSharedSecret(receiverKeyPair, pub);

            string ss = StringExtensions.ByteArrayToHexString(sharedSecret, true);

            string ps = memo.nonce.ToString() + StringExtensions.ByteArrayToHexString(Crypto.ComputeSha512( sharedSecret), true);

            byte[] seed = ASCIIEncoding.ASCII.GetBytes(ps);

            string hex = StringExtensions.ByteArrayToHexString(Crypto.ComputeSha512(seed), true);

            string key = hex.Substring(0, 64);
            string iv = hex.Substring(64, 32);

            byte[] data = Util.HexStringToBytes(memo.message);

            int len = AES.AesDecrypt(data, Util.HexStringToBytes(key), Util.HexStringToBytes(iv));

            byte[] result = new byte[len - 4];
            Buffer.BlockCopy(data, 4, result, 0, result.Length);

            string message = UTF8Encoding.UTF8.GetString(result);

            return message;
        }
示例#2
0
 /// <summary>	Bitshares account to bitcoin address. </summary>
 ///
 /// <remarks>	Paul, 15/01/2015. </remarks>
 ///
 /// <param name="account">	The account. </param>
 ///
 /// <returns>	A string. </returns>
 protected string BitsharesAccountToBitcoinAddress(BitsharesAccount account)
 {
     // turn that into a BTC address
     BitsharesPubKey pubKey = new BitsharesPubKey(account.active_key_history.Last().Values.Last());
     return pubKey.ToBitcoinAddress(true, m_addressByteType);
 }
        public void CheckBitcoinAddressFromBitsharesPublicKey()
        {
            for (int i = 0; i < m_btsPubKeys.Count; i++)
            {
                string btsPubKey = m_btsPubKeys[i];
                string bitcoinAddress = m_bitcoinAddresses[i];

                BitsharesPubKey key = new BitsharesPubKey(btsPubKey);

                Assert.AreEqual(bitcoinAddress, key.ToBitcoinAddress(false, 0));
            }
        }