/// <summary>
        ///     Register the standard multi-base algorithms for IPFS.
        /// </summary>
        /// <seealso href="https://github.com/multiformats/multibase/blob/master/multibase.csv" />
        static MultiBaseAlgorithm()
        {
            Register("base58btc", 'z',
                     bytes => SimpleBase.Base58.Bitcoin.Encode(bytes),
                     s => SimpleBase.Base58.Bitcoin.Decode(s));
            Register("base58flickr", 'Z',
                     bytes => SimpleBase.Base58.Flickr.Encode(bytes),
                     s => SimpleBase.Base58.Flickr.Decode(s));
            Register("base64", 'm',
                     bytes => bytes.ToBase64NoPad(),
                     s => s.FromBase64NoPad());
            Register("base64pad", 'M',
                     bytes => Convert.ToBase64String(bytes),
                     s => Convert.FromBase64String(s));
            Register("base64url", 'u',
                     bytes => bytes.ToBase64Url(),
                     s => s.FromBase64Url());
            Register("base16", 'f',
                     bytes => Base16.EncodeLower(bytes),
                     s => Base16.Decode(s));
            Register("base32", 'b',
                     bytes => SimpleBase.Base32.Rfc4648.Encode(bytes, false).ToLowerInvariant(),
                     s => SimpleBase.Base32.Rfc4648.Decode(s));
            Register("base32pad", 'c',
                     bytes => SimpleBase.Base32.Rfc4648.Encode(bytes, true).ToLowerInvariant(),
                     s => SimpleBase.Base32.Rfc4648.Decode(s));
            Register("base32hex", 'v',
                     bytes => SimpleBase.Base32.ExtendedHex.Encode(bytes, false).ToLowerInvariant(),
                     s => SimpleBase.Base32.ExtendedHex.Decode(s));
            Register("base32hexpad", 't',
                     bytes => SimpleBase.Base32.ExtendedHex.Encode(bytes, true).ToLowerInvariant(),
                     s => SimpleBase.Base32.ExtendedHex.Decode(s));
            Register("BASE16", 'F',
                     bytes => Base16.EncodeUpper(bytes),
                     s => Base16.Decode(s));
            Register("BASE32", 'B',
                     bytes => SimpleBase.Base32.Rfc4648.Encode(bytes, false),
                     s => SimpleBase.Base32.Rfc4648.Decode(s));
            Register("BASE32PAD", 'C',
                     bytes => SimpleBase.Base32.Rfc4648.Encode(bytes, true),
                     s => SimpleBase.Base32.Rfc4648.Decode(s));
            Register("BASE32HEX", 'V',
                     bytes => SimpleBase.Base32.ExtendedHex.Encode(bytes, false),
                     s => SimpleBase.Base32.ExtendedHex.Decode(s));
            Register("BASE32HEXPAD", 'T',
                     bytes => SimpleBase.Base32.ExtendedHex.Encode(bytes, true),
                     s => SimpleBase.Base32.ExtendedHex.Decode(s));
            Register("base32z", 'h',
                     bytes => Base32z.Codec.Encode(bytes, false),
                     s => Base32z.Codec.Decode(s));

            // Not supported
#if false
            Register("base1", '1');
            Register("base2", '0');
            Register("base8", '7');
            Register("base10", '9');
#endif
        }
Exemplo n.º 2
0
        public void EncodeUpper_Stream(byte[] input, string expectedOutput)
        {
            using var inputStream = new MemoryStream(input);
            using var writer      = new StringWriter();
#pragma warning disable CS0618 // Type or member is obsolete
            Base16.EncodeUpper(inputStream, writer);
#pragma warning restore CS0618 // Type or member is obsolete
            Assert.AreEqual(expectedOutput, writer.ToString());
        }
Exemplo n.º 3
0
        public void EncodeUpper(byte[] input, string expectedOutput)
        {
            var result = Base16.EncodeUpper(input);

            Assert.AreEqual(expectedOutput, result);
        }
Exemplo n.º 4
0
        public void EncodeUpper_Works()
        {
#pragma warning disable CS0618 // Type or member is obsolete
            Assert.AreEqual("ABCD", Base16.EncodeUpper(new byte[] { 0xAB, 0xCD }));
#pragma warning restore CS0618 // Type or member is obsolete
        }
 /// <summary>
 /// Convert string to Base16.
 /// Encoding UTF-8.
 /// </summary>
 /// <param name="str">string to convert.</param>
 /// <returns>Base16 string.</returns>
 public static string EncodeBase16(this string str)
 {
     return(Base16.EncodeUpper(str.GetBytes()));
 }