将 VB6 随机化转换为 C#
我正在为旧数据库编写一个 C# 前端,该数据库使用 VB6 Rnd() 和 Randomize() 方法进行用户密码加密。 加密函数非常简单,实际上并不那么安全,但这就是所有当前密码都存储在其中。
我希望能够从 C# 应用程序对旧用户进行身份验证。我可以为 VB6 编写新的加密(或最好是散列)代码,以便所有未来的用户都拥有更安全的密码,并且可以在 C# 中复制。但我不想要求当前用户在使用新前端之前重置密码。
有什么方法可以在 C# 中重新实现该算法,以便它产生与旧版 VB6 代码相同的结果吗?
I'm writing a C# frontend to a legacy database that uses VB6 Rnd() and Randomize() methods for user password encryption. The encryption function is very simplistic and really not all that secure, but it's what all current passwords are stored with.
What I'd like to be able to do is authenticate legacy users from a C# application. I can write new encryption (or preferably hashing) code for VB6 so that all future users have a more secure password, and that can be duplicated in C#. But I don't want to require current users to have had their password reset before they can use the new frontend.
Is there any way I can reimplement that algorithm in C# so that it produces identical results to the legacy VB6 code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这应该是可能的。棘手的部分是模拟对 Visual Basic 的
Randomize
语句和Rnd
函数的调用。我刚刚找到一篇知识库文章,看起来可能包含您需要的信息:
编辑...< /strong>
经过一番调查,最新版本的 Visual Basic 中的
Randomize
和Rnd
实现似乎使用与 VB6 完全相同的算法。因此,好消息是您不需要自己弄清楚并重新实现 VB6 算法。只需导入
Microsoft.VisualBasic
命名空间,您就可以从 C# 调用内置方法:(如果您仍然对所使用的实际算法感到好奇,您可以随时在 Reflector 中查看!)
It should be possible. The tricky part will be emulating the calls to Visual Basic's
Randomize
statement andRnd
function.I just found a knowledge base article that looks like it might have the information that you'll need:
EDIT...
After some investigation, it appears that the
Randomize
andRnd
implementations in recent versions of Visual Basic use exactly the same algorithms as VB6.So, the good news is that you don't need to figure out and re-implement the VB6 algorithms yourself. Just import the
Microsoft.VisualBasic
namespace and you can call the built-in methods from C#:(And if you're still curious about the actual algorithms used, you can always take a look in Reflector!)
您可以从 VB6 和 C# 生成相同的序列。只需注意我们的舍入误差(C# 的结果更精确)。确保在将新种子传递给
VBMath.Randomize()
之前调用VBMath.Rnd(-1)
。You can generate the same sequence from VB6 and C#. Just watch our for rounding errors (the results from C# are more precise). Make sure to call
VBMath.Rnd(-1)
before passing in a new seed toVBMath.Randomize()
.示例 VB 代码:(
大致)相当于 C# 代码:
Random
类构造函数使用当前时间初始化随机数生成器,这就是 Randomize 的作用。您还可以将种子传递给构造函数,这相当于使用种子参数调用 RandomizeSample VB code :
(roughly) equivalent C# code :
The
Random
class constructor initializes the random number generator with the current time, which is what Randomize does. You can also pass a seed to the constructor, which is equivalent to calling Randomize with a seed parameter