[ASP 3.0] Pb de connexion + encodage PassWord

Pb de connexion + encodage PassWord [ASP 3.0] - ASP - Programmation

Marsh Posté le 14-04-2004 à 11:45:58    

bah voila je crois faire faire correctement mais apparemment non!
 
QQ pour m'aider?
 
* Panneau de configuration > Sources de donnees ODBC > Onglet DSN systeme (sources de données système) > Ajouter > Driver Microsoft Access Driver (*.mdb)
* Nom de la source : test
* selection du fichier access
 
 

Code :
  1. <%
  2. ' Création de l'objet permettant la connexion
  3. Dim Conn
  4. Set Conn = Server.CreateObject("ADODB.Connection" )
  5. ' Connexion
  6. Conn.Open "test"
  7. %>


 
 
et lors que je me connecte j'obtient ca!
 
[Microsoft][Pilote ODBC Microsoft Access] Le moteur de la base de données Microsoft Jet ne peut pas ouvrir le fichier '(Inconnu)'. Il est déjà ouvert en mode exclusif par un autre utilisateur, ou vous devez avoir l'autorisation de visualiser ses données.
 
 [:atog]  [:atog]  [:atog]  [:atog]  [:atog]  [:atog]  [:atog]  [:atog]  
 
Je me console comme je peux mais bon.... [:buvons]  
 
 [:dehors]


Message édité par !cricri le 15-04-2004 à 16:07:30
Reply

Marsh Posté le 14-04-2004 à 11:45:58   

Reply

Marsh Posté le 14-04-2004 à 12:26:18    

Vérifie le droits sur le repertoire de la base et reboot le PC  ;)

Reply

Marsh Posté le 14-04-2004 à 15:28:49    

Flyman30 a écrit :

Vérifie le droits sur le repertoire de la base et reboot le PC  ;)  


 
Bah j'ai bien les droits ... et j'ai fais la manip magik windows (ie j'ai rebooté)
 
mais toujours le meme message
Sinon le code est bon ?
 
---
J'en profite pour demander comment on trouve le dernier jour du mois...
un truc genre "Samedi 29 février" ... Il me faudrait un fonction ki me retourne le nombre de jours dans le mois suivant l'annee spécifiée

Reply

Marsh Posté le 14-04-2004 à 23:16:39    

up!

Reply

Marsh Posté le 15-04-2004 à 08:30:37    

J'ai pas trouvé pour les connexions au SGBD...
Mais par contre je crois que ça, ça doit marcher

Code :
  1. Dim jourNum      'le numero (lundi, mardi, etc.)du jour du 1er du mois
  2. Dim jourDansLeMois    'nb jour dans le mois
  3. jourNum   = DatePart("w", DateSerial(year(now()), Month(now()), 1))
  4. jourDansLeMois = DatePart("d", DateSerial(year(now()), Month(now())+1, 1-1))

Reply

Marsh Posté le 15-04-2004 à 13:42:06    

Pour la connexion  
 
en DSN less :
 

Code :
  1. <%
  2. ' Path long de la base de données
  3. dbPath = Server.MapPath("/rep_depro/ma_base.mdb" )
  4. ' Création de l'objet permettant la connexion
  5. Set Conn = Server.CreateObject("ADODB.Connection" )
  6. ' Connexion
  7. Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)};" _
  8.    & " DBQ=" & dbPath
  9. %>


 
avec DSN :  
 
Panneau de configuration > Sources de donnees ODBC > Onglet DSN systeme (sources de données système) > Ajouter > Driver Microsoft Access Driver (*.mdb)  
Sélectionner la base de donnée  
Nom de la source : ma_base  
 

Code :
  1. <%
  2. ' Création de l'objet permettant la connexion
  3. Set Conn = Server.CreateObject("ADODB.Connection" )
  4. ' Connexion
  5. Conn.Open "ma_base"
  6. %>

Reply

Marsh Posté le 15-04-2004 à 16:06:10    

