public static String Sign(MySign mySign, string tempStr) { var sha1CryptoServiceProvider = new SHA1CryptoServiceProvider(); byte[] tempStrSha1Bytes = sha1CryptoServiceProvider.ComputeHash(Encoding.UTF8.GetBytes(tempStr)); byte[] tempStrSha1HexBytes = Helper.HexEncode4Bytes(tempStrSha1Bytes); byte[] uidBytes = Encoding.UTF8.GetBytes(mySign.Uid.ToString()); byte[] timeBytes = Encoding.UTF8.GetBytes(mySign.Time.ToString()); byte[] devUIDBytes = Encoding.UTF8.GetBytes(mySign.DevUID); byte[] mergeBytes = Helper.MergeBytes(new byte[][] { tempStrSha1HexBytes, uidBytes, CONSTANT_BYTES, timeBytes, devUIDBytes }); byte[] resultSha1Bytes = sha1CryptoServiceProvider.ComputeHash(mergeBytes); return(Helper.HexEncode(resultSha1Bytes)); }
static void Main(string[] args) { //var rightValue = "O|FC5E038D38A57032085441E7FE7010B0"; //var testValue = SignTool.getDevUID("helloworld"); //Console.WriteLine(rightValue == testValue); //Console.WriteLine(testValue); MySign mySign = new MySign(); mySign.Uid = 1L; mySign.DevUID = SignTool.getDevUID("helloworld"); mySign.Time = 1L; var outSign = SignTool.Sign(mySign, "hello"); Console.WriteLine(outSign); Console.ReadKey(); }