private static string GetNPP10Sign(JDPayDictionary dictionary, string algorithm, string salt) { if (dictionary == null || dictionary.Count == 0) { return(string.Empty); } var sb = new StringBuilder(); foreach (var iter in dictionary) { if (!string.IsNullOrEmpty(iter.Value) && iter.Key != "sign_type" && iter.Key != "sign_data" && iter.Key != "encrypt_type" && iter.Key != "encrypt_data" && iter.Key != "salt") { sb.Append(iter.Key).Append("=").Append(iter.Value).Append("&"); } } var sign = string.Empty; var data = sb.Remove(sb.Length - 1, 1) + salt; if ("SHA" == algorithm) { sign = SHA1.Compute(data).ToUpper(); } else if ("SHA-256" == algorithm) { sign = SHA256.Compute(data).ToUpper(); } return(sign); }
public static string RSASign(string sourceSignString, ICipherParameters privateKey) { var sha256SourceSignString = SHA256.Compute(sourceSignString); var newsks = RSA_ECB_PKCS1Padding.Encrypt(Encoding.UTF8.GetBytes(sha256SourceSignString), privateKey); return(Convert.ToBase64String(newsks, Base64FormattingOptions.InsertLineBreaks)); }
public static bool RSACheckContent(string content, string sign, ICipherParameters publicKey) { var sha256SourceSignString = SHA256.Compute(content); var decryptArr = RSA_ECB_PKCS1Padding.Decrypt(Convert.FromBase64String(sign), publicKey); var decrypStr = Encoding.UTF8.GetString(decryptArr); return(sha256SourceSignString.Equals(decrypStr)); }
private static string GetNPP10Sign(string content, string algorithm, string salt) { var sign = string.Empty; var data = content + salt; if ("SHA" == algorithm) { sign = SHA1.Compute(data); } else if ("SHA-256" == algorithm) { sign = SHA256.Compute(data); } return(sign); }