ComputeContentMd5() public method

Computes the MD5 checksum of the content.
Computes the MD5 checksum of the MIME content in its canonical format and then base64-encodes the result.
/// The is null. ///
public ComputeContentMd5 ( ) : string
return string
Exemplo n.º 1
0
		public void TestMimePartContentObject ()
		{
			byte[] data = Encoding.ASCII.GetBytes ("abcd");

			// Checksum will be wrong if content is encoded in any way.
			string checksum;
			using (var md5 = MD5.Create ())
				checksum = Convert.ToBase64String (md5.ComputeHash (data));

			var msg = new MimePart ("application", "octet-stream",
				new ContentObject (new MemoryStream (data), ContentEncoding.Binary)
			);

			Assert.AreEqual (checksum, msg.ComputeContentMd5 (), "Content MD5 is wrong");
			Assert.AreEqual (ContentEncoding.Binary, msg.ContentObject.Encoding, "ContentEncoding is wrong");
		}
Exemplo n.º 2
0
		public void TestContentMd5 ()
		{
			var part = new MimePart ();

			Assert.IsNull (part.ContentMd5, "Initial ContentMd5 value should be null");

			part.ContentMd5 = "XYZ";
			Assert.AreEqual ("XYZ", part.ContentMd5, "Expected ContentMd5 to be updated");
			Assert.IsTrue (part.Headers.Contains (HeaderId.ContentMd5), "Expected header to exist");

			part.ContentMd5 = null;
			Assert.IsNull (part.ContentMd5, "Expected ContentMd5 to be null again");
			Assert.IsFalse (part.Headers.Contains (HeaderId.ContentMd5), "Expected header to be removed");

			part.Headers.Add (HeaderId.ContentMd5, "XYZ");
			Assert.AreEqual ("XYZ", part.ContentMd5, "Expected ContentMd5 to be set again");

			part.Headers.Remove (HeaderId.ContentMd5);
			Assert.IsNull (part.ContentMd5, "Expected ContentMd5 to be null again");

			part.ContentMd5 = "XYZ";
			part.Headers.Clear ();
			Assert.IsNull (part.ContentMd5, "Expected ContentMd5 to be null again");

			Assert.Throws<InvalidOperationException> (() => part.ComputeContentMd5 ());
			Assert.IsFalse (part.VerifyContentMd5 ());
		}