public void Decode_GivenInvalidChars_ThrowsInvalidOperationException() { // prefix 0 - base2 // value 99 - invalid chars Assert.Throws <InvalidOperationException>(() => Multibase.Decode("099", out string _)); }
public static Key LoadNBEcKey(String base58) { byte[] b = Multibase.Decode(base58, out MultibaseEncoding encoding); EcKey key = EcKey.FromAsn1(b); return(new Key(key.GetPrivKeyBytes())); }
private ulong StringToInt(string value) { byte[] codedBytes = Multibase.Decode("Z" + value, out MultibaseEncoding _); ulong codedValue = BitConverter.ToUInt64(codedBytes, 0); return(Rearrange(codedValue)); }
public void TestVector_6(string encoding, string encoded) { var expected = "hello world"; var decoded = Multibase.Decode(encoded, out string mbEncoding, false); Assert.Equal(encoding, mbEncoding); Assert.Equal(expected, Encoding.UTF8.GetString(decoded)); }
// 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 static Cid Decode(string v) { if (v.Length < 2) { throw new ArgumentException("cid too short", nameof(v)); } if (v.Length == 46 && v.Substring(0, 2) == "Qm") { return(new Cid(Multihash.Parse(v))); } return(Cast(Multibase.Decode(v))); }
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 }); }
public static PublicKey FromString(string str) { byte[] decoded = Multibase.Decode(str, out string _); return(new PublicKey(LibP2P.Crypto.PublicKey.Unmarshal(decoded))); }
public void Decode_GivenUnknownPrefix_ThrowsUnsupportedException() { Assert.Throws <NotSupportedException>(() => Multibase.Decode("ø", out string _)); }
public void Decode_GivenEmptyInput_ThrowsArgumentNullException(string value) { Assert.Throws <ArgumentNullException>(() => Multibase.Decode(value, out string _)); }
public override void Decode(string value) => Value = Multibase.Decode(value, out MultibaseEncoding _);