Public Shared Function Sign(VarPost As NameValueCollection) As String '读取私钥 Dim fs As New FileStream(AppDomain.CurrentDomain.BaseDirectory & "\prkeynet.key", FileMode.Open) Dim sr As New StreamReader(fs) Dim KeyStr As String = sr.ReadToEnd.ToString Dim SignStr As String = "" For i As Integer = 0 To VarPost.Count - 1 SignStr += VarPost.Get(i).ToString & "|" Next Dim RSA As New RSACryptoServiceProvider() RSA.FromXmlString(KeyStr) Dim AOutput As Byte() = RSA.SignData(Encoding.UTF8.GetBytes(SignStr.Substring(0, SignStr.Length - 1)), "SHA1") fs.Close() fs.Dispose() Return Convert.ToBase64String(AOutput) End Function
public string Sign(NameValueCollection varPost) { var fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "\prkeynet.key", FileMode.Open); var sr = new StreamReader(fs); var keyStr = sr.ReadToEnd.ToString(); var signStr = ""; for(int i = 0; i <= varPost.Count - 1; i++){ signStr += varPost.Get(i).ToString() + '|'; } var RSA = new RSACryptoServiceProvider(); RSA.FromXmlString(keyStr) byte[] AOutput = RSA.SignData(Encoding.UTF8.GetBytes(signStr.Substring(0, signStr.Length - 1)), "SHA1"); fs.Close(); fs.Dispose(); return Convert.ToBase64String(AOutput); }
大概看看吧。
vb.net 转ASP.NET什么鬼啊?
ASP.NET本身就包括了VB.NET语言的实现在内的,一个是架构一个是语言,转啥转啊。
http://converter.telerik.com/
类似的VB C#互相转换的工具有很多,善用搜索。