vb.net - VB, DES and MD5 -
hello guys trying migrate java code vb, need duplicate des encryption having trouble part.
i admit haven't done encryption since college.
this encrypt key using md5, , send function des encryption, seems got clue of error, key must 8 digit key , sending 16 length key.
dim md5 new md5cryptoserviceprovider() dim datahash() byte = md5.computehash(encoding.utf8.getbytes(challenge + password)) dim sb new stringbuilder dim b byte each b in datahash sb.append(b.tostring("x2").tolower()) next dim md5key string = sb.tostring ''dim md5key string = digestutils.md5hex(challenge + password) dim geoencrypt new geoencriptamiento dim challengeanswer string = geoencrypt.encryptfile(challenge, md5key)
this code encryption
function encryptfile(byval esquema string, byval llave string) string dim des new descryptoserviceprovider() 'establecer la clave secreta para el algoritmo des. 'se necesita una clave de 64 bits y iv para este proveedor des.key = utf8encoding.utf8.getbytes(llave) des.iv = utf8encoding.utf8.getbytes(llave) try dim inputbytearray() byte = encoding.utf8.getbytes(esquema) dim ms new memorystream dim cs new cryptostream(ms, des.createencryptor(des.key, des.iv), cryptostreammode.write) cs.write(inputbytearray, 0, inputbytearray.length) cs.flushfinalblock() return convert.tobase64string(ms.toarray()) catch ex exception return "error" end try end function
the error when try parse md5 des.key
i'd check use of utf8encoding.utf8.getbytes(llave) that's converting incoming 16 byte key format createencryptor isn't expecting.
createencryptor expects see key same size blocksize, which, according docs, 64 bits, or 8 bytes.
you're passing in key of 16 bytes, because of loop each b in datahash sb.append(b.tostring("x2").tolower()) next
also note computehash function returns array of 16 bytes, not 8 bytes "the computehash methods of md5 class return hash array of 16 bytes. note md5 implementations produce 32-character, hexadecimal-formatted hash. interoperate such implementations, format return value of computehash methods hexadecimal value."
looks you'll either need use different hash, or use part of 16 byte hash.
Comments
Post a Comment