Esempio n. 1
0
        public void Add(BlockChainNode nodetoadd, int db, string domain, byte[] publicKey)
        {
            var password = SHA512.Create().ComputeHash(Guid.NewGuid().ToByteArray());

            WriteLog($"password: {Convert.ToBase64String(password)}");
            var decriptkey = this.cryptoService.EncodeKey(password, publicKey);
            var key64      = Convert.ToBase64String(decriptkey);

            WriteLog($"key64: {key64}");


            WriteLog($"node 64: { nodetoadd.ToBase64()}");
            var dataToEncode = UnicodeEncoding.Unicode.GetBytes(nodetoadd.Data.ToString(Formatting.None));

            WriteLog($"node 64: { dataToEncode.Length}");
            WriteLog($"datatoencode: {Convert.ToBase64String(dataToEncode)}");
            WriteLogByteArray("decript key", password);
            WriteLogByteArray("decript key encoded", decriptkey);
            var encoded = this.cryptoService.EncodeData(dataToEncode, password);

            WriteLogByteArray($"encoded data:", encoded);
            WriteLog($"encoded: {encoded.Length}");
            WriteLog($"encoded 64: {Convert.ToBase64String(encoded)}");
            WriteLogByteArray("data encoded", encoded);
            var data64 = Convert.ToBase64String(encoded); //TODO is neede the double base 64 encoding?

            WriteLog($"data64 encoded: {data64}");
            var fullObj = new JObject();

            fullObj["key"]  = key64;
            fullObj["data"] = data64;
            var fullObj64 = Convert.ToBase64String(UnicodeEncoding.Unicode.GetBytes(fullObj.ToString(Formatting.None)));

            WriteLog($"fullObj64: {fullObj64}");


            var itemUrl   = ComputeRecordUrl(db, nodetoadd.Hash, domain);
            var keyDomain = lookup.QueryAsync(itemUrl, QueryType.TXT).Result;

            //token count
            if (keyDomain == null || keyDomain.Questions.Count == 0)
            {
                client.AddRecord(new DNSEntry()
                {
                    Domain = itemUrl,
                    Value  = fullObj64.Length.ToString()
                });
            }


            WriteDNSFragmentedText(itemUrl, fullObj64, 254);
        }