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)); }
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)); }
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)); }
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)); }
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); }
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); } }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }