// // 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); } }
// // 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))); }
protected override object ConvertFromBytes(ITypeDescriptorContext context, CultureInfo culture, IEnumerable <byte> value) { return(From(Binary.From(value))); }
public static Base64 From(string value, Encoding encoding = null) { var data = Convert.FromBase64String(value); return(new Base64(value, Binary.From(data))); }
public static Sha1 Compute(Binary value) { var hash = new SHA1CryptoServiceProvider().ComputeHash(value.ToBytes()); return(Sha1.From(Hex.From(Binary.From(hash)))); }
public static Sha1 Compute(string value, Encoding encoding = null) => Compute(Binary.From(value, encoding));