merci Flyman30
 
 
Maintenant je souhaiterai encoder le mot de pass de mes utilisateur pour kil ne soit pas en clair dans le base de données mais je trouve pas la fonction (s'il y en a une)

Reply

Marsh Posté le 16-04-2004 à 11:24:37    

3xc4l18ur a écrit :

merci Flyman30
 
 
Maintenant je souhaiterai encoder le mot de pass de mes utilisateur pour kil ne soit pas en clair dans le base de données mais je trouve pas la fonction (s'il y en a une)


 
un exemple :
 

Code :
  1. <%
  2. 'Cryptage du mot de passe
  3. longeur1=Len(Nom2)
  4. longeur2=Len(Passe2)
  5. J=1
  6. For I=1 To longeur2
  7. char1=Mid(Nom2,J,1)
  8. char2=Mid(Passe2,I,1)
  9. char3=Mid(Passe2,I,1)
  10. code1=Asc(char1)
  11. code2=Asc(char2)
  12. code2=code2+code1
  13. If code2>255 Then
  14.  code2=code2-255
  15. End If
  16. char2=Chr(code2)
  17. Passe2=Replace(Passe2,char3,char2,1,1)
  18. J=J+1
  19. If J>longeur1 Then
  20. J=1
  21. End If
  22. %>


 

Code :
  1. <%
  2. 'Dé-Cryptage du mot de passe
  3. longeur1=Len(Nom2)
  4. longeur2=Len(Passe2)
  5. J=1
  6. For I=1 To longeur2
  7.  char1=Mid(Nom2,J,1)
  8.  char2=Mid(Passe2,I,1)
  9.  char3=Mid(Passe2,I,1)
  10.  code1=Asc(char1)
  11.  code2=Asc(char2)
  12.  code2=code2-code1
  13.  If code2<0 Then
  14.   code2=code2+255
  15.  End If
  16.  char2=Chr(code2)
  17.  Passe2=Replace(Passe2,char3,char2,1,1)
  18.  J=J+1
  19.  If J>longeur1 Then
  20.   J=1
  21.  End If
  22. Next
  23. %>

Reply

Marsh Posté le 16-04-2004 à 12:45:18    

y'a pas une implémentation d'une fonction de hachage ASP ? c'est bourrin ton truc là

Reply

Marsh Posté le 16-04-2004 à 12:54:29    

JagStang a écrit :

y'a pas une implémentation d'une fonction de hachage ASP ? c'est bourrin ton truc là


 
Ça marche  [:airforceone]

Reply

Marsh Posté le 16-04-2004 à 12:54:29   

Reply

Marsh Posté le 16-04-2004 à 12:57:37    

Flyman30 a écrit :


 
Ça marche  [:airforceone]  


belle mentalité...  :o

Reply

Marsh Posté le 16-04-2004 à 13:14:46    

Si tu avais à disposition la librairie (qui existe en PHP) MD5() ...
 
Il n'y aurait pas d'équivalent des fois ?


---------------
Tant que la couleur de la peau sera plus importante que celle des yeux, nous ne connaitrons pas la paix. ● L'écriture, c'est la mémoire du futur. ● Mods FO4
Reply

Marsh Posté le 16-04-2004 à 13:17:44    

Gilbert Gosseyn a écrit :

Si tu avais à disposition la librairie (qui existe en PHP) MD5() ...
 
Il n'y aurait pas d'équivalent des fois ?


c'est ce que j'ai dit il y a 4 post. Mais j'ai pas trouvé sinon. bizzare. En .NET c'est faisable

Reply

Marsh Posté le 16-04-2004 à 13:28:07    

JagStang a écrit :


c'est ce que j'ai dit il y a 4 post. Mais j'ai pas trouvé sinon. bizzare. En .NET c'est faisable


 
Je n'ai rien trouvé d'équivalent non plus  [:airforceone]

Reply

Marsh Posté le 16-04-2004 à 21:44:26    

horreur !!
 
Utilises ça, c'est largement mieux
 

Code :
  1. <%
  2. ' Derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm,
  3. ' as set out in the memo RFC1321.
  4. '
  5. '
  6. ' ASP VBScript code for generating an MD5 'digest' or 'signature' of a string. The
  7. ' MD5 algorithm is one of the industry standard methods for generating digital
  8. ' signatures. It is generically known as a digest, digital signature, one-way
  9. ' encryption, hash or checksum algorithm. A common use for MD5 is for password
  10. ' encryption as it is one-way in nature, that does not mean that your passwords
  11. ' are not free from a dictionary attack.
  12. '
  13. ' This is 'free' software with the following restrictions:
  14. '
  15. ' You may not redistribute this code as a 'sample' or 'demo'. However, you are free
  16. ' to use the source code in your own code, but you may not claim that you created
  17. ' the sample code. It is expressly forbidden to sell or profit from this source code
  18. ' other than by the knowledge gained or the enhanced value added by your own code.
  19. '
  20. ' Use of this software is also done so at your own risk. The code is supplied as
  21. ' is without warranty or guarantee of any kind.
  22. '
  23. ' Should you wish to commission some derivative work based on this code provided
  24. ' here, or any consultancy work, please do not hesitate to contact us.
  25. '
  26. ' Web Site:  http://www.frez.co.uk
  27. ' E-mail:    sales@frez.co.uk
  28. Private Const BITS_TO_A_BYTE = 8
  29. Private Const BYTES_TO_A_WORD = 4
  30. Private Const BITS_TO_A_WORD = 32
  31. Private m_lOnBits(30)
  32. Private m_l2Power(30)
  33.     m_lOnBits(0) = CLng(1)
  34.     m_lOnBits(1) = CLng(3)
  35.     m_lOnBits(2) = CLng(7)
  36.     m_lOnBits(3) = CLng(15)
  37.     m_lOnBits(4) = CLng(31)
  38.     m_lOnBits(5) = CLng(63)
  39.     m_lOnBits(6) = CLng(127)
  40.     m_lOnBits(7) = CLng(255)
  41.     m_lOnBits(8) = CLng(511)
  42.     m_lOnBits(9) = CLng(1023)
  43.     m_lOnBits(10) = CLng(2047)
  44.     m_lOnBits(11) = CLng(4095)
  45.     m_lOnBits(12) = CLng(8191)
  46.     m_lOnBits(13) = CLng(16383)
  47.     m_lOnBits(14) = CLng(32767)
  48.     m_lOnBits(15) = CLng(65535)
  49.     m_lOnBits(16) = CLng(131071)
  50.     m_lOnBits(17) = CLng(262143)
  51.     m_lOnBits(18) = CLng(524287)
  52.     m_lOnBits(19) = CLng(1048575)
  53.     m_lOnBits(20) = CLng(2097151)
  54.     m_lOnBits(21) = CLng(4194303)
  55.     m_lOnBits(22) = CLng(8388607)
  56.     m_lOnBits(23) = CLng(16777215)
  57.     m_lOnBits(24) = CLng(33554431)
  58.     m_lOnBits(25) = CLng(67108863)
  59.     m_lOnBits(26) = CLng(134217727)
  60.     m_lOnBits(27) = CLng(268435455)
  61.     m_lOnBits(28) = CLng(536870911)
  62.     m_lOnBits(29) = CLng(1073741823)
  63.     m_lOnBits(30) = CLng(2147483647)
  64.    
  65.     m_l2Power(0) = CLng(1)
  66.     m_l2Power(1) = CLng(2)
  67.     m_l2Power(2) = CLng(4)
  68.     m_l2Power(3) = CLng(8)
  69.     m_l2Power(4) = CLng(16)
  70.     m_l2Power(5) = CLng(32)
  71.     m_l2Power(6) = CLng(64)
  72.     m_l2Power(7) = CLng(128)
  73.     m_l2Power(8) = CLng(256)
  74.     m_l2Power(9) = CLng(512)
  75.     m_l2Power(10) = CLng(1024)
  76.     m_l2Power(11) = CLng(2048)
  77.     m_l2Power(12) = CLng(4096)
  78.     m_l2Power(13) = CLng(8192)
  79.     m_l2Power(14) = CLng(16384)
  80.     m_l2Power(15) = CLng(32768)
  81.     m_l2Power(16) = CLng(65536)
  82.     m_l2Power(17) = CLng(131072)
  83.     m_l2Power(18) = CLng(262144)
  84.     m_l2Power(19) = CLng(524288)
  85.     m_l2Power(20) = CLng(1048576)
  86.     m_l2Power(21) = CLng(2097152)
  87.     m_l2Power(22) = CLng(4194304)
  88.     m_l2Power(23) = CLng(8388608)
  89.     m_l2Power(24) = CLng(16777216)
  90.     m_l2Power(25) = CLng(33554432)
  91.     m_l2Power(26) = CLng(67108864)
  92.     m_l2Power(27) = CLng(134217728)
  93.     m_l2Power(28) = CLng(268435456)
  94.     m_l2Power(29) = CLng(536870912)
  95.     m_l2Power(30) = CLng(1073741824)
  96. Private Function LShift(lValue, iShiftBits)
  97.     If iShiftBits = 0 Then
  98.         LShift = lValue
  99.         Exit Function
  100.     ElseIf iShiftBits = 31 Then
  101.         If lValue And 1 Then
  102.             LShift = &H80000000
  103.         Else
  104.             LShift = 0
  105.         End If
  106.         Exit Function
  107.     ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
  108.         Err.Raise 6
  109.     End If
  110.     If (lValue And m_l2Power(31 - iShiftBits)) Then
  111.         LShift = ((lValue And m_lOnBits(31 - (iShiftBits + 1))) * m_l2Power(iShiftBits)) Or &H80000000
  112.     Else
  113.         LShift = ((lValue And m_lOnBits(31 - iShiftBits)) * m_l2Power(iShiftBits))
  114.     End If
  115. End Function
  116. Private Function RShift(lValue, iShiftBits)
  117.     If iShiftBits = 0 Then
  118.         RShift = lValue
  119.         Exit Function
  120.     ElseIf iShiftBits = 31 Then
  121.         If lValue And &H80000000 Then
  122.             RShift = 1
  123.         Else
  124.             RShift = 0
  125.         End If
  126.         Exit Function
  127.     ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
  128.         Err.Raise 6
  129.     End If
  130.    
  131.     RShift = (lValue And &H7FFFFFFE) \ m_l2Power(iShiftBits)
  132.     If (lValue And &H80000000) Then
  133.         RShift = (RShift Or (&H40000000 \ m_l2Power(iShiftBits - 1)))
  134.     End If
  135. End Function
  136. Private Function RotateLeft(lValue, iShiftBits)
  137.     RotateLeft = LShift(lValue, iShiftBits) Or RShift(lValue, (32 - iShiftBits))
  138. End Function
  139. Private Function AddUnsigned(lX, lY)
  140.     Dim lX4
  141.     Dim lY4
  142.     Dim lX8
  143.     Dim lY8
  144.     Dim lResult
  145.     lX8 = lX And &H80000000
  146.     lY8 = lY And &H80000000
  147.     lX4 = lX And &H40000000
  148.     lY4 = lY And &H40000000
  149.     lResult = (lX And &H3FFFFFFF) + (lY And &H3FFFFFFF)
  150.     If lX4 And lY4 Then
  151.         lResult = lResult Xor &H80000000 Xor lX8 Xor lY8
  152.     ElseIf lX4 Or lY4 Then
  153.         If lResult And &H40000000 Then
  154.             lResult = lResult Xor &HC0000000 Xor lX8 Xor lY8
  155.         Else
  156.             lResult = lResult Xor &H40000000 Xor lX8 Xor lY8
  157.         End If
  158.     Else
  159.         lResult = lResult Xor lX8 Xor lY8
  160.     End If
  161.     AddUnsigned = lResult
  162. End Function
  163. Private Function F(x, y, z)
  164.     F = (x And y) Or ((Not x) And z)
  165. End Function
  166. Private Function G(x, y, z)
  167.     G = (x And z) Or (y And (Not z))
  168. End Function
  169. Private Function H(x, y, z)
  170.     H = (x Xor y Xor z)
  171. End Function
  172. Private Function I(x, y, z)
  173.     I = (y Xor (x Or (Not z)))
  174. End Function
  175. Private Sub FF(a, b, c, d, x, s, ac)
  176.     a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac))
  177.     a = RotateLeft(a, s)
  178.     a = AddUnsigned(a, b)
  179. End Sub
  180. Private Sub GG(a, b, c, d, x, s, ac)
  181.     a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac))
  182.     a = RotateLeft(a, s)
  183.     a = AddUnsigned(a, b)
  184. End Sub
  185. Private Sub HH(a, b, c, d, x, s, ac)
  186.     a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac))
  187.     a = RotateLeft(a, s)
  188.     a = AddUnsigned(a, b)
  189. End Sub
  190. Private Sub II(a, b, c, d, x, s, ac)
  191.     a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac))
  192.     a = RotateLeft(a, s)
  193.     a = AddUnsigned(a, b)
  194. End Sub
  195. Private Function ConvertToWordArray(sMessage)
  196.     Dim lMessageLength
  197.     Dim lNumberOfWords
  198.     Dim lWordArray()
  199.     Dim lBytePosition
  200.     Dim lByteCount
  201.     Dim lWordCount
  202.    
  203.     Const MODULUS_BITS = 512
  204.     Const CONGRUENT_BITS = 448
  205.    
  206.     lMessageLength = Len(sMessage)
  207.    
  208.     lNumberOfWords = (((lMessageLength + ((MODULUS_BITS - CONGRUENT_BITS) \ BITS_TO_A_BYTE)) \ (MODULUS_BITS \ BITS_TO_A_BYTE)) + 1) * (MODULUS_BITS \ BITS_TO_A_WORD)
  209.     ReDim lWordArray(lNumberOfWords - 1)
  210.    
  211.     lBytePosition = 0
  212.     lByteCount = 0
  213.     Do Until lByteCount >= lMessageLength
  214.         lWordCount = lByteCount \ BYTES_TO_A_WORD
  215.         lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
  216.         lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(Asc(Mid(sMessage, lByteCount + 1, 1)), lBytePosition)
  217.         lByteCount = lByteCount + 1
  218.     Loop
  219.     lWordCount = lByteCount \ BYTES_TO_A_WORD
  220.     lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
  221.     lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(&H80, lBytePosition)
  222.     lWordArray(lNumberOfWords - 2) = LShift(lMessageLength, 3)
  223.     lWordArray(lNumberOfWords - 1) = RShift(lMessageLength, 29)
  224.    
  225.     ConvertToWordArray = lWordArray
  226. End Function
  227. Private Function WordToHex(lValue)
  228.     Dim lByte
  229.     Dim lCount
  230.    
  231.     For lCount = 0 To 3
  232.         lByte = RShift(lValue, lCount * BITS_TO_A_BYTE) And m_lOnBits(BITS_TO_A_BYTE - 1)
  233.         WordToHex = WordToHex & Right("0" & Hex(lByte), 2)
  234.     Next
  235. End Function
  236. Public Function fct_md5(sMessage)
  237.     Dim x
  238.     Dim k
  239.     Dim AA
  240.     Dim BB
  241.     Dim CC
  242.     Dim DD
  243.     Dim a
  244.     Dim b
  245.     Dim c
  246.     Dim d
  247.    
  248.     Const S11 = 7
  249.     Const S12 = 12
  250.     Const S13 = 17
  251.     Const S14 = 22
  252.     Const S21 = 5
  253.     Const S22 = 9
  254.     Const S23 = 14
  255.     Const S24 = 20
  256.     Const S31 = 4
  257.     Const S32 = 11
  258.     Const S33 = 16
  259.     Const S34 = 23
  260.     Const S41 = 6
  261.     Const S42 = 10
  262.     Const S43 = 15
  263.     Const S44 = 21
  264.     x = ConvertToWordArray(sMessage)
  265.    
  266.     a = &H67452301
  267.     b = &HEFCDAB89
  268.     c = &H98BADCFE
  269.     d = &H10325476
  270.     For k = 0 To UBound(x) Step 16
  271.         AA = a
  272.         BB = b
  273.         CC = c
  274.         DD = d
  275.    
  276.         FF a, b, c, d, x(k + 0), S11, &HD76AA478
  277.         FF d, a, b, c, x(k + 1), S12, &HE8C7B756
  278.         FF c, d, a, b, x(k + 2), S13, &H242070DB
  279.         FF b, c, d, a, x(k + 3), S14, &HC1BDCEEE
  280.         FF a, b, c, d, x(k + 4), S11, &HF57C0FAF
  281.         FF d, a, b, c, x(k + 5), S12, &H4787C62A
  282.         FF c, d, a, b, x(k + 6), S13, &HA8304613
  283.         FF b, c, d, a, x(k + 7), S14, &HFD469501
  284.         FF a, b, c, d, x(k + 8), S11, &H698098D8
  285.         FF d, a, b, c, x(k + 9), S12, &H8B44F7AF
  286.         FF c, d, a, b, x(k + 10), S13, &HFFFF5BB1
  287.         FF b, c, d, a, x(k + 11), S14, &H895CD7BE
  288.         FF a, b, c, d, x(k + 12), S11, &H6B901122
  289.         FF d, a, b, c, x(k + 13), S12, &HFD987193
  290.         FF c, d, a, b, x(k + 14), S13, &HA679438E
  291.         FF b, c, d, a, x(k + 15), S14, &H49B40821
  292.    
  293.         GG a, b, c, d, x(k + 1), S21, &HF61E2562
  294.         GG d, a, b, c, x(k + 6), S22, &HC040B340
  295.         GG c, d, a, b, x(k + 11), S23, &H265E5A51
  296.         GG b, c, d, a, x(k + 0), S24, &HE9B6C7AA
  297.         GG a, b, c, d, x(k + 5), S21, &HD62F105D
  298.         GG d, a, b, c, x(k + 10), S22, &H2441453
  299.         GG c, d, a, b, x(k + 15), S23, &HD8A1E681
  300.         GG b, c, d, a, x(k + 4), S24, &HE7D3FBC8
  301.         GG a, b, c, d, x(k + 9), S21, &H21E1CDE6
  302.         GG d, a, b, c, x(k + 14), S22, &HC33707D6
  303.         GG c, d, a, b, x(k + 3), S23, &HF4D50D87
  304.         GG b, c, d, a, x(k + 8), S24, &H455A14ED
  305.         GG a, b, c, d, x(k + 13), S21, &HA9E3E905
  306.         GG d, a, b, c, x(k + 2), S22, &HFCEFA3F8
  307.         GG c, d, a, b, x(k + 7), S23, &H676F02D9
  308.         GG b, c, d, a, x(k + 12), S24, &H8D2A4C8A
  309.            
  310.         HH a, b, c, d, x(k + 5), S31, &HFFFA3942
  311.         HH d, a, b, c, x(k + 8), S32, &H8771F681
  312.         HH c, d, a, b, x(k + 11), S33, &H6D9D6122
  313.         HH b, c, d, a, x(k + 14), S34, &HFDE5380C
  314.         HH a, b, c, d, x(k + 1), S31, &HA4BEEA44
  315.         HH d, a, b, c, x(k + 4), S32, &H4BDECFA9
  316.         HH c, d, a, b, x(k + 7), S33, &HF6BB4B60
  317.         HH b, c, d, a, x(k + 10), S34, &HBEBFBC70
  318.         HH a, b, c, d, x(k + 13), S31, &H289B7EC6
  319.         HH d, a, b, c, x(k + 0), S32, &HEAA127FA
  320.         HH c, d, a, b, x(k + 3), S33, &HD4EF3085
  321.         HH b, c, d, a, x(k + 6), S34, &H4881D05
  322.         HH a, b, c, d, x(k + 9), S31, &HD9D4D039
  323.         HH d, a, b, c, x(k + 12), S32, &HE6DB99E5
  324.         HH c, d, a, b, x(k + 15), S33, &H1FA27CF8
  325.         HH b, c, d, a, x(k + 2), S34, &HC4AC5665
  326.    
  327.         II a, b, c, d, x(k + 0), S41, &HF4292244
  328.         II d, a, b, c, x(k + 7), S42, &H432AFF97
  329.         II c, d, a, b, x(k + 14), S43, &HAB9423A7
  330.         II b, c, d, a, x(k + 5), S44, &HFC93A039
  331.         II a, b, c, d, x(k + 12), S41, &H655B59C3
  332.         II d, a, b, c, x(k + 3), S42, &H8F0CCC92
  333.         II c, d, a, b, x(k + 10), S43, &HFFEFF47D
  334.         II b, c, d, a, x(k + 1), S44, &H85845DD1
  335.         II a, b, c, d, x(k + 8), S41, &H6FA87E4F
  336.         II d, a, b, c, x(k + 15), S42, &HFE2CE6E0
  337.         II c, d, a, b, x(k + 6), S43, &HA3014314
  338.         II b, c, d, a, x(k + 13), S44, &H4E0811A1
  339.         II a, b, c, d, x(k + 4), S41, &HF7537E82
  340.         II d, a, b, c, x(k + 11), S42, &HBD3AF235
  341.         II c, d, a, b, x(k + 2), S43, &H2AD7D2BB
  342.         II b, c, d, a, x(k + 9), S44, &HEB86D391
  343.    
  344.         a = AddUnsigned(a, AA)
  345.         b = AddUnsigned(b, BB)
  346.         c = AddUnsigned(c, CC)
  347.         d = AddUnsigned(d, DD)
  348.     Next
  349.    
  350.     fct_md5 = LCase(WordToHex(a) & WordToHex(b) & WordToHex(c) & WordToHex(d))
  351. End Function
  352. %>


Message édité par Gfreeman le 16-04-2004 à 21:45:41
Reply

Marsh Posté le 16-04-2004 à 23:07:25    

Peut tu donner des explications sur la façon de s'en servir ?
 
Merci  :)

Reply

Marsh Posté le 17-04-2004 à 00:23:59    

euh pareil...
 
Sinon il existe pas une fonction qui encode ??? ça m'étonne un  peu... ca existe bien en PHP!

Reply

Marsh Posté le 17-04-2004 à 00:29:15    

Ben le MD5 est uniquement pour l'encryption. Pas pour décrypter (ce truc est à sens unique). Donc cette fonction doit faire la même chose. On doit lui donner à manger une variable pour qu'elle fonctionnne.


---------------
Tant que la couleur de la peau sera plus importante que celle des yeux, nous ne connaitrons pas la paix. ● L'écriture, c'est la mémoire du futur. ● Mods FO4
Reply

Marsh Posté le 17-04-2004 à 00:50:23    

Flyman30 a écrit :

Peut tu donner des explications sur la façon de s'en servir ?
 
Merci  :)  


appelles la fonction fct_md5() et passes ton texte en paramètre.

Reply

Marsh Posté le 17-04-2004 à 01:01:42    

oui c'est le source de MD5. Apparement c'est pas implémenté dans la librairie standard. C'est horrible en ASP...

