SHA1-Verschlüsselung

  • Allgemein

Es gibt 18 Antworten in diesem Thema. Der letzte Beitrag () ist von Triple-Axe.

    SHA1-Verschlüsselung

    Hi Comm,
    möchte nen Login für mein Forum ins Programm einbaun.
    Das mit der Passwort verschlüsselung bekomm ich aber noch ned so ganz hin :(
    in JAVA:

    Quellcode

    1. /*
    2. * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
    3. * in FIPS PUB 180-1
    4. * Version 2.1a Copyright Paul Johnston 2000 - 2002.
    5. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
    6. * Distributed under the BSD License
    7. * See http://pajhome.org.uk/crypt/md5 for details.
    8. */
    9. /*
    10. * Configurable variables. You may need to tweak these to be compatible with
    11. * the server-side, but the defaults work in most cases.
    12. */
    13. var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
    14. var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
    15. var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
    16. /*
    17. * These are the functions you'll usually want to call
    18. * They take string arguments and return either hex or base-64 encoded strings
    19. */
    20. function hex_sha1(s){return binb2hex(core_sha1(str2binb(s),s.length * chrsz));}
    21. function b64_sha1(s){return binb2b64(core_sha1(str2binb(s),s.length * chrsz));}
    22. function str_sha1(s){return binb2str(core_sha1(str2binb(s),s.length * chrsz));}
    23. function hex_hmac_sha1(key, data){ return binb2hex(core_hmac_sha1(key, data));}
    24. function b64_hmac_sha1(key, data){ return binb2b64(core_hmac_sha1(key, data));}
    25. function str_hmac_sha1(key, data){ return binb2str(core_hmac_sha1(key, data));}
    26. /*
    27. * Calculate the SHA-1 of an array of big-endian words, and a bit length
    28. */
    29. function core_sha1(x, len)
    30. {
    31. /* append padding */
    32. x[len >> 5] |= 0x80 << (24 - len % 32);
    33. x[((len + 64 >> 9) << 4) + 15] = len;
    34. var w = Array(80);
    35. var a = 1732584193;
    36. var b = -271733879;
    37. var c = -1732584194;
    38. var d = 271733878;
    39. var e = -1009589776;
    40. for(var i = 0; i < x.length; i += 16)
    41. {
    42. var olda = a;
    43. var oldb = b;
    44. var oldc = c;
    45. var oldd = d;
    46. var olde = e;
    47. for(var j = 0; j < 80; j++)
    48. {
    49. if(j < 16) w[j] = x[i + j];
    50. else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
    51. var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)),
    52. safe_add(safe_add(e, w[j]), sha1_kt(j)));
    53. e = d;
    54. d = c;
    55. c = rol(b, 30);
    56. b = a;
    57. a = t;
    58. }
    59. a = safe_add(a, olda);
    60. b = safe_add(b, oldb);
    61. c = safe_add(c, oldc);
    62. d = safe_add(d, oldd);
    63. e = safe_add(e, olde);
    64. }
    65. return Array(a, b, c, d, e);
    66. }
    67. /*
    68. * Perform the appropriate triplet combination function for the current
    69. * iteration
    70. */
    71. function sha1_ft(t, b, c, d)
    72. {
    73. if(t < 20) return (b & c) | ((~b) & d);
    74. if(t < 40) return b ^ c ^ d;
    75. if(t < 60) return (b & c) | (b & d) | (c & d);
    76. return b ^ c ^ d;
    77. }
    78. /*
    79. * Determine the appropriate additive constant for the current iteration
    80. */
    81. function sha1_kt(t)
    82. {
    83. return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
    84. (t < 60) ? -1894007588 : -899497514;
    85. }
    86. /*
    87. * Calculate the HMAC-SHA1 of a key and some data
    88. */
    89. function core_hmac_sha1(key, data)
    90. {
    91. var bkey = str2binb(key);
    92. if(bkey.length > 16) bkey = core_sha1(bkey, key.length * chrsz);
    93. var ipad = Array(16), opad = Array(16);
    94. for(var i = 0; i < 16; i++)
    95. {
    96. ipad[i] = bkey[i] ^ 0x36363636;
    97. opad[i] = bkey[i] ^ 0x5C5C5C5C;
    98. }
    99. var hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz);
    100. return core_sha1(opad.concat(hash), 512 + 160);
    101. }
    102. /*
    103. * Add integers, wrapping at 2^32. This uses 16-bit operations internally
    104. * to work around bugs in some JS interpreters.
    105. */
    106. function safe_add(x, y)
    107. {
    108. var lsw = (x & 0xFFFF) + (y & 0xFFFF);
    109. var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
    110. return (msw << 16) | (lsw & 0xFFFF);
    111. }
    112. /*
    113. * Bitwise rotate a 32-bit number to the left.
    114. */
    115. function rol(num, cnt)
    116. {
    117. return (num << cnt) | (num >>> (32 - cnt));
    118. }
    119. /*
    120. * Convert an 8-bit or 16-bit string to an array of big-endian words
    121. * In 8-bit function, characters >255 have their hi-byte silently ignored.
    122. */
    123. function str2binb(str)
    124. {
    125. var bin = Array();
    126. var mask = (1 << chrsz) - 1;
    127. for(var i = 0; i < str.length * chrsz; i += chrsz)
    128. bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - i%32);
    129. return bin;
    130. }
    131. /*
    132. * Convert an array of big-endian words to a string
    133. */
    134. function binb2str(bin)
    135. {
    136. var str = "";
    137. var mask = (1 << chrsz) - 1;
    138. for(var i = 0; i < bin.length * 32; i += chrsz)
    139. str += String.fromCharCode((bin[i>>5] >>> (32 - chrsz - i%32)) & mask);
    140. return str;
    141. }
    142. /*
    143. * Convert an array of big-endian words to a hex string.
    144. */
    145. function binb2hex(binarray)
    146. {
    147. var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
    148. var str = "";
    149. for(var i = 0; i < binarray.length * 4; i++)
    150. {
    151. str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
    152. hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8 )) & 0xF);
    153. }
    154. return str;
    155. }
    156. /*
    157. * Convert an array of big-endian words to a base-64 string
    158. */
    159. function binb2b64(binarray)
    160. {
    161. var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    162. var str = "";
    163. for(var i = 0; i < binarray.length * 4; i += 3)
    164. {
    165. var triplet = (((binarray[i >> 2] >> 8 * (3 - i %4)) & 0xFF) << 16)
    166. | (((binarray[i+1 >> 2] >> 8 * (3 - (i+1)%4)) & 0xFF) << 8 )
    167. | ((binarray[i+2 >> 2] >> 8 * (3 - (i+2)%4)) & 0xFF);
    168. for(var j = 0; j < 4; j++)
    169. {
    170. if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
    171. else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
    172. }
    173. }
    174. return str;
    175. }


    Kann mir das vielleicht einer in VB übersetzen oder sagen, wie ich das in VB umsetzen kann?
    Der Verschlüsselungstyp ist SHA1. Wenn ich den von System.Security.Cryptography nehm, funkts ned..
    LG
    Merio
    das ist JavaScript kein Java...
    außerdem funktioniert das aus System.Security.Cryptographie sehr wohl, oder wo liegt das Problem an dem dort zurückgegebenen Wert? Dass es vlt. alles Großgeschrieben ist und in JavaScript klein und deshalb nicht übereinstimmen kann?!
    Ich wollte auch mal ne total überflüssige Signatur:
    ---Leer---

    ThuCommix schrieb:

    Er will Dateien hashen und keine Strings

    ICH WILL STRINGS HASHEN!
    Das mit der Passwort verschlüsselung bekomm ich aber noch ned so ganz hin :(

    Is das so schwer zu verstehen?!

    jvbsl schrieb:

    außerdem funktioniert das aus System.Security.Cryptographie sehr wohl, oder wo liegt das Problem an dem dort zurückgegebenen Wert? Dass es vlt. alles Großgeschrieben ist und in JavaScript klein und deshalb nicht übereinstimmen kann?!

    Das Problem liegt darin, dass ich einen anderen String zurückbekomme als in der Datenbank mit dem Passwort steht.
    LG
    Merio
    Also nochmal eine einfache erklärung..
    Ich habe oben das JavaScript, verwendet von meinem Forum, um Passwörter zu hashen.
    Jetzt will ich ein Programm machen, das einen String hasht und diesen Hash mit dem eingetragenen hash vom Forum zu vergleichen.

    Wenn ich im Forum das Passwort lol verwende und hashen lasse, steht in der DB:
    186cc4ac66888ec06f97a391e71255d998449223

    Wenn ich mit deinem SHA1-Verfahren lol hashen lasse bekomme ich das hier:
    403926033D001B5279DF37CBBE5287B7C7C267FA

    und wenn diese beiden Hashs das gleiche sind, dann bin ich wohl blind.. O_o
    LG
    Merio
    also dann mal so wie man das machen sollte ok ?

    welche forensoftware
    und bitte ein mal die datenbank tabellenstruktur ( KOMPLETT ) in der die daten rein sollen

    also die tabelle wo das pw drin steht das du vergleichen möchtest

    die einträge bitte nicht posten die interesieren keinen

    sowas meine ich in der art
    Bilder
    • 1.png

      80,03 kB, 1.002×712, 102 mal angesehen