protected static Byte[] computeHash(Byte[] message, hashTypes selectedHash) { Byte[] hash = new Byte[0]; switch (selectedHash) { case hashTypes.NONE: break; case hashTypes.MD5: MD5 md5Hash = MD5.Create(); hash = md5Hash.ComputeHash(message); break; case hashTypes.SHA256: SHA256 sha256 = SHA256.Create(); hash = sha256.ComputeHash(message); break; case hashTypes.SHA512: SHA512 sha512 = SHA512.Create(); hash = sha512.ComputeHash(message); break; } return(hash); }
private void sHA512ToolStripMenuItem_Click(object sender, EventArgs e) { selectedHash = hashTypes.SHA512; noneToolStripMenuItem.Checked = false; mD5ToolStripMenuItem.Checked = false; sHA256ToolStripMenuItem.Checked = false; sHA512ToolStripMenuItem.Checked = true; }
new public static Color[] encodeMessage(Color[] pixelArray, Byte[] message, hashTypes selectedHash) { encodeByte(0, (byte)((message.Length >> 8) & 0xFF), pixelArray); encodeByte(1, (byte)((message.Length) & 0xFF), pixelArray); encodeByte(2, 0xAA, pixelArray); //Compute the message hash Byte[] hash = computeHash(message, selectedHash); encodeByteArray(3, hash, pixelArray); encodeByteArray(3 + hash.Length, message, pixelArray); return(pixelArray); }
new public static Byte[] decodeMessage(Color[] pixelArray, hashTypes selectedHash) { //bool padding = oaepPadding.Checked; int messageSize = (((int)decodeByte(0, pixelArray)) << 8) + ((int)decodeByte(1, pixelArray)); Byte[] message = new byte[messageSize]; //int hash = (int)decodeByte(2, pixelArray); int hashSize = 0; //Compute the size of the hash switch (selectedHash) { case hashTypes.MD5: hashSize = 16; break; case hashTypes.SHA256: hashSize = 32; break; case hashTypes.SHA512: hashSize = 64; break; } Byte[] hash = decodeByteArray(3, hashSize, pixelArray); message = decodeByteArray(3 + hashSize, messageSize, pixelArray); if (!compareHashes(hash, computeHash(message, selectedHash))) { MessageBox.Show("Hashes do not match!", "Decoding Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(message); }
private void sha256Hash_CheckedChanged(object sender, EventArgs e) { selectedHash = hashTypes.SHA256; }
private void md5Hash_CheckedChanged(object sender, EventArgs e) { selectedHash = hashTypes.MD5; }
private void noHash_CheckedChanged(object sender, EventArgs e) { selectedHash = hashTypes.NONE; }
public static Byte[] decodeMessage(Color[] pixelArray, hashTypes selectedHash) { return(new byte[0]); }
public static Color[] encodeMessage(Color[] pixelArray, Byte[] message, hashTypes selectedHash) { return(pixelArray); }