Reply

Marsh Posté le 17-04-2004 à 08:39:35    

Gfreeman a écrit :


appelles la fonction fct_md5() et passes ton texte en paramètre.


 
Merci  :jap:

Reply

Marsh Posté le 17-04-2004 à 10:02:57    

JagStang a écrit :

oui c'est le source de MD5. Apparement c'est pas implémenté dans la librairie standard. C'est horrible en ASP...


Ho mon dieu oui, que c'est laid, bouhouuuuuu !!!

Reply

Marsh Posté le 17-04-2004 à 12:26:16    

Gfreeman a écrit :


Ho mon dieu oui, que c'est laid, bouhouuuuuu !!!


ta gueule :o je parle par rapport à la version originale en C

Reply

Marsh Posté le 17-04-2004 à 14:40:29    


 
Reste poli :sarcastic:

Reply

Marsh Posté le 18-04-2004 à 00:28:55    

oulà tant d'animosité pour un simple question de capacité de langage...  
Gfreeman merci pour le md5 :D

Reply

Marsh Posté le 18-04-2004 à 09:57:53    

3xc4l18ur >> Bah de rien. Voila le code pour l'algo sha1.
 

Code :
  1. <%
  2. ' See the VB6 project that accompanies this sample for full code comments on how
  3. ' it works.
  4. '
  5. ' ASP VBScript code for generating a SHA256 'digest' or 'signature' of a string. The
  6. ' MD5 algorithm is one of the industry standard methods for generating digital
  7. ' signatures. It is generically known as a digest, digital signature, one-way
  8. ' encryption, hash or checksum algorithm. A common use for SHA256 is for password
  9. ' encryption as it is one-way in nature, that does not mean that your passwords
  10. ' are not free from a dictionary attack.
  11. '
  12. ' If you are using the routine for passwords, you can make it a little more secure
  13. ' by concatenating some known random characters to the password before you generate
  14. ' the signature and on subsequent tests, so even if a hacker knows you are using
  15. ' SHA-256 for your passwords, the random characters will make it harder to dictionary
  16. ' attack.
  17. '
  18. ' NOTE: Due to the way in which the string is processed the routine assumes a
  19. ' single byte character set. VB passes unicode (2-byte) character strings, the
  20. ' ConvertToWordArray function uses on the first byte for each character. This
  21. ' has been done this way for ease of use, to make the routine truely portable
  22. ' you could accept a byte array instead, it would then be up to the calling
  23. ' routine to make sure that the byte array is generated from their string in
  24. ' a manner consistent with the string type.
  25. '
  26. ' This is 'free' software with the following restrictions:
  27. '
  28. ' You may not redistribute this code as a 'sample' or 'demo'. However, you are free
  29. ' to use the source code in your own code, but you may not claim that you created
  30. ' the sample code. It is expressly forbidden to sell or profit from this source code
  31. ' other than by the knowledge gained or the enhanced value added by your own code.
  32. '
  33. ' Use of this software is also done so at your own risk. The code is supplied as
  34. ' is without warranty or guarantee of any kind.
  35. '
  36. ' Should you wish to commission some derivative work based on this code provided
  37. ' here, or any consultancy work, please do not hesitate to contact us.
  38. '
  39. ' Web Site:  http://www.frez.co.uk
  40. ' E-mail:    sales@frez.co.uk
  41. Private m_lOnBits(30)
  42. Private m_l2Power(30)
  43. Private K(63)
  44. Private Const BITS_TO_A_BYTE = 8
  45. Private Const BYTES_TO_A_WORD = 4
  46. Private Const BITS_TO_A_WORD = 32
  47. m_lOnBits(0) = CLng(1)
  48. m_lOnBits(1) = CLng(3)
  49. m_lOnBits(2) = CLng(7)
  50. m_lOnBits(3) = CLng(15)
  51. m_lOnBits(4) = CLng(31)
  52. m_lOnBits(5) = CLng(63)
  53. m_lOnBits(6) = CLng(127)
  54. m_lOnBits(7) = CLng(255)
  55. m_lOnBits(8) = CLng(511)
  56. m_lOnBits(9) = CLng(1023)
  57. m_lOnBits(10) = CLng(2047)
  58. m_lOnBits(11) = CLng(4095)
  59. m_lOnBits(12) = CLng(8191)
  60. m_lOnBits(13) = CLng(16383)
  61. m_lOnBits(14) = CLng(32767)
  62. m_lOnBits(15) = CLng(65535)
  63. m_lOnBits(16) = CLng(131071)
  64. m_lOnBits(17) = CLng(262143)
  65. m_lOnBits(18) = CLng(524287)
  66. m_lOnBits(19) = CLng(1048575)
  67. m_lOnBits(20) = CLng(2097151)
  68. m_lOnBits(21) = CLng(4194303)
  69. m_lOnBits(22) = CLng(8388607)
  70. m_lOnBits(23) = CLng(16777215)
  71. m_lOnBits(24) = CLng(33554431)
  72. m_lOnBits(25) = CLng(67108863)
  73. m_lOnBits(26) = CLng(134217727)
  74. m_lOnBits(27) = CLng(268435455)
  75. m_lOnBits(28) = CLng(536870911)
  76. m_lOnBits(29) = CLng(1073741823)
  77. m_lOnBits(30) = CLng(2147483647)
  78. m_l2Power(0) = CLng(1)
  79. m_l2Power(1) = CLng(2)
  80. m_l2Power(2) = CLng(4)
  81. m_l2Power(3) = CLng(8)
  82. m_l2Power(4) = CLng(16)
  83. m_l2Power(5) = CLng(32)
  84. m_l2Power(6) = CLng(64)
  85. m_l2Power(7) = CLng(128)
  86. m_l2Power(8) = CLng(256)
  87. m_l2Power(9) = CLng(512)
  88. m_l2Power(10) = CLng(1024)
  89. m_l2Power(11) = CLng(2048)
  90. m_l2Power(12) = CLng(4096)
  91. m_l2Power(13) = CLng(8192)
  92. m_l2Power(14) = CLng(16384)
  93. m_l2Power(15) = CLng(32768)
  94. m_l2Power(16) = CLng(65536)
  95. m_l2Power(17) = CLng(131072)
  96. m_l2Power(18) = CLng(262144)
  97. m_l2Power(19) = CLng(524288)
  98. m_l2Power(20) = CLng(1048576)
  99. m_l2Power(21) = CLng(2097152)
  100. m_l2Power(22) = CLng(4194304)
  101. m_l2Power(23) = CLng(8388608)
  102. m_l2Power(24) = CLng(16777216)
  103. m_l2Power(25) = CLng(33554432)
  104. m_l2Power(26) = CLng(67108864)
  105. m_l2Power(27) = CLng(134217728)
  106. m_l2Power(28) = CLng(268435456)
  107. m_l2Power(29) = CLng(536870912)
  108. m_l2Power(30) = CLng(1073741824)
  109.    
  110. K(0) = &H428A2F98
  111. K(1) = &H71374491
  112. K(2) = &HB5C0FBCF
  113. K(3) = &HE9B5DBA5
  114. K(4) = &H3956C25B
  115. K(5) = &H59F111F1
  116. K(6) = &H923F82A4
  117. K(7) = &HAB1C5ED5
  118. K(8) = &HD807AA98
  119. K(9) = &H12835B01
  120. K(10) = &H243185BE
  121. K(11) = &H550C7DC3
  122. K(12) = &H72BE5D74
  123. K(13) = &H80DEB1FE
  124. K(14) = &H9BDC06A7
  125. K(15) = &HC19BF174
  126. K(16) = &HE49B69C1
  127. K(17) = &HEFBE4786
  128. K(18) = &HFC19DC6
  129. K(19) = &H240CA1CC
  130. K(20) = &H2DE92C6F
  131. K(21) = &H4A7484AA
  132. K(22) = &H5CB0A9DC
  133. K(23) = &H76F988DA
  134. K(24) = &H983E5152
  135. K(25) = &HA831C66D
  136. K(26) = &HB00327C8
  137. K(27) = &HBF597FC7
  138. K(28) = &HC6E00BF3
  139. K(29) = &HD5A79147
  140. K(30) = &H6CA6351
  141. K(31) = &H14292967
  142. K(32) = &H27B70A85
  143. K(33) = &H2E1B2138
  144. K(34) = &H4D2C6DFC
  145. K(35) = &H53380D13
  146. K(36) = &H650A7354
  147. K(37) = &H766A0ABB
  148. K(38) = &H81C2C92E
  149. K(39) = &H92722C85
  150. K(40) = &HA2BFE8A1
  151. K(41) = &HA81A664B
  152. K(42) = &HC24B8B70
  153. K(43) = &HC76C51A3
  154. K(44) = &HD192E819
  155. K(45) = &HD6990624
  156. K(46) = &HF40E3585
  157. K(47) = &H106AA070
  158. K(48) = &H19A4C116
  159. K(49) = &H1E376C08
  160. K(50) = &H2748774C
  161. K(51) = &H34B0BCB5
  162. K(52) = &H391C0CB3
  163. K(53) = &H4ED8AA4A
  164. K(54) = &H5B9CCA4F
  165. K(55) = &H682E6FF3
  166. K(56) = &H748F82EE
  167. K(57) = &H78A5636F
  168. K(58) = &H84C87814
  169. K(59) = &H8CC70208
  170. K(60) = &H90BEFFFA
  171. K(61) = &HA4506CEB
  172. K(62) = &HBEF9A3F7
  173. K(63) = &HC67178F2
  174. Private Function LShift(lValue, iShiftBits)
  175.     If iShiftBits = 0 Then
  176.         LShift = lValue
  177.         Exit Function
  178.     ElseIf iShiftBits = 31 Then
  179.         If lValue And 1 Then
  180.             LShift = &H80000000
  181.         Else
  182.             LShift = 0
  183.         End If
  184.         Exit Function
  185.     ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
  186.         Err.Raise 6
  187.     End If
  188.    
  189.     If (lValue And m_l2Power(31 - iShiftBits)) Then
  190.         LShift = ((lValue And m_lOnBits(31 - (iShiftBits + 1))) * m_l2Power(iShiftBits)) Or &H80000000
  191.     Else
  192.         LShift = ((lValue And m_lOnBits(31 - iShiftBits)) * m_l2Power(iShiftBits))
  193.     End If
  194. End Function
  195. Private Function RShift(lValue, iShiftBits)
  196.     If iShiftBits = 0 Then
  197.         RShift = lValue
  198.         Exit Function
  199.     ElseIf iShiftBits = 31 Then
  200.         If lValue And &H80000000 Then
  201.             RShift = 1
  202.         Else
  203.             RShift = 0
  204.         End If
  205.         Exit Function
  206.     ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
  207.         Err.Raise 6
  208.     End If
  209.    
  210.     RShift = (lValue And &H7FFFFFFE) \ m_l2Power(iShiftBits)
  211.    
  212.     If (lValue And &H80000000) Then
  213.         RShift = (RShift Or (&H40000000 \ m_l2Power(iShiftBits - 1)))
  214.     End If
  215. End Function
  216. Private Function AddUnsigned(lX, lY)
  217.     Dim lX4
  218.     Dim lY4
  219.     Dim lX8
  220.     Dim lY8
  221.     Dim lResult
  222.     lX8 = lX And &H80000000
  223.     lY8 = lY And &H80000000
  224.     lX4 = lX And &H40000000
  225.     lY4 = lY And &H40000000
  226.     lResult = (lX And &H3FFFFFFF) + (lY And &H3FFFFFFF)
  227.     If lX4 And lY4 Then
  228.         lResult = lResult Xor &H80000000 Xor lX8 Xor lY8
  229.     ElseIf lX4 Or lY4 Then
  230.         If lResult And &H40000000 Then
  231.             lResult = lResult Xor &HC0000000 Xor lX8 Xor lY8
  232.         Else
  233.             lResult = lResult Xor &H40000000 Xor lX8 Xor lY8
  234.         End If
  235.     Else
  236.         lResult = lResult Xor lX8 Xor lY8
  237.     End If
  238.     AddUnsigned = lResult
  239. End Function
  240. Private Function Ch(x, y, z)
  241.     Ch = ((x And y) Xor ((Not x) And z))
  242. End Function
  243. Private Function Maj(x, y, z)
  244.     Maj = ((x And y) Xor (x And z) Xor (y And z))
  245. End Function
  246. Private Function S(x, n)
  247.     S = (RShift(x, (n And m_lOnBits(4))) Or LShift(x, (32 - (n And m_lOnBits(4)))))
  248. End Function
  249. Private Function R(x, n)
  250.     R = RShift(x, CInt(n And m_lOnBits(4)))
  251. End Function
  252. Private Function Sigma0(x)
  253.     Sigma0 = (S(x, 2) Xor S(x, 13) Xor S(x, 22))
  254. End Function
  255. Private Function Sigma1(x)
  256.     Sigma1 = (S(x, 6) Xor S(x, 11) Xor S(x, 25))
  257. End Function
  258. Private Function Gamma0(x)
  259.     Gamma0 = (S(x, 7) Xor S(x, 18) Xor R(x, 3))
  260. End Function
  261. Private Function Gamma1(x)
  262.     Gamma1 = (S(x, 17) Xor S(x, 19) Xor R(x, 10))
  263. End Function
  264. Private Function ConvertToWordArray(sMessage)
  265.     Dim lMessageLength
  266.     Dim lNumberOfWords
  267.     Dim lWordArray()
  268.     Dim lBytePosition
  269.     Dim lByteCount
  270.     Dim lWordCount
  271.     Dim lByte
  272.    
  273.     Const MODULUS_BITS = 512
  274.     Const CONGRUENT_BITS = 448
  275.    
  276.     lMessageLength = Len(sMessage)
  277.    
  278.     lNumberOfWords = (((lMessageLength + ((MODULUS_BITS - CONGRUENT_BITS) \ BITS_TO_A_BYTE)) \ (MODULUS_BITS \ BITS_TO_A_BYTE)) + 1) * (MODULUS_BITS \ BITS_TO_A_WORD)
  279.     ReDim lWordArray(lNumberOfWords - 1)
  280.    
  281.     lBytePosition = 0
  282.     lByteCount = 0
  283.     Do Until lByteCount >= lMessageLength
  284.         lWordCount = lByteCount \ BYTES_TO_A_WORD
  285.        
  286.         lBytePosition = (3 - (lByteCount Mod BYTES_TO_A_WORD)) * BITS_TO_A_BYTE
  287.        
  288.         lByte = AscB(Mid(sMessage, lByteCount + 1, 1))
  289.        
  290.         lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(lByte, lBytePosition)
  291.         lByteCount = lByteCount + 1
  292.     Loop
  293.     lWordCount = lByteCount \ BYTES_TO_A_WORD
  294.     lBytePosition = (3 - (lByteCount Mod BYTES_TO_A_WORD)) * BITS_TO_A_BYTE
  295.     lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(&H80, lBytePosition)
  296.     lWordArray(lNumberOfWords - 1) = LShift(lMessageLength, 3)
  297.     lWordArray(lNumberOfWords - 2) = RShift(lMessageLength, 29)
  298.    
  299.     ConvertToWordArray = lWordArray
  300. End Function
  301. Public Function SHA256(sMessage)
  302.     Dim HASH(7)
  303.     Dim M
  304.     Dim W(63)
  305.     Dim a
  306.     Dim b
  307.     Dim c
  308.     Dim d
  309.     Dim e
  310.     Dim f
  311.     Dim g
  312.     Dim h
  313.     Dim i
  314.     Dim j
  315.     Dim T1
  316.     Dim T2
  317.    
  318.     HASH(0) = &H6A09E667
  319.     HASH(1) = &HBB67AE85
  320.     HASH(2) = &H3C6EF372
  321.     HASH(3) = &HA54FF53A
  322.     HASH(4) = &H510E527F
  323.     HASH(5) = &H9B05688C
  324.     HASH(6) = &H1F83D9AB
  325.     HASH(7) = &H5BE0CD19
  326.    
  327.     M = ConvertToWordArray(sMessage)
  328.    
  329.     For i = 0 To UBound(M) Step 16
  330.         a = HASH(0)
  331.         b = HASH(1)
  332.         c = HASH(2)
  333.         d = HASH(3)
  334.         e = HASH(4)
  335.         f = HASH(5)
  336.         g = HASH(6)
  337.         h = HASH(7)
  338.        
  339.         For j = 0 To 63
  340.             If j < 16 Then
  341.                 W(j) = M(j + i)
  342.             Else
  343.                 W(j) = AddUnsigned(AddUnsigned(AddUnsigned(Gamma1(W(j - 2)), W(j - 7)), Gamma0(W(j - 15))), W(j - 16))
  344.             End If
  345.                
  346.             T1 = AddUnsigned(AddUnsigned(AddUnsigned(AddUnsigned(h, Sigma1(e)), Ch(e, f, g)), K(j)), W(j))
  347.             T2 = AddUnsigned(Sigma0(a), Maj(a, b, c))
  348.            
  349.             h = g
  350.             g = f
  351.             f = e
  352.             e = AddUnsigned(d, T1)
  353.             d = c
  354.             c = b
  355.             b = a
  356.             a = AddUnsigned(T1, T2)
  357.         Next
  358.        
  359.         HASH(0) = AddUnsigned(a, HASH(0))
  360.         HASH(1) = AddUnsigned(b, HASH(1))
  361.         HASH(2) = AddUnsigned(c, HASH(2))
  362.         HASH(3) = AddUnsigned(d, HASH(3))
  363.         HASH(4) = AddUnsigned(e, HASH(4))
  364.         HASH(5) = AddUnsigned(f, HASH(5))
  365.         HASH(6) = AddUnsigned(g, HASH(6))
  366.         HASH(7) = AddUnsigned(h, HASH(7))
  367.     Next
  368.    
  369.     SHA256 = LCase(Right("00000000" & Hex(HASH(0)), 8) & Right("00000000" & Hex(HASH(1)), 8) & Right("00000000" & Hex(HASH(2)), 8) & Right("00000000" & Hex(HASH(3)), 8) & Right("00000000" & Hex(HASH(4)), 8) & Right("00000000" & Hex(HASH(5)), 8) & Right("00000000" & Hex(HASH(6)), 8) & Right("00000000" & Hex(HASH(7)), 8))
  370. End Function
  371. %>


