starryrendezv...@gmail.com wrote:
If it helps, here is the code I currently utilize;

        hash: function(str,method) {

           var hash_engine = Components.classes["@mozilla.org/security/hash;
1"].createInstance().QueryInterface
(Components.interfaces.nsICryptoHash);



           var charcodes = [];
           for (var i = 0; i < str.length; i++){
                 charcodes.push(str.charCodeAt(i));
           }
at this point, charcodes is an array of UCS2 (*) code points, [24744,22909]
           hash_engine.update(charcodes, str.length);
https://developer.mozilla.org/en/nsICryptoHash#update
that takes octets, so your values get truncated into [168,125]
           return TOOLS.convert('bin2hex',hash_engine.finish(false));
        },

try, at the very top:
str = unescape(encodeURIComponent("您好"))
(this does a conversion to UTF8, because *URIComponent is defined to be UTF8, but unescape is platform encoding / ASCII / something along those lines)


(*) IIRC; might be UTF16 instead, but that doesn't make a difference here
--
dev-tech-crypto mailing list
dev-tech-crypto@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-tech-crypto

Reply via email to