如下:
/// <summary> /// 生成 Json /// </summary> /// <param name="obj"></param> /// <returns></returns> public string ObjToJson(Object obj) { StringWriter sw; JsonSerializer serializer = new JsonSerializer(); sw = new StringWriter(); serializer.Serialize(new JsonTextWriter(sw), obj); return sw.GetStringBuilder().ToString(); }
这里只做 SHA1 加密:
/// <summary> /// 基于Sha1的自定义加密字符串方法:输入一个字符串,返回一个由40个字符组成的十六进制的哈希散列(字符串)。(x2:字母小写,X2字母大写) /// </summary> /// <param name="str">要加密的字符串</param> /// <returns>加密后的十六进制的哈希散列(字符串)</returns> public string Sha1(string str) { var buffer = Encoding.UTF8.GetBytes(str); var data = SHA1.Create().ComputeHash(buffer); var sb = new StringBuilder(); foreach (var t in data) { sb.Append(t.ToString("x2")); } return sb.ToString(); }