public static string ToBinaryString(this RSAParameters subject) { subject.Verify(nameof(subject)).IsNotNull(); RsaParameterModel model = subject.ConvertTo(); var formatter = new BinaryFormatter(); using var memory = new MemoryStream(); formatter.Serialize(memory, model); memory.Position = 0; return(Convert.ToBase64String(memory.ToArray())); }