VB.NET和的sizeof [英] VB.NET and sizeof

查看:416
本文介绍了VB.NET和的sizeof的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我把一些code,从C#到VB.NET。我有在C#以下行

  VAR字节=新字节[password.Length *的sizeof(字符)];
 

看好 的看来,VB.NET似乎并不有的sizeof 运营商。我知道有一个 Marshal.SizeOf ,但进一步的 MSDN文档指出返回值可以不同于对的sizeof

有人能帮忙吗?有没有在VB.NET等效声明,声明?

其他信息

我的目标是将密码转换为字节,然后我就可以散列,然后或者存储在数据库中或比较到previously存储的哈希的数组。但我不一定要涉及到我的特殊情况下的答案。

 暗淡字节(password.Length * XXX)为字节
System.Buffer.BlockCopy(password.ToCharArray(),0,字节,0,bytes.Length)
昏暗的SHA512 = System.Security.Cryptography.SHA512.Create()
暗淡的散列= sha512.ComputeHash(字节)

比较数据库哈希或Stroe的
 

解决方案

在莱恩运营商在VB中会做到这一点(但它适用于情况,所以你需要做相应的调整):

 暗淡字节=新字节((someString.Length·莱恩(新字符)) -  1){}
 

I'm converting some code from C# to VB.NET. I have the following line in C#

var bytes = new byte[password.Length * sizeof(char)];

Looking on MSDN it appears that VB.NET does not seem to have the sizeof operator. I understand there is a Marshal.SizeOf but further MSDN documentation states that the value returned can be different to that of sizeof.

Can anybody help? Is there an equivalent statement in VB.NET?

Additional Information

My aim is to convert a password into an array of bytes which I can then hash and then either store in a database or compare to a previously stored hash. But I don't necessarily want an answer relating to my particular situation.

Dim bytes(password.Length * xxx) As Byte
System.Buffer.BlockCopy(password.ToCharArray(), 0, bytes, 0, bytes.Length)
Dim sha512 = System.Security.Cryptography.SHA512.Create()
Dim hash = sha512.ComputeHash(bytes)

' compare hash or stroe in database

解决方案

The 'Len' operator in VB will do this (but it works on instances, so you need to adjust accordingly):

Dim bytes = New Byte((someString.Length * Len(New Char)) - 1){}

这篇关于VB.NET和的sizeof的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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