Пример #1
0
        //
        // Factory
        //

        public static bool TryFrom(string value, out Base64 base64, Encoding encoding = null)
        {
            try
            {
                var data = Convert.FromBase64String(value);

                base64 = new Base64(value, Binary.From(data));

                return(true);
            }
            catch (FormatException)
            {
                base64 = null;

                return(false);
            }
        }
Пример #2
0
        //
        // Factory
        //

        public static Base64 From(string value, bool strict = true, Encoding encoding = null)
        {
            byte[] data;

            try
            {
                data = Convert.FromBase64String(value);
            }
            catch (FormatException error)
            {
                if (strict)
                {
                    Expect.False(strict, Text
                                 .Of("Failed to parse value: ")
                                 .Write(value)
                                 .WriteTwoLines()
                                 .Write(error));
                }

                return(null);
            }

            return(new Base64(value, Binary.From(data)));
        }
Пример #3
0
 protected override object ConvertFromBytes(ITypeDescriptorContext context, CultureInfo culture, IEnumerable <byte> value)
 {
     return(From(Binary.From(value)));
 }
Пример #4
0
        public static Base64 From(string value, Encoding encoding = null)
        {
            var data = Convert.FromBase64String(value);

            return(new Base64(value, Binary.From(data)));
        }
Пример #5
0
        public static Sha1 Compute(Binary value)
        {
            var hash = new SHA1CryptoServiceProvider().ComputeHash(value.ToBytes());

            return(Sha1.From(Hex.From(Binary.From(hash))));
        }
Пример #6
0
 public static Sha1 Compute(string value, Encoding encoding = null) =>
 Compute(Binary.From(value, encoding));