Esempio n. 1
0
		public static void Serialize( Stream stream, XKey key )
		{
			if( stream == null )
			{
				throw new ArgumentNullException( "stream" );
			}

			if( key == null )
			{
				throw new ArgumentNullException( "key" );
			}

			Contract.EndContractBlock();

			using( var writer = new KeyValuePairWriter( stream, true ) )
			{
				foreach( var pair in key )
				{
					writer.Write( pair );
				}

				writer.WriteEpilogue();
			}
		}
Esempio n. 2
0
		public static void Serialize( BinaryWriter binaryWriter, XKey key )
		{
			if( binaryWriter == null )
			{
				throw new ArgumentNullException( "binaryWriter" );
			}

			if( key == null )
			{
				throw new ArgumentNullException( "key" );
			}

			Contract.EndContractBlock();

			using( var writer = new KeyValuePairWriter( binaryWriter ) )
			{
				foreach( var pair in key )
				{
					writer.Write( pair );
				}

				writer.WriteEpilogue();
			}
		}
Esempio n. 3
0
		public static string Serialize( XKey key )
		{
			if( key == null )
			{
				throw new ArgumentNullException( "key" );
			}

			Contract.Ensures( Contract.Result<string>() != null );

			using( var stream = new MemoryStream() )
			{
				using( var writer = new KeyValuePairWriter( stream ) )
				{
					foreach( var pair in key )
					{
						writer.Write( pair );
					}

					writer.WriteEpilogue();
				}

				return Convert.ToBase64String( stream.ToArray() );
			}
		}