IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ASP Discussion :

Fonction de hashage SHA-1 en VBScript


Sujet :

ASP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre expérimenté Avatar de gderenne
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juillet 2007
    Messages
    250
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Juillet 2007
    Messages : 250
    Par défaut Fonction de hashage SHA-1 en VBScript
    Bonjour à tous,

    Je suis à la recherche d'une fonction écrite en VBScript pour le hashage en SHA-1.

    Je sais qu'elle existe, je l'avais trouvé un jour sans réellement chercher, et là, maintenant que je cherche, je ne la trouve plus... Gnargh'.

    Je vous remercie par avance.

  2. #2
    Membre expérimenté Avatar de gderenne
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juillet 2007
    Messages
    250
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Juillet 2007
    Messages : 250
    Par défaut
    Ca y est, j'ai trouvé.

    Pour ne pas avoir crée ce sujet pour rien et pour la communauté, voici le script qui vient de :
    http://p2p.wrox.com/archive/proasp_howto/2002-02/27.asp

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    <%
    function tohex(value)
      value = clng(value)
      tohex = lcase(hex(value))
      do while len(tohex) < 8
        tohex = "0" & tohex
      loop
    end function
     
    function tobin(value)
      dim hexstr
      hexstr = tohex(value)
      tobin = ""
      for i = 1 to len(hexstr)
        select case mid(hexstr, i, 1)
          case "f", "F"
            tobin = tobin & "1111"
          case "e", "E"
            tobin = tobin & "1110"
          case "d", "D"
            tobin = tobin & "1101"
          case "c", "C"
            tobin = tobin & "1100"
          case "b", "B"
            tobin = tobin & "1011"
          case "a", "A"
            tobin = tobin & "1010"
          case "9"
            tobin = tobin & "1001"
          case "8"
            tobin = tobin & "1000"
          case "7"
            tobin = tobin & "0111"
          case "6"
            tobin = tobin & "0110"
          case "5"
            tobin = tobin & "0101"
          case "4"
            tobin = tobin & "0100"
          case "3"
            tobin = tobin & "0011"
          case "2"
            tobin = tobin & "0010"
          case "1"
            tobin = tobin & "0001"
          case else
            tobin = tobin & "0000"
        end select
      next
    end function
     
    function bin2dec(binstr)
      dim flip
      flip = false
      bin2dec = clng(0)
      if left(binstr,1) = "0" then
        for i = 1 to len(binstr)
          if mid(binstr,33-i,1)="1" then
            bin2dec = bin2dec + (2^(i-1))
          end if
        next
      else
        for i = 1 to len(binstr)
          if flip then
            if mid(binstr,33-i,1)="0" then
              bin2dec = bin2dec - (2^(i-1))
            end if
          else
            if mid(binstr,33-i,1)="1" then
              bin2dec = bin2dec - (2^(i-1))
              flip = true
            end if
          end if
        next
      end if
    end function  
     
    function rshift(value,count)
      dim binstr
      if count >= 32 then
        binstr = ""
      elseif count > 0 then
        binstr = left(tobin(value), 32-count)
      else
        binstr = tobin(value)
      end if
      do while len(binstr) < 32
        binstr = "0" + binstr
      loop
      rshift = bin2dec(binstr)  
    end function
     
    function lshift(value,count)
      dim binstr
      if count >= 32 then
        binstr = ""
      elseif count > 0 then
        binstr = right(tobin(value), 32-count)
      else
        binstr = tobin(value)
      end if
      do while len(binstr) < 32
        binstr = binstr + "0"
      loop
      lshift = bin2dec(binstr)
    end function
     
    function rol(value,count)
      rol = lshift(value,count) or rshift(value,32-count)
    end function
     
    function add32(a, b)
      dim bina, binb, total, result, carry
      bina = tobin(a)
      binb = tobin(b)
      result = ""
      carry = "0"
      for i = 1 to 32
        total = 0
        if mid(bina,33-i,1)="1" then total = total + 1
        if mid(binb,33-i,1)="1" then total = total + 1
        if carry="1" then total = total + 1
        select case total
          case 3
            carry = "1"
            result = "1" + result
          case 2
            carry = "1"
            result = "0" + result
          case 1
            carry = "0"
            result = "1" + result
          case else
            carry = "0"
            result = "0" + result
        end select
      next
      add32 = bin2dec(result)    
    end function
     
    function f(b,c,d,t)
      if t < 20 then
        f = (b and c) or ((not b) and d)
      elseif t < 40 then
        f = b xor c xor d
      elseif t < 60 then
        f = (b and c) or (b and d) or (c and d)
      else
        f = b xor c xor d
      end if
    end function
     
    function k(t)
      if t < 20 then
        k = clng(1518500249)
      elseif t < 40 then
        k = clng(1859775393)
      elseif t < 60 then
        k = clng(-1894007588)
      else
        k = clng(-899497514)
      end if
    end function
     
    function pad(message)
      dim l, n
      l = len(message)
      n = (((l+8) \ 64) + 1)*16
      redim m(n-1)
      for i = 0 to n-1
        m(i) = clng(0)
      next
      for i = 0 to l-1
        m(i\4) = m(i\4) or lshift(asc(mid(message,i+1,1)),(24-(i mod 4)*8))
      next
      m(l\4) = m(l\4) or lshift(clng(128),(24-(l mod 4)*8))
      m(n-1) = l*8
      pad = m
    end function
     
    function sha1(message)
      dim h0, h1, h2, h3, h4
      dim a, b, c, d, e, temp
      dim l, n
      dim w(79)
     
      l = len(message)
      n = (((l+8) \ 64) + 1)*16
      m = pad(message)
     
      h0 = clng(1732584193)
      h1 = clng(-271733879)
      h2 = clng(-1732584194)
      h3 = clng(271733878)
      h4 = clng(-1009589776)
     
      for block = 0 to n-1 step 16
        a = h0
        b = h1
        c = h2
        d = h3
        e = h4
        for t = 0 to 79
          if t < 16 then
            w(t) = m(block + t)
          else
            w(t) = rol(w(t-3) xor w(t-8) xor w(t-14) xor w(t-16),1)
          end if
          temp = add32(rol(a,5),add32(f(b,c,d,t),add32(e,add32(w(t),k(t)))))
          e = d
          d = c
          c = rol(b,30)
          b = a
          a = temp
        next
        h0 = add32(h0, a)
        h1 = add32(h1, b)
        h2 = add32(h2, c)
        h3 = add32(h3, d)
        h4 = add32(h4, e)
      next
      sha1 = tohex(h0)+tohex(h1)+tohex(h2)+tohex(h3)+tohex(h4)
    end function
    %>
    Ce code s'utilise de cette facon :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    <%
      dim message, hash
      message = "hello world"
      hash = sha1(message)
    %>
    @bientot

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Fonction de hashage tel que MD5
    Par bebemyouler dans le forum MATLAB
    Réponses: 1
    Dernier message: 04/07/2013, 18h38
  2. Fonction de hashage
    Par hugodu28 dans le forum Général JavaScript
    Réponses: 28
    Dernier message: 20/01/2013, 20h38
  3. Hashage SHA - 256
    Par K-Kaï dans le forum Sécurité
    Réponses: 6
    Dernier message: 26/04/2010, 17h38
  4. Fonction de hachage SHA ou whirlpool
    Par thms92 dans le forum C++
    Réponses: 3
    Dernier message: 01/09/2008, 18h09
  5. [Oracle / Fonction hachage] Fonction de hachage SHA / MD5
    Par shaun_the_sheep dans le forum Oracle
    Réponses: 8
    Dernier message: 26/01/2006, 08h58

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo