private async Task <byte[]> CreateSignAndEncodeDataAsync(BaseModel model) { model.Sender = _publicIdentity; var signedData = new SignedData { Data = Config.DefaultEncoding.GetBytes(await JsonUtils.SerializeAsync(model)) }; var signature = SignUtils.Sign(Config.DefaultEncoding.GetBytes(Convert.ToBase64String(signedData.Data)), _personalIdentity.KeyPair.Private); signedData.Signature = signature; var json = await JsonUtils.SerializeAsync(signedData); var bytes = Config.DefaultEncoding.GetBytes(json); return(bytes); }
/** * 对支付参数信息进行签名 * * @param map * 待签名授权信息 * * @return */ public static string GetSign(Dictionary <string, string> map, string rsaKey, bool rsa2) { List <string> keys = new List <string>(map.Keys); // key排序 Collections.Sort(keys); StringBuilder authInfo = new StringBuilder(); for (int i = 0; i < keys.Count - 1; i++) { string key = keys[i]; string value = map[key]; authInfo.Append(BuildKeyValue(key, value, false)); authInfo.Append("&"); } string tailKey = keys[keys.Count - 1]; string tailValue = map[tailKey]; authInfo.Append(BuildKeyValue(tailKey, tailValue, false)); string auth = authInfo.ToString(); string oriSign = SignUtils.Sign(auth, rsaKey, rsa2); string encodedSign = ""; try { encodedSign = URLEncoder.Encode(oriSign, "UTF-8"); } catch (UnsupportedEncodingException e) { e.PrintStackTrace(); } return("sign=" + encodedSign); }