home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 57131 / 57131.xpi / chrome / beefree.jar / content / beefree / beefree.hash.js < prev    next >
Encoding:
JavaScript  |  2010-01-25  |  3.7 KB  |  83 lines

  1. /*
  2.     2010 - Copyright by Bee <http://www.honeybeenet.altervista.org>.
  3.     This program is free software; you can redistribute it and/or
  4.     modify it under the terms of the GNU General Public License
  5.     as published by the Free Software Foundation; either version 2
  6.     of the License, or (at your option) any later version.
  7.  
  8.     This program is distributed in the hope that it will be useful,
  9.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.     GNU General Public License for more details.
  12.  
  13.     You should have received a copy of the GNU General Public License
  14.     along with this program; if not, write to the Free Software
  15.     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. */
  17.  
  18.  
  19. //TODO: added for future uses ???????????????!!!!!!!!
  20.  
  21. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  22. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  23. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  24. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  25. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  26. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  27. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  28. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  29. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  30. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  31. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  32. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  33. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  34. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  35. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  36. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  37. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  38. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  39. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  40. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  41. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  42. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  43. //THIS FILE IS UNUSED!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ATM!!!!!!!!!)
  44.  
  45. /*
  46. Stolen from https://developer.mozilla.org/en/nsICryptoHash !!!!!!! super!!!!!!!!!!!!
  47. I've no ideas about how this function works, but it works very well!!!!!!!!!!!!
  48. This code is magic:
  49.     [toHexString(hash.charCodeAt(i)) for (i in hash)].join("");
  50. one line, is doing so much!!!!!!!!!!! (from array to hex string, and everything in one hop!!!!)
  51. */
  52.  
  53. function beefree_hash_toHexString(charCode) // return the two-digit hexadecimal code for a byte
  54. {
  55.     return ("0" + charCode.toString(16)).slice(-2);
  56. }
  57.  
  58. function beefree_hash_md5_string(str)
  59. {
  60.     //var str = "hello world";
  61.     var converter =
  62.       Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
  63.     // we use UTF-8 here, you can choose other encodings.
  64.     converter.charset = "UTF-8";
  65.     // result is an out parameter,
  66.     // result.value will contain the array length
  67.     var result = {};
  68.     // data is an array of bytes
  69.     var data = converter.convertToByteArray(str, result);
  70.     var ch = Components.classes["@mozilla.org/security/hash;1"].createInstance(Components.interfaces.nsICryptoHash);
  71.     ch.init(ch.MD5);
  72.     ch.update(data, data.length);
  73.     var hash = ch.finish(false);
  74.     // convert the binary hash data to a hex string.
  75.     var s = [beefree_hash_toHexString(hash.charCodeAt(i)) for (i in hash)].join("");
  76.     // s now contains your hash in hex: should be
  77.     // 5eb63bbbe01eeed093cb22bb8f5acdc3
  78.     return s;
  79. }
  80.  
  81.  
  82.  
  83.