Situation
I am using Bouncy Castle API in my C# project. I need to hash a String using Org.BouncyCastle.Crypto
My Sample
String msg = "Message to Hash";
MD5Digest dig = new MD5Digest();
byte[] msgBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(msg);
dig.BlockUpdate(msgBytes, 0, msgBytes.Length);
byte[] result = new byte[dig.GetDigestSize()];
dig.DoFinal(result, 0);
Console.WriteLine("{0}", Convert.ToBase64String(result));
As as result i got a hash looking like XasdDdflk7ghXi8azuhe==
Questions
- I got always the "==" in the end of any different message. Is it normal ?
- I tried to convert from
byte[]toStringusingSystem.Text.ASCIIEncoding.ASCII.GetString()but I get symbols like "!?..." I want to avoid the "==" in the end. What should I do ? changing Encoder ?
The
==is a result of base 64 padding the result. You can strip them if you so desire.