/// <summary> /// Converts the MPKCPrivateKey to an encoded MemoryStream /// </summary> /// /// <returns>The Private Key encoded as a MemoryStream</returns> public MemoryStream ToStream() { BinaryWriter writer = new BinaryWriter(new MemoryStream()); // length writer.Write(m_N); // dimension writer.Write(m_K); // gf writer.Write(m_gField.GetEncoded()); // gp byte[] gp = m_goppaPoly.GetEncoded(); writer.Write(gp.Length); writer.Write(gp); // p1 byte[] p = m_P1.GetEncoded(); writer.Write(p.Length); writer.Write(p); // check matrix byte[] h = m_H.GetEncoded(); writer.Write(h.Length); writer.Write(h); // length of first dimension writer.Write(m_qInv.Length); for (int i = 0; i < m_qInv.Length; i++) { // roots byte[] qi = m_qInv[i].GetEncoded(); writer.Write(qi.Length); writer.Write(qi); } writer.BaseStream.Seek(0, SeekOrigin.Begin); return((MemoryStream)writer.BaseStream); }
/// <summary> /// Converts the key pair to a byte array /// </summary> /// /// <returns>The encoded key pair</returns> public byte[] ToBytes() { BinaryWriter writer = new BinaryWriter(new MemoryStream()); // length writer.Write(N); // dimension writer.Write(K); // gf writer.Write(_gField.GetEncoded()); // gp byte[] gp = _goppaPoly.GetEncoded(); writer.Write(gp.Length); writer.Write(gp); // p1 byte[] p = _P1.GetEncoded(); writer.Write(p.Length); writer.Write(p); // check matrix byte[] h = _H.GetEncoded(); writer.Write(h.Length); writer.Write(h); // length of first dimension writer.Write(_qInv.Length); for (int i = 0; i < _qInv.Length; i++) { // roots byte[] qi = _qInv[i].GetEncoded(); writer.Write(qi.Length); writer.Write(qi); } return(((MemoryStream)writer.BaseStream).ToArray()); }