[wm21 - android] how to generate MD5 for multiplatform

Startbeitrag von ccc2 am 01.03.2017 12:25

Hi,

I going to explain how to generate MD5 for multi platform using wm21 - android to match with md5 generate by nodejs.

Please take Note that
1. UNICODE in WM21 is UTF-8 LE.
2. WM21 (android) doesn't support UTF-8 . the function stringtoUTF8() is actually covert unicode to ANSI.

ansi and utf-8 has alot similarity but ansi is not unicode while utf-8 is unicode.

as long as stay away from unicode character (chinese, japanese, etc..) , you won't have any problem.

--------------------------NO UNICODE characters---------------------------------------------
The following method will work as long as no unicode characters in the string . StringToUTF8() is only convert to ansi . wm21 won't throw any error but the md5 won't match.

------ Node JS (UTF-8) ---------------

var m_str = "QWERT";
console.log(crypto.createHash('md5').update(m_str).digest("hex"));

output
f1ce609eb6591ecd3dc405282fef22f9

----- WM21 android (UNICODE)

m_str is string = "QWERT"
info( BufferToHexa(HashString(HA_MD5_128,StringToUTF8(m_str))) )

output
f1 ce 60 9e b6 59 1e cd 3d c4 05 28 2f ef 22 f9



--------------------------contain UNICODE characters---------------------------------------------
in order to be able to use unicode character and since WM21 do not support UTF-8, the only solution is using WM21 (UNICODE) which is UTF-16 LE.

------ Node JS
on NodeJS convert it UTF-8 to UTF-16 LE

var m_str = 'セカイの果て';
var Iconv = require('iconv').Iconv;

var iconv = new Iconv('UTF-8', 'UTF-16LE');
var Buff = iconv.convert(m_str);

console.log(crypto.createHash('md5').update(Buff).digest("hex"));

output
17cbe635a4b2d08caf1b8c42257d04e7


----- WM21 android (UNICODE)
since WM unicode is UTF-16 LE , no need to do any conversion

M_str is string = "セカイの果て"

Info(BufferToHexa(HashString(HA_MD5_128,M_str )) )

output
17 cb e6 35 a4 b2 d0 8c af 1b 8c 42 25 7d 04 e7


----------------------- conclusion ------------------------------------------------------
if your app do not use unicode characters then on use StringToUTF8() is safe . else if you need to use unicode characters then do the conversion UTF-16LE to UTF-8 on server side.

Antworten:

Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.