/// <summary> /// Parses a Base64 formated string to Base64 object. /// </summary> /// <param name="base64"> /// Base64 formated string. /// </param> /// <param name="format"> /// Specify the Base64 encoding format. /// </param> /// <returns> /// A Base64 representation of the Base64 formated string. /// </returns> public static Base64 Parse(string base64, Base64Format format = Base64Format.RFC4648) { if (base64 == null) { throw new System.ArgumentNullException(nameof(base64)); } var byteArray = System.Convert.FromBase64String(base64); return(new Base64(byteArray, base64, format)); }
/// <summary> /// Tryies to parses a Base64 formated string to Base64 object. /// </summary> /// <param name="base64string"> /// Base64 formates string. /// </param> /// <param name="base64"> /// Return Base64 representation of the Base64 formated string. /// </param> /// <param name="format"> /// Specify the Base64 encoding format. /// </param> /// <returns> /// True if Parse of string was successful. /// </returns> public static bool TryParse(string base64string, out Base64 base64, Base64Format format = Base64Format.RFC4648) { try { base64 = Parse(base64string, format); return(true); } catch (System.Exception) { base64 = null; return(false); } }
/// <summary> /// Constructs a Base64 value from a byte array. /// </summary> /// <param name="bytes"> /// Source bytes for the Base32 value. /// </param> /// <param name="format"> /// Specifies the Base64 encoding format. /// </param> public Base64(IList <byte> bytes, Base64Format format = Base64Format.RFC4648) { Bytes = bytes as ImmutableCollection <byte> ?? new ImmutableCollection <byte>(bytes); Value = Convert.ToBase64String(Bytes.ToArray()); Format = format; }
private Base64(IList <byte> bytes, string value, Base64Format format) { Bytes = bytes as ImmutableCollection <byte> ?? new ImmutableCollection <byte>(bytes); Value = value; Format = format; }
private Base64(SerializationInfo info, StreamingContext context) { Bytes = (ImmutableCollection <byte>)info.GetValue("B", typeof(ImmutableCollection <byte>)); Format = (Base64Format)info.GetValue("F", typeof(Base64Format)); Value = Convert.ToBase64String(Bytes.ToArray()); }