public void ToStream(Stream stream) { if (stream == null) { throw new ArgumentNullException("stream"); } using (var binaryWriter = new BinaryWriter(stream)) { binaryWriter.Write(RegistrationReservedByte); var publicKey = UserPublicKey.ToByteArray(); binaryWriter.Write(publicKey); var keyHandle = KeyHandle.ToByteArray(); binaryWriter.Write((byte)keyHandle.Length); binaryWriter.Write(keyHandle); var certBytes = AttestationCertificate.Certificate.GetEncoded(); binaryWriter.Write(certBytes); binaryWriter.Write(Signature.ToByteArray()); } }