如何在c#中将整数转换为ASCII charectors? [英] How to convert integer to ASCII charectors in c#?

查看:162
本文介绍了如何在c#中将整数转换为ASCII charectors?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用vb函数将字符串编码为asscii字符以用于某些安全目的。

此字符串信息存储到数据库。

现在我正在获取来自ac#mvc应用程序的相同(密码)数据。

但是当我使用c#代码转换相同的字符串时,它返回一个不同的ascii字符串。

它是一个用户登录过程。我在vb和c#应用程序中使用相同的用户。用户及其密码将从vb应用程序中保存。

vb和c#中的代码,

I am using a vb function to code the string to asscii chars for some security purpose.
And this string info is stored to database.
Now i am fetching the same (password) data from a c# mvc application.
But when i cast the same string using c# code it returns a different string of ascii chars.
Its a user login process.I am using same users in both vb and c# applications.The users and their passwords will be saved from vb application.
The codes in vb and c#,

Public Function DecodeId(ByVal mmId) As String
       Dim DVal As String
       Dim I As Integer
       On Error Resume Next
       If mmId.ToString.Length < 10 Then mmId = mmId.ToString.PadRight(10)
       DVal = ""
       For I = 1 To mmId.ToString.Length
           DVal = DVal & Chr(Asc(Mid(mmId, I, 1)) + 58)
       Next
       DecodeId = DVal
   End Function
c#

    public string DecodeId(string mmId)
             {
               	string DVal = string.Empty ;
               	int I = 0;
                            
               	for (I = 0; I <= mmId.Length-1; I++) {
                    char c = (char)(System.Convert.ToInt32(mmId[I]) + 58);
                    //int x = (System.Convert.ToInt32(mmId[I]) + 58);
                   // char nw = (Char)x;
                   // string s = char.ConvertFromUtf32(x).ToString();
                    DVal = DVal + s.ToString();
               	}
               	return DVal;
           
              }

Please reply if there is any difference in ascii values according o.s or prgmng languages etc (the ascii value for 155 is '>' but from my c# code it gives '""').
Please reply
Thanks

推荐答案

不要这样做:改为使用哈希密码。有关如何在此处执行此操作的信息:密码存储:如何做到这一点。 [ ^ ]和使用SHA或MD5将使它在两种语言中都非常容易使用。
Don't do that: hash your passwords instead. There is some information on how to do it here: Password Storage: How to do it.[^] and usingh SHA or MD5 will make it work very easily in both languages.


这篇关于如何在c#中将整数转换为ASCII charectors?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