public static void SaveEcKey(Key nbEcKey, IResourceDataAccess resourceDataAccess) { byte[] bytes = EcKey.ToAsn1(nbEcKey.ToBytes(), nbEcKey.PubKey.ToBytes()); string base58 = Multibase.Encode(MultibaseEncoding.Base58Btc, bytes); resourceDataAccess.Save(base58); }
private string IntToString(ulong value) { var codedValue = Rearrange(value); byte[] codedBytes = BitConverter.GetBytes(codedValue); return(Multibase.Encode(MultibaseEncoding.Base58Flickr, codedBytes).Substring(1)); }
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); } }
// Official test vectors private static void TestVector(string encoding, string encoded, string expected) { var decoded = Multibase.Decode(encoded, out string mbEncoding); Assert.Equal(encoding, mbEncoding); Assert.Equal(expected, Encoding.UTF8.GetString(decoded)); var rencoded = Multibase.Encode(mbEncoding, decoded); Assert.Equal(encoded, rencoded); }
public void TestRoundTripRaw(MultibaseEncoding encoding) { var rand = new Random(Environment.TickCount); var buf = new byte[rand.Next(16, 256)]; rand.NextBytes(buf); var encoded = Multibase.Encode(encoding, buf); var decoded = Multibase.Decode(encoded, out MultibaseEncoding decodedEncoding); Assert.Equal(encoding, decodedEncoding); Assert.Equal(decoded, buf); }
public string Sign(string input) { var privateKeyParameters = new ECPrivateKeyParameters(_priv, _ecParams); ISigner signer = SignerUtilities.GetSigner("SHA-256withECDSA"); signer.Init(true, privateKeyParameters); var bytes = Encoding.UTF8.GetBytes(input); signer.BlockUpdate(bytes, 0, bytes.Length); var signature = signer.GenerateSignature(); return(Multibase.Encode(MultibaseEncoding.Base58Btc, signature)); }
public override string ToString() { switch (_version) { case 0: return(Hash.ToString(Multibase.Base58)); case 1: return(Multibase.Encode(Multibase.Base58, ToBytes())); default: throw new Exception("unsupported version"); } }
async void local() { try { string imagePath = "NethereumWithTraditionalMVVM.Images.download.jpeg"; Assembly assembly = typeof(MainPage).GetTypeInfo().Assembly; string result; using (Stream stream = assembly.GetManifestResourceStream(imagePath)) { long length = stream.Length; byte[] buffer = new byte[length]; stream.Read(buffer, 0, (int)length); bytes = GetImageStreamAsBytes(stream); CancellationToken token = new CancellationToken(false); IpfsClient ipfs = new IpfsClient("http://10.0.3.2:5001"); IFileSystemNode fileSystemNode = await ipfs.FileSystem.AddFileAsync(imagePath, null, token); Debug.WriteLine("fileSystemNode Hash:" + fileSystemNode.Id); bytes = null; bytes = GetImageStreamAsBytes(fileSystemNode.DataStream); mh = Multihash.Sum <SHA2_256>(bytes); stringHash.Text = fileSystemNode.Id; Debug.WriteLine("bytes after multihash:" + mh); Multibase multibase = Multibase.Base58; string checkData = multibase.Encode(mh); Debug.WriteLine("Multihash after Base58 Encode:" + checkData); imageHash.Text = checkData; } } catch (Exception err) { Debug.WriteLine("Message:" + err.Message); Debug.WriteLine("Source:" + err.Source); Debug.WriteLine("Stack Trace:" + err.StackTrace); } }
public static ApiSig CreateApiSig(string secret, DateTime?date = null) { if (date is null) { date = DateTime.UtcNow.AddMinutes(30); } byte[] sec = Multibase.Decode(secret, out string _); string msg = date.Value.ToString("o", CultureInfo.InvariantCulture); using HMACSHA256 hash = new (sec); byte[] mac = hash.ComputeHash(Encoding.ASCII.GetBytes(msg)); string sig = Multibase.Encode(MultibaseEncoding.Base32Lower, mac); return(new ApiSig() { Msg = msg, Sig = sig }); }
async void Handle_Clicked(object sender, System.EventArgs e) { try { string textValue = txtValue.Text; //Hash with Mutlihash Encoding encoding = Encoding.UTF8; bytes = encoding.GetBytes(textValue); mh = Multihash.Sum <SHA2_256>(bytes); Debug.WriteLine("string bytes after Multihash:" + mh); Multibase multibase = Multibase.Base58; string checkData = multibase.Encode(mh); 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.AddTextAsync(textValue, 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 override string ToString() { return(Multibase.Encode(MultibaseEncoding.Base32Lower, this.Bytes)); }
async void pickPhoto(object sender, System.EventArgs e) { if (!CrossMedia.Current.IsPickPhotoSupported) { await DisplayAlert("Photos Not Supported", ":( Permission not granted to photos.", "OK"); return; } try { Stream stream = null; var file = await CrossMedia.Current.PickPhotoAsync().ConfigureAwait(true); if (file == null) { return; } stream = file.GetStream(); // imgIcon.Source = ImageSource.FromStream(() => stream); //Hash With Multihash Multibase multibase = Multibase.Base58; bytes = null; mh = null; bytes = GetImageStreamAsBytes(stream); string hexString = bytes.ToBase64Url(); if (App.HexString == null) { App.HexString = hexString; } else { if (App.HexString == hexString) { Debug.WriteLine("both hex are equal"); } else { Debug.WriteLine("Both strings are not equal"); } } Debug.WriteLine(bytes.ToHexString()); 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); Debug.WriteLine("fileSystemNode Hash:" + fileSystemNode.Id); imageHash.Text = fileSystemNode.Id; file.Dispose(); } catch (Exception err) { Debug.WriteLine("Message:" + err.Message); Debug.WriteLine("Source:" + err.Source); Debug.WriteLine("Stack Trace:" + err.StackTrace); } }
public void Encode_GivenUnknownEncoding_ThrowsUnsupportedException() { Assert.Throws <NotSupportedException>(() => Multibase.Encode((MultibaseEncoding)0x2000, new byte[] { 0, 1, 2, 3 })); }
public void Encode_GivenNullBytes_ThrowsArgumentNullException() { Assert.Throws <ArgumentNullException>(() => Multibase.Encode(MultibaseEncoding.Base2, null)); }
public void Encode_GivenEmptyBytes_ThrowsArgumentNullException() { Assert.Throws <ArgumentNullException>(() => Multibase.Encode(MultibaseEncoding.Base2, new byte[] {})); }
public override string ToString() => Multibase.Encode(MultibaseEncoding.Base32Lower, (byte[])Value);