예제 #1
0
        public void Compare_GivenNonEqualHashes_ReturnsOneOrMinusOne()
        {
            var mh1 = Multihash.Sum <SHA1>(Encoding.UTF8.GetBytes("hello world"));
            var mh2 = Multihash.Sum <SHA1>(Encoding.UTF8.GetBytes("hello_world!"));

            Assert.That(mh1.Compare(mh2), Is.Not.EqualTo(0));
        }
예제 #2
0
        public static bool ValidatePublicKeyRecord(string key, byte[] value)
        {
            if (key.Length < 5)
            {
                return(false);
            }

            var prefix = key.Substring(0, 4);

            if (prefix != "/pk/")
            {
                return(false);
            }

            Multihash mh;

            if (!Multihash.TryParse(key.Substring(4), out mh))
            {
                return(false);
            }

            var pkh = Multihash.Sum <SHA2_256>(value);

            return(mh.Equals(pkh));
        }
예제 #3
0
        public void Compare_GivenEqualHashes_ReturnsZero()
        {
            var mh1 = Multihash.Sum <SHA1>(Encoding.UTF8.GetBytes("hello world"));
            var mh2 = Multihash.Sum <SHA1>(Encoding.UTF8.GetBytes("hello world"));

            Assert.That(mh1.Compare(mh2), Is.EqualTo(0));
        }
예제 #4
0
        public void Test16BytesVarint()
        {
            var data = Encoding.UTF8.GetBytes("this is some test content");
            var hash = Multihash.Sum <SHA2_256>(data);
            var c    = new Cid((MulticodecCode)(1UL << 63), hash);

            c.ToBytes();
        }
 public static bool ValidateCredentialsOffline(
     string credentials,
     VASPCredentialsHash credentialsHash)
 {
     return(Multihash
            .Sum <KECCAK_256>(Encoding.UTF8.GetBytes(credentials)).Digest
            .SequenceEqual((byte[])credentialsHash));
 }
예제 #6
0
        public void Constructor_GivenData_HasCorrectMultihash()
        {
            var data  = Encoding.UTF8.GetBytes("some other data");
            var block = new BasicBlock(data);
            var hash  = Multihash.Sum(HashType.SHA2_256, data);

            Assert.Equal(hash, block.Multihash);
        }
예제 #7
0
        async void videoSelection()
        {
            if (!CrossMedia.Current.IsPickVideoSupported)
            {
                await DisplayAlert("Photos Not Supported", ":( Permission not granted to photos.", "OK");

                return;
            }
            try
            {
                Stream stream = null;
                var    file   = await CrossMedia.Current.PickVideoAsync().ConfigureAwait(true);

                if (file == null)
                {
                    return;
                }

                stream = file.GetStream();
                //file.Dispose();
                //  imgIcon.Source = ImageSource.FromStream(() => stream);


                //Hash with Multihash

                Multibase multibase = Multibase.Base58;

                bytes = null;
                mh    = null;

                bytes = GetImageStreamAsBytes(stream);

                var multihash = Multihash.Sum <SHA2_256>(bytes);

                string checkData = multibase.Encode(multihash);

                stringHash.Text = checkData;


                //Hash With IPFS

                CancellationToken token = new CancellationToken(false);

                IpfsClient ipfs = new IpfsClient("http://10.0.3.2:5001");

                IFileSystemNode fileSystemNode = await ipfs.FileSystem.AddFileAsync(file.Path, null, token);

                Debug.WriteLine("fileSystemNode Hash:" + fileSystemNode.Id);

                imageHash.Text = fileSystemNode.Id;
            }
            catch (Exception err)
            {
                Debug.WriteLine("Message:" + err.Message);
                Debug.WriteLine("Source:" + err.Source);
                Debug.WriteLine("Stack Trace:" + err.StackTrace);
            }
        }
예제 #8
0
        public void TestMD5()
        {
            var text = "hello world";
            var hash = Hex.Decode("5eb63bbbe01eeed093cb22bb8f5acdc3");

            var mh = Multihash.Sum <MD5>(Encoding.UTF8.GetBytes(text));

            Assert.Equal(hash, mh.Digest);
        }
예제 #9
0
        public void TestMurmur3_32()
        {
            var text = "beep boop";
            var hash = Hex.Decode("243ddb9e");

            var mh = Multihash.Sum <MURMUR3_32>(Encoding.UTF8.GetBytes(text));

            Assert.Equal(mh.Digest, hash);
        }
예제 #10
0
        public void TestMD4()
        {
            var text = "hello world";
            var hash = Hex.Decode("aa010fbc1d14c795d86ef98c95479d17");

            var mh = Multihash.Sum <MD4>(Encoding.UTF8.GetBytes(text));

            Assert.Equal(hash, mh.Digest);
        }
예제 #11
0
        public void TestID()
        {
            var text = "hello world";
            var hash = "1DVBjHhYDaZ47EzaX";

            var mh = Multihash.Sum <ID>(Encoding.UTF8.GetBytes(text));

            Assert.Equal(mh.ToString(MultibaseEncoding.Base58Btc), hash);
        }
예제 #12
0
        public void TestSHA3_384()
        {
            var text = "hello world";
            var hash = Hex.Decode("83bff28dde1b1bf5810071c6643c08e5b05bdb836effd70b403ea8ea0a634dc4997eb1053aa3593f590f9c63630dd90b");

            var mh = Multihash.Sum <SHA3_384>(Encoding.UTF8.GetBytes(text));

            Assert.Equal(mh.Digest, hash);
        }
예제 #13
0
        public void TestSHA2_512()
        {
            var text = "hello world";
            var hash = "8Vtkv2tdQ43bNGdWN9vNx9GVS9wrbXHk4ZW8kmucPmaYJwwedXir52kti9wJhcik4HehyqgLrQ1hBuirviLhxgRBNv";

            var mh = Multihash.Sum <SHA2_512>(Encoding.UTF8.GetBytes(text));

            Assert.Equal(mh.ToString(MultibaseEncoding.Base58Btc), hash);
        }
예제 #14
0
        public void TestKeccak_512()
        {
            var text = "hello world";
            var hash = Hex.Decode("3ee2b40047b8060f68c67242175660f4174d0af5c01d47168ec20ed619b0b7c42181f40aa1046f39e2ef9efc6910782a998e0013d172458957957fac9405b67d");

            var mh = Multihash.Sum <KECCAK_512>(Encoding.UTF8.GetBytes(text));

            Assert.Equal(mh.Digest, hash);
        }
예제 #15
0
        public void TestKeccak_384()
        {
            var text = "hello world";
            var hash = Hex.Decode("65fc99339a2a40e99d3c40d695b22f278853ca0f925cde4254bcae5e22ece47e6441f91b6568425adc9d95b0072eb49f");

            var mh = Multihash.Sum <KECCAK_384>(Encoding.UTF8.GetBytes(text));

            Assert.Equal(mh.Digest, hash);
        }
예제 #16
0
        public void TestKeccak_256()
        {
            var text = "hello world";
            var hash = Hex.Decode("47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad");

            var mh = Multihash.Sum <KECCAK_256>(Encoding.UTF8.GetBytes(text));

            Assert.Equal(mh.Digest, hash);
        }
예제 #17
0
        public void TestKeccak_224()
        {
            var text = "hello world";
            var hash = Hex.Decode("25f3ecfebabe99686282f57f5c9e1f18244cfee2813d33f955aae568");

            var mh = Multihash.Sum <KECCAK_224>(Encoding.UTF8.GetBytes(text));

            Assert.Equal(mh.Digest, hash);
        }
예제 #18
0
        public void TestBlake2S()
        {
            var text = "hello world";
            var hash = "9aec6806794561107e594b1f6a8a6b0c92a0cba9acf5e5e93cca06f781813b0b";

            var mh = Multihash.Sum <BLAKE2S_256>(Encoding.UTF8.GetBytes(text));

            Assert.Equal(BitConverter.ToString(mh.Digest).Replace("-", "").ToLower(), hash);
        }
예제 #19
0
        public void TestBlake2B()
        {
            var text = "hello world";
            var hash = "021ced8799296ceca557832ab941a50b4a11f83478cf141f51f933f653ab9fbcc05a037cddbed06e309bf334942c4e58cdf1a46e237911ccd7fcf9787cbc7fd0";

            var mh = Multihash.Sum <BLAKE2B_512>(Encoding.UTF8.GetBytes(text));

            Assert.Equal(BitConverter.ToString(mh.Digest).Replace("-", "").ToLower(), hash);
        }
예제 #20
0
        public void TestSHA1()
        {
            var text = "hello world";
            var hash = "5drNu81uhrFLRiS4bxWgAkpydaLUPW";

            var mh = Multihash.Sum <SHA1>(Encoding.UTF8.GetBytes(text));

            Assert.Equal(mh.ToString(MultibaseEncoding.Base58Btc), hash);
        }
예제 #21
0
        public void TestSHA2_256()
        {
            var text = "hello world";
            var hash = "QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4";

            var mh = Multihash.Sum <SHA2_256>(Encoding.UTF8.GetBytes(text));

            Assert.Equal(mh.ToString(MultibaseEncoding.Base58Btc), hash);
        }
예제 #22
0
        public void TestShake_128()
        {
            var text = "hello world";
            var hash = Hex.Decode("3a9159f071e4dd1c8c4f968607c30942");

            var mh = Multihash.Sum <SHAKE_128>(Encoding.UTF8.GetBytes(text));

            Assert.Equal(mh.Digest, hash);
        }
예제 #23
0
        public void TestSHA3_512()
        {
            var text = "hello world";
            var hash = "8tWhXW5oUwtPd9d3FnjuLP1NozN3vc45rmsoWEEfrZL1L6gi9dqi1YkZu5iHb2HJ8WbZaaKAyNWWRAa8yaxMkGKJmX";

            var mh = Multihash.Sum <SHA3_512>(Encoding.UTF8.GetBytes(text));

            Assert.Equal(mh.ToString(MultibaseEncoding.Base58Btc), hash);
        }
예제 #24
0
        public void TestShake_256()
        {
            var text = "hello world";
            var hash = Hex.Decode("369771bb2cb9d2b04c1d54cca487e372d9f187f73f7ba3f65b95c8ee7798c527");

            var mh = Multihash.Sum <SHAKE_256>(Encoding.UTF8.GetBytes(text));

            Assert.Equal(mh.Digest, hash);
        }
        private static byte[] SumBytes(params byte[][] data)
        {
            var multihash = Multihash.Sum <KECCAK_256>
                            (
                data: ConcatMany(data)
                            );

            return(multihash.Digest);
        }
예제 #26
0
        public void TestSHA3_256()
        {
            var text = "hello world";
            var hash = Hex.Decode("644bcc7e564373040999aac89e7622f3ca71fba1d972fd94a31c3bfbf24e3938");

            var mh = Multihash.Sum <SHA3_256>(Encoding.UTF8.GetBytes(text));

            Assert.Equal(mh.Digest, hash);
        }
예제 #27
0
        public void Constructor_GivenDataAndCid_HasValidHash()
        {
            var data  = Encoding.UTF8.GetBytes("I can't figure out more names .. data");
            var hash  = Multihash.Sum(HashType.SHA2_256, data);
            var cid   = new Cid(hash);
            var block = new BasicBlock(data, cid);

            Assert.Equal(hash, block.Multihash);
        }
예제 #28
0
        public void TestSHA3_224()
        {
            var text = "hello world";
            var hash = Hex.Decode("dfb7f18c77e928bb56faeb2da27291bd790bc1045cde45f3210bb6c5");

            var mh = Multihash.Sum <SHA3_224>(Encoding.UTF8.GetBytes(text));

            Assert.Equal(mh.Digest, hash);
        }
예제 #29
0
        public void TestDblSha2_256()
        {
            var text = "foo";
            var hash = Hex.Decode("c7ade88fc7a21498a6a5e5c385e1f68bed822b72aa63c4a9a48a02c2466ee29e");

            var mh = Multihash.Sum <DBL_SHA2_256>(Encoding.UTF8.GetBytes(text));

            Assert.Equal(mh.Digest, hash);
        }
예제 #30
0
        public void TestMurmur3_128()
        {
            var text = "beep boop";
            var hash = Hex.Decode("acfe9c5bbf88f075c0c4df0464430ead");

            var mh = Multihash.Sum <MURMUR3_128>(Encoding.UTF8.GetBytes(text));

            Assert.Equal(mh.Digest, hash);
        }