﻿using System;
using System.Text;
using System.Security.Cryptography;

namespace Gibe.DittoProcessors.Processors
{
	public class StringToMd5HashAttribute : TestableDittoProcessorAttribute
	{
		public override object ProcessValue()
		{
			if (Value == null) throw new NullReferenceException();

			var stringValue = Value as string;

			// byte array representation of that string
			byte[] encodedValue = new UTF8Encoding().GetBytes(stringValue);

			// need MD5 to calculate the hash
			byte[] hashValue = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(encodedValue);

			// string representation (similar to UNIX format)
			return BitConverter.ToString(hashValue).Replace("-", string.Empty).ToLower();
		}
	}
}

﻿using System;
using System.Text;
using System.Security.Cryptography;

namespace Gibe.DittoProcessors.Processors
{
	public class StringToMd5HashAttribute : TestableDittoProcessorAttribute
	{
		public override object ProcessValue()
		{
			if (Value == null) throw new NullReferenceException();

			var stringValue = Value as string;

			byte[] encodedValue = new UTF8Encoding().GetBytes(stringValue);

			byte[] hashValue = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(encodedValue);

			// string representation (similar to UNIX format)
			return BitConverter.ToString(hashValue).Replace("-", string.Empty).ToLower();
		}
	}
}

Update to MD5 hash PR.
Update to MD5 hash PR.
