vb.net - Get hashed Password using same concept in c# , vb give different results -
i have vb code apply hashing string , tried same concept using c# give me different result although when debug code using same value , values of myhash,bytearray,hasharray in c# project same vb project final returned string different here code in vb:
dim hashkey(23) byte public function stringhash(byval strstring string) string if strstring.trim = "" return "" try generatekey() dim myhash hashalgorithm = new mactripledes(hashkey) dim bytearray() byte bytearray = asciistringtobytearray(strstring) dim hasharray() byte hasharray = myhash.computehash(bytearray) hasharray = removequotes(hasharray) return bytearraytoasciistring(hasharray) catch ex exception return "" end try end function public function generatekey() byte() integer = 0 hashkey.length - 1 hashkey(i) = * 3 + 19 next return hashkey end function public function asciistringtobytearray(byval strstring string) byte() dim e encoding = encoding.ascii 'dim result(strstring.length - 1) byte dim result() byte result = e.getbytes(strstring) return result end function public function removequotes(byref bytearray() byte) byte() dim intarraylength integer intarraylength = bytearray.length dim result(intarraylength - 1) byte integer = 0 bytearray.length - 1 if bytearray(i) <> 34 , bytearray(i) <> 39 result(i) = bytearray(i) else result(i) = 32 end if next return result end function public function bytearraytoasciistring(byval bytearray() byte) string return system.text.encoding.ascii.getstring(bytearray) end function
the code in c# :
byte[] hashkey = new byte[24]; public string stringhash(string strstring) { if ((strstring == "")) { return ""; } try { generatekey(); hashalgorithm myhash = new mactripledes(hashkey); byte[] bytearray; bytearray = asciistringtobytearray(strstring); byte[] hasharray; hasharray = myhash.computehash(bytearray); hasharray = removequotes(ref hasharray); return bytearraytoasciistring(hasharray); } catch (exception ex) { return ""; } } public byte[] generatekey() { (int = 0; (i <= (hashkey.length - 1)); i++) { //hashkey[i] = bitconverter.getbytes(i * 3 + 19)[0]; hashkey[i] = (byte)(i * 3 + 19); } return hashkey; } public byte[] asciistringtobytearray(string strstring) { encoding e = encoding.ascii; // dim result(strstring.length - 1) byte byte[] result; result = e.getbytes(strstring); return result; } public byte[] removequotes(ref byte[] bytearray) { int intarraylength; intarraylength = bytearray.length; byte[] result = new byte[intarraylength]; (int = 0; (i <= (bytearray.length - 1)); i++) { if (((bytearray[i] != 34) && (bytearray[i] != 39))) { result[i] = bytearray[i]; } else { result[i] = 32; } } return result; } public string bytearraytoasciistring(byte[] bytearray) { return system.text.encoding.ascii.getstring(bytearray); }
wiki
Comments
Post a Comment