Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert String to Byte

Status
Not open for further replies.

sbelgium

Programmer
Mar 31, 2005
5
BE
Hey,
I want to make a hashcode for a String.

What is have to do is convert the String to Byte.
I do the following:

------------------------------------------------
Dim ae As New ASCIIEncoding

Dim bericht As String = "test"
hash = sha1.ComputeHash(ae.GetBytes(bericht))
-------------------------------------------------

I get the following error:
Value of type '1-dimensional array of Byte' cannot be converted to 'Byte'.


Can anyone help me?
 
When you declared your hash variable, did you create it as a byte array?

Dim hash() as byte
 
Addition: The following worked for me

Dim ae As New System.Text.ASCIIEncoding
Dim hash() As Byte
Dim bericht As String = "test"
hash = System.Security.Cryptography.SHA1.Create.ComputeHash(ae.GetBytes(bericht))
 
Note that the ASCIIEncoding class will fold every character value down to the ASCII range of 0..127

If you have high-bit ASCII (ANSI), or Unicode data, you'll want to use the UnicodeEncoding class.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top