/// Encodes the specified string. /// @param text The string to encode. /// @returns The encoded string. public string Encode(string text) { var buffer = Encoding.Default.GetBytes(text); var hash = MD2.Create().ComputeHash(buffer); return(HexCodec.GetString(hash)); }
public override void Create() { // try creating ourselve using Create HashAlgorithm h = MD2.Create("MD2Managed"); Assert.IsTrue((h is MD2Managed), "MD2Managed"); }
public virtual void Create() { // create the default implementation HashAlgorithm h = MD2.Create(); Assert.IsTrue((h is MD2Managed), "MD2Managed"); // Note: will fail is default is changed in machine.config }
public void RFC1319_d(string testName, MD2 hash, byte[] input, byte[] result) { byte[] output = hash.TransformFinalBlock(input, 0, input.Length); AssertEquals(testName + ".d.1", input, output); AssertEquals(testName + ".d.2", result, hash.Hash); // required or next operation will still return old hash hash.Initialize(); }
public void RFC1319_b(string testName, MD2 hash, byte[] input, byte[] result) { byte[] output = hash.ComputeHash(input, 0, input.Length); AssertEquals(testName + ".b.1", result, output); AssertEquals(testName + ".b.2", result, hash.Hash); // required or next operation will still return old hash hash.Initialize(); }
public void RFC1319_c(string testName, MD2 hash, byte[] input, byte[] result) { MemoryStream ms = new MemoryStream(input); byte[] output = hash.ComputeHash(ms); AssertEquals(testName + ".c.1", result, output); AssertEquals(testName + ".c.2", result, hash.Hash); // required or next operation will still return old hash hash.Initialize(); }
public void RFC1319_e(string testName, MD2 hash, byte[] input, byte[] result) { byte[] copy = new byte [input.Length]; for (int i = 0; i < input.Length - 1; i++) { hash.TransformBlock(input, i, 1, copy, i); } byte[] output = hash.TransformFinalBlock(input, input.Length - 1, 1); AssertEquals(testName + ".e.1", input [input.Length - 1], output [0]); AssertEquals(testName + ".e.2", result, hash.Hash); // required or next operation will still return old hash hash.Initialize(); }
public static string GetMD5SecondForFile(string file, string relative, string time) { string md5 = ResCommon.GetFileMD5(file); string fileName = file.Replace("\\", "/"); fileName = fileName.Replace(relative + "/", ""); MD2 md2 = new MD2(); md2.fileName = fileName; md2.hashCode = md5; md2.time = time.ToString(); return(JsonMapper.ToJson(md2)); }
public static void GenMD5Second() { string mdSecondFile = resFolder + "/MD2.dat"; string fresfolder = resFolder.Replace("\\", "/"); string jsonStr = ""; if (File.Exists(mdSecondFile)) { string data = FileUtilTool.ReadFile(mdSecondFile); MD2 md2 = JsonMapper.ToObject <MD2>(data); jsonStr = GetMD5SecondForFile(mdFile, fresfolder, md2.time); } else { jsonStr = GetMD5SecondForFile(mdFile, fresfolder); } FileUtilTool.DelFile(mdSecondFile); FileUtilTool.WriteFile(mdSecondFile, jsonStr); }
public static string Md2Crypto(string source) { using (MD2 myMD2 = MD2.Create()) { try { byte[] input = Encoding.UTF8.GetBytes(source); byte[] output = myMD2.ComputeHash(input); string hashstr = GetHexStrByteArray(output); return(hashstr); } catch (Exception e) { Console.WriteLine(e); throw; } } }
static internal HashAlgorithm CreateFromName(string name) { #if FULL_AOT_RUNTIME switch (name) { case "MD2": return(MD2.Create()); case "MD4": return(MD4.Create()); case "MD5": return(MD5.Create()); case "SHA1": return(SHA1.Create()); case "SHA256": return(SHA256.Create()); case "SHA384": return(SHA384.Create()); case "SHA512": return(SHA512.Create()); case "RIPEMD160": return(RIPEMD160.Create()); default: try { return((HashAlgorithm)Activator.CreateInstance(Type.GetType(name))); } catch { throw new CryptographicException("Unsupported hash algorithm: " + name); } } #else return(HashAlgorithm.Create(name)); #endif }
public override void updateLocalElements(object sender, EventArgs e) { // SET FLASH VFlash = dataStorage.getData("AGC_VFLSH") == "SET" ? true : false; NFlash = dataStorage.getData("AGC_NFLSH") == "SET" ? true : false; // PROGRAM MD1 = dataStorage.getData("AGC_MD1"); MD2 = dataStorage.getData("AGC_MD2"); screenSegDisps[5].setValue(MD1.ToString() + MD2.ToString()); // VERB VD1 = dataStorage.getData("AGC_VD1"); VD2 = dataStorage.getData("AGC_VD2"); if (VFlash) { if (VFC < 1) { screenSegDisps[3].setValue(VD1.ToString() + VD2.ToString()); VFC++; } else if (VFC < 2) { screenSegDisps[3].setValue(""); VFC = 0; } } else { screenSegDisps[3].setValue(VD1.ToString() + VD2.ToString()); } // NOUN ND1 = dataStorage.getData("AGC_ND1"); ND2 = dataStorage.getData("AGC_ND2"); if (NFlash) { if (NFC < 1) { screenSegDisps[4].setValue(ND1.ToString() + ND2.ToString()); NFC++; } else if (NFC < 2) { screenSegDisps[4].setValue(""); NFC = 0; } } else { screenSegDisps[4].setValue(ND1.ToString() + ND2.ToString()); } // R1 R1D1 = dataStorage.getData("AGC_R1D1"); R1D2 = dataStorage.getData("AGC_R1D2"); R1D3 = dataStorage.getData("AGC_R1D3"); R1D4 = dataStorage.getData("AGC_R1D4"); R1D5 = dataStorage.getData("AGC_R1D5"); string sign = dataStorage.getData("AGC_R1S"); SegDisp.SignState signState = SegDisp.SignState.AUTO; if (sign == "NEG") { signState = SegDisp.SignState.MINUS; } int.TryParse(dataStorage.getData("AGC_R1P"), out int p); screenSegDisps[0].setValue(R1D1.ToString() + R1D2.ToString() + R1D3.ToString() + R1D4.ToString() + R1D5.ToString(), p, signState); // R2 R2D1 = dataStorage.getData("AGC_R2D1"); R2D2 = dataStorage.getData("AGC_R2D2"); R2D3 = dataStorage.getData("AGC_R2D3"); R2D4 = dataStorage.getData("AGC_R2D4"); R2D5 = dataStorage.getData("AGC_R2D5"); sign = dataStorage.getData("AGC_R2S"); signState = SegDisp.SignState.AUTO; if (sign == "NEG") { signState = SegDisp.SignState.MINUS; } int.TryParse(dataStorage.getData("AGC_R2P"), out p); screenSegDisps[1].setValue(R2D1.ToString() + R2D2.ToString() + R2D3.ToString() + R2D4.ToString() + R2D5.ToString(), p, signState); // R3 R3D1 = dataStorage.getData("AGC_R3D1"); R3D2 = dataStorage.getData("AGC_R3D2"); R3D3 = dataStorage.getData("AGC_R3D3"); R3D4 = dataStorage.getData("AGC_R3D4"); R3D5 = dataStorage.getData("AGC_R3D5"); sign = dataStorage.getData("AGC_R3S"); signState = SegDisp.SignState.AUTO; if (sign == "NEG") { signState = SegDisp.SignState.MINUS; } int.TryParse(dataStorage.getData("AGC_R3P"), out p); screenSegDisps[2].setValue(R3D1.ToString() + R3D2.ToString() + R3D3.ToString() + R3D4.ToString() + R3D5.ToString(), p, signState); // INDICATORS screenIndicators[53].setStatus(dataStorage.getData("AGC_KEYREL") == "SET" ? Indicator.status.WHITE : Indicator.status.OFF); screenIndicators[54].setStatus(dataStorage.getData("AGC_OPRERR") == "SET" ? Indicator.status.WHITE : Indicator.status.OFF); }