Message édité par Gfreeman le 18-04-2004 à 09:58:52
Reply

Marsh Posté le 18-04-2004 à 10:16:18    

J'ai mieux, un composant MD5.wsc il faut le mettre dans un répertoire avec les droits de lecture
Clic gauche pour l'enregistrer et c'est parti on peut utiliser l'objet!
 
Pour l'appeler :
 

Code :
  1. Function Md5(sString)
  2.     Dim oMd5
  3.     Set oMd5 = Server.CreateObject("MD5.WSC" )
  4.     Md5 = oMd5.CalcMd5(sString)
  5.     Set oMd5 = Nothing
  6. End Function


 
 

Code :
  1. <?xml version="1.0"?>
  2. <component>
  3. <?component error="true" debug="false"?>
  4. <registration
  5. description="MD5"
  6. progid="MD5.WSC"
  7. version="1.00"
  8. classid="{cab3f5a1-775f-4da5-851f-d11c96a1f024}"
  9. />
  10. <public>
  11. <method name="calcMD5">
  12.  <PARAMETER name="sInput"/>
  13. </method>
  14. </public>
  15. <script language="JScript">
  16. <![CDATA[
  17. // ---------------------------------------------------------------------------------
  18. // MD5 Windows Scripting Component wrapper definition
  19. var description = new MD5;
  20. function MD5()
  21. {
  22.  this.calcMD5 = calcMD5;
  23. }
  24. // ---------------------------------------------------------------------------------
  25. // ---------------------------------------------------------------------------------
  26. // Legal notice taken from Google's cache of http://pajhome.org.uk/site/legal.html
  27. /*
  28. The following is distributed under the GNU Lesser General Public License, which
  29. also allows linking into proprietory programs, under certain circumstances.
  30. GNU LGPL described here: http://www.gnu.org/copyleft/lgpl.html
  31. The JavaScript code implementing the algorithm is derived from the C code in
  32. RFC 1321 and is covered by the following copyright:  
  33. ---------------------------------------------------------------------------------
  34. Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All rights reserved.  
  35. License to copy and use this software is granted provided that it is identified  
  36. as the "RSA Data Security, Inc. MD5 Message-Digest Algorithm" in all material  
  37. mentioning or referencing this software or this function.
  38. License is also granted to make and use derivative works provided that such works
  39. are identified as "derived from the RSA Data Security, Inc. MD5 Message-Digest  
  40. Algorithm" in all material mentioning or referencing the derived work.
  41. RSA Data Security, Inc. makes no representations concerning either the  
  42. merchantability of this software or the suitability of this software for any  
  43. particular purpose. It is provided "as is" without express or implied warranty  
  44. of any kind.
  45. These notices must be retained in any copies of any part of this documentation  
  46. and/or software.  
  47. ---------------------------------------------------------------------------------
  48. This copyright does not prohibit distribution of the JavaScript code under LGPL.
  49. */
  50. // ---------------------------------------------------------------------------------
  51. // ---------------------------------------------------------------------------------
  52. // MD5 code taken from Google's cache of http://pajhome.org.uk/crypt/md5/md5src.html
  53. /*
  54.  * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
  55.  * Digest Algorithm, as defined in RFC 1321.
  56.  * Copyright (C) Paul Johnston 1999 - 2002.
  57.  * Code also contributed by Greg Holt
  58.  * See http://pajhome.org.uk/site/legal.html for details. (also copied above)
  59.  */
  60. /*
  61.  * Convert a 32-bit number to a hex string with ls-byte first
  62.  */
  63. var hex_chr = "0123456789ABCDEF"; // changed to use upper-case hex chars
  64. //var hex_chr = "0123456789abcdef"; // original lower-case hex chars
  65. function rhex(num)
  66. {
  67.  var str = "";
  68.  for(var j = 0; j <= 3; j++)
  69.    str += hex_chr.charAt((num >> (j * 8 + 4)) & 0x0F) +
  70.           hex_chr.charAt((num >> (j * 8)) & 0x0F);
  71.  return str;
  72. }
  73. /*
  74.  * Convert a string to a sequence of 16-word blocks, stored as an array.
  75.  * Append padding bits and the length, as described in the MD5 standard.
  76.  */
  77. function str2blks_MD5(str)
  78. {
  79.  var nblk = ((str.length + 8) >> 6) + 1; // number of 16-word blocks
  80.  var blks = new Array(nblk * 16);
  81.  for(var i = 0; i < nblk * 16; i++) blks[i] = 0;
  82.  for(var i = 0; i < str.length; i++)
  83.   blks[i >> 2] |= str.charCodeAt(i) << ((i % 4) * 8);
  84.  blks[i >> 2] |= 0x80 << ((i % 4) * 8);
  85.  blks[nblk * 16 - 2] = str.length * 8;
  86.  return blks;
  87. }
  88. /*
  89.  * Add integers, wrapping at 2^32. This uses 16-bit operations internally
  90.  * to work around bugs in some JS interpreters.
  91.  */
  92. function safe_add(x, y)
  93. {
  94.  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  95.  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  96.  return (msw << 16) | (lsw & 0xFFFF);
  97. }
  98. /*
  99.  * Bitwise rotate a 32-bit number to the left
  100.  */
  101. function rol(num, cnt)
  102. {
  103.  return (num << cnt) | (num >>> (32 - cnt));
  104. }
  105. /*
  106.  * These functions implement the basic operation for each round of the
  107.  * algorithm.
  108.  */
  109. function cmn(q, a, b, x, s, t)
  110. {
  111.  return safe_add(rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b);
  112. }
  113. function ff(a, b, c, d, x, s, t)
  114. {
  115.  return cmn((b & c) | ((~b) & d), a, b, x, s, t);
  116. }
  117. function gg(a, b, c, d, x, s, t)
  118. {
  119.  return cmn((b & d) | (c & (~d)), a, b, x, s, t);
  120. }
  121. function hh(a, b, c, d, x, s, t)
  122. {
  123.  return cmn(b ^ c ^ d, a, b, x, s, t);
  124. }
  125. function ii(a, b, c, d, x, s, t)
  126. {
  127.  return cmn(c ^ (b | (~d)), a, b, x, s, t);
  128. }
  129. /*
  130.  * Take a string and return the hex representation of its MD5.
  131.  */
  132. function calcMD5(sInput)
  133. {
  134.  var x = str2blks_MD5(sInput);
  135.  var a =  1732584193;
  136.  var b = -271733879;
  137.  var c = -1732584194;
  138.  var d =  271733878;
  139.  for(i = 0; i < x.length; i += 16)
  140.  {
  141.     var olda = a;
  142.     var oldb = b;
  143.     var oldc = c;
  144.     var oldd = d;
  145.     a = ff(a, b, c, d, x[i+ 0], 7 , -680876936);
  146.     d = ff(d, a, b, c, x[i+ 1], 12, -389564586);
  147.     c = ff(c, d, a, b, x[i+ 2], 17,  606105819);
  148.     b = ff(b, c, d, a, x[i+ 3], 22, -1044525330);
  149.     a = ff(a, b, c, d, x[i+ 4], 7 , -176418897);
  150.     d = ff(d, a, b, c, x[i+ 5], 12,  1200080426);
  151.     c = ff(c, d, a, b, x[i+ 6], 17, -1473231341);
  152.     b = ff(b, c, d, a, x[i+ 7], 22, -45705983);
  153.     a = ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
  154.     d = ff(d, a, b, c, x[i+ 9], 12, -1958414417);
  155.     c = ff(c, d, a, b, x[i+10], 17, -42063);
  156.     b = ff(b, c, d, a, x[i+11], 22, -1990404162);
  157.     a = ff(a, b, c, d, x[i+12], 7 ,  1804603682);
  158.     d = ff(d, a, b, c, x[i+13], 12, -40341101);
  159.     c = ff(c, d, a, b, x[i+14], 17, -1502002290);
  160.     b = ff(b, c, d, a, x[i+15], 22,  1236535329);
  161.     a = gg(a, b, c, d, x[i+ 1], 5 , -165796510);
  162.     d = gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
  163.     c = gg(c, d, a, b, x[i+11], 14,  643717713);
  164.     b = gg(b, c, d, a, x[i+ 0], 20, -373897302);
  165.     a = gg(a, b, c, d, x[i+ 5], 5 , -701558691);
  166.     d = gg(d, a, b, c, x[i+10], 9 ,  38016083);
  167.     c = gg(c, d, a, b, x[i+15], 14, -660478335);
  168.     b = gg(b, c, d, a, x[i+ 4], 20, -405537848);
  169.     a = gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
  170.     d = gg(d, a, b, c, x[i+14], 9 , -1019803690);
  171.     c = gg(c, d, a, b, x[i+ 3], 14, -187363961);
  172.     b = gg(b, c, d, a, x[i+ 8], 20,  1163531501);
  173.     a = gg(a, b, c, d, x[i+13], 5 , -1444681467);
  174.     d = gg(d, a, b, c, x[i+ 2], 9 , -51403784);
  175.     c = gg(c, d, a, b, x[i+ 7], 14,  1735328473);
  176.     b = gg(b, c, d, a, x[i+12], 20, -1926607734);
  177.     a = hh(a, b, c, d, x[i+ 5], 4 , -378558);
  178.     d = hh(d, a, b, c, x[i+ 8], 11, -2022574463);
  179.     c = hh(c, d, a, b, x[i+11], 16,  1839030562);
  180.     b = hh(b, c, d, a, x[i+14], 23, -35309556);
  181.     a = hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
  182.     d = hh(d, a, b, c, x[i+ 4], 11,  1272893353);
  183.     c = hh(c, d, a, b, x[i+ 7], 16, -155497632);
  184.     b = hh(b, c, d, a, x[i+10], 23, -1094730640);
  185.     a = hh(a, b, c, d, x[i+13], 4 ,  681279174);
  186.     d = hh(d, a, b, c, x[i+ 0], 11, -358537222);
  187.     c = hh(c, d, a, b, x[i+ 3], 16, -722521979);
  188.     b = hh(b, c, d, a, x[i+ 6], 23,  76029189);
  189.     a = hh(a, b, c, d, x[i+ 9], 4 , -640364487);
  190.     d = hh(d, a, b, c, x[i+12], 11, -421815835);
  191.     c = hh(c, d, a, b, x[i+15], 16,  530742520);
  192.     b = hh(b, c, d, a, x[i+ 2], 23, -995338651);
  193.     a = ii(a, b, c, d, x[i+ 0], 6 , -198630844);
  194.     d = ii(d, a, b, c, x[i+ 7], 10,  1126891415);
  195.     c = ii(c, d, a, b, x[i+14], 15, -1416354905);
  196.     b = ii(b, c, d, a, x[i+ 5], 21, -57434055);
  197.     a = ii(a, b, c, d, x[i+12], 6 ,  1700485571);
  198.     d = ii(d, a, b, c, x[i+ 3], 10, -1894986606);
  199.     c = ii(c, d, a, b, x[i+10], 15, -1051523);
  200.     b = ii(b, c, d, a, x[i+ 1], 21, -2054922799);
  201.     a = ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
  202.     d = ii(d, a, b, c, x[i+15], 10, -30611744);
  203.     c = ii(c, d, a, b, x[i+ 6], 15, -1560198380);
  204.     b = ii(b, c, d, a, x[i+13], 21,  1309151649);
  205.     a = ii(a, b, c, d, x[i+ 4], 6 , -145523070);
  206.     d = ii(d, a, b, c, x[i+11], 10, -1120210379);
  207.     c = ii(c, d, a, b, x[i+ 2], 15,  718787259);
  208.     b = ii(b, c, d, a, x[i+ 9], 21, -343485551);
  209.     a = safe_add(a, olda);
  210.     b = safe_add(b, oldb);
  211.     c = safe_add(c, oldc);
  212.     d = safe_add(d, oldd);
  213.  }
  214.  return rhex(a) + rhex(b) + rhex(c) + rhex(d);
  215. }
  216. ]]>
  217. </script>
  218. </component>


 
 

Reply

Marsh Posté le    

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed