MD5加密算法(asp)

加密|算法

我想 用户密码有加密才是安全的(相对),不是吗?
下面是 md5加密算法!
<%
Private Const BITS_TO_A_BYTE = 8
Private Const BYTES_TO_A_WORD = 4
Private Const BITS_TO_A_WORD = 32

Private m_lOnBits(30)
Private m_l2Power(30)

Private Function LShift(lValue, iShiftBits)
If iShiftBits = 0 Then
LShift = lValue
Exit Function
ElseIf iShiftBits = 31 Then
If lValue And 1 Then
LShift = &H80000000
Else
LShift = 0
End If
Exit Function
ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
Err.Raise 6
End If

If (lValue And m_l2Power(31 - iShiftBits)) Then
LShift = ((lValue And m_lOnBits(31 - (iShiftBits + 1))) * m_l2Power(iShiftBits)) Or &H80000000
Else
LShift = ((lValue And m_lOnBits(31 - iShiftBits)) * m_l2Power(iShiftBits))
End If
End Function

Private Function RShift(lValue, iShiftBits)
If iShiftBits = 0 Then
RShift = lValue
Exit Function
ElseIf iShiftBits = 31 Then
If lValue And &H80000000 Then
RShift = 1
Else
RShift = 0
End If
Exit Function
ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
Err.Raise 6
End If

RShift = (lValue And &H7FFFFFFE) \ m_l2Power(iShiftBits)

If (lValue And &H80000000) Then
RShift = (RShift Or (&H40000000 \ m_l2Power(iShiftBits - 1)))
End If
End Function

Private Function RotateLeft(lValue, iShiftBits)
RotateLeft = LShift(lValue, iShiftBits) Or RShift(lValue, (32 - iShiftBits))
End Function

Private Function AddUnsigned(lX, lY)
Dim lX4
Dim lY4
Dim lX8
Dim lY8
Dim lResult

lX8 = lX And &H80000000
lY8 = lY And &H80000000
lX4 = lX And &H40000000
lY4 = lY And &H40000000

lResult = (lX And &H3FFFFFFF) + (lY And &H3FFFFFFF)

If lX4 And lY4 Then
lResult = lResult Xor &H80000000 Xor lX8 Xor lY8
ElseIf lX4 Or lY4 Then
If lResult And &H40000000 Then
lResult = lResult Xor &HC0000000 Xor lX8 Xor lY8
Else
lResult = lResult Xor &H40000000 Xor lX8 Xor lY8
End If
Else
lResult = lResult Xor lX8 Xor lY8
End If

AddUnsigned = lResult
End Function

Private Function md5_F(x, y, z)
md5_F = (x And y) Or ((Not x) And z)
End Function

Private Function md5_G(x, y, z)
md5_G = (x And z) Or (y And (Not z))
End Function

Private Function md5_H(x, y, z)
md5_H = (x Xor y Xor z)
End Function

Private Function md5_I(x, y, z)
md5_I = (y Xor (x Or (Not z)))
End Function

Private Sub md5_FF(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_F(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub

Private Sub md5_GG(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_G(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub

Private Sub md5_HH(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_H(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub

Private Sub md5_II(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_I(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub

Private Function ConvertToWordArray(sMessage)
Dim lMessageLength
Dim lNumberOfWords
Dim lWordArray()
Dim lBytePosition
Dim lByteCount
Dim lWordCount

Const MODULUS_BITS = 512
Const CONGRUENT_BITS = 448

lMessageLength = Len(sMessage)

lNumberOfWords = (((lMessageLength + ((MODULUS_BITS - CONGRUENT_BITS) \ BITS_TO_A_BYTE)) \ (MODULUS_BITS \ BITS_TO_A_BYTE)) + 1) * (MODULUS_BITS \ BITS_TO_A_WORD)
ReDim lWordArray(lNumberOfWords - 1)

lBytePosition = 0
lByteCount = 0
Do Until lByteCount >= lMessageLength
lWordCount = lByteCount \ BYTES_TO_A_WORD
lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(Asc(Mid(sMessage, lByteCount + 1, 1)), lBytePosition)
lByteCount = lByteCount + 1
Loop

lWordCount = lByteCount \ BYTES_TO_A_WORD
lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE

lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(&H80, lBytePosition)

lWordArray(lNumberOfWords - 2) = LShift(lMessageLength, 3

时间: 2024-10-30 09:52:16

MD5加密算法(asp)的相关文章

MD5加密算法 ASP版

加密|算法|加密|算法   <% private const bits_to_a_byte = 8 private const bytes_to_a_word = 4 private const bits_to_a_word = 32 private m_lonbits(30) private m_l2power(30) private function lshift(lvalue, ishiftbits) if ishiftbits = 0 then lshift = lvalue exit

asp md5加密算法完整文件

asp教程 md5加密算法完整文件 private const bits_to_a_byte = 8 private const bytes_to_a_word = 4 private const bits_to_a_word = 32 private m_lonbits(30) private m_l2power(30)   private function lshift(lvalue, ishiftbits)     if ishiftbits = 0 then         lshift

MD5加密算法在网站数据库安全方面的应用与查表攻击

编者按:本文作者为北师大的大三学生张俏,女Geek,在CSDN等各大网站的用户数据被泄露之后,她就MD5加密问题写下此文,发表了自己的看法,如果有读者想要跟作者进一步探讨,可以在新浪微博@阿豆拉. MD5为现在应用最广泛的Hash算法之一,在1992年由MIT 的Ronald L. Riverst提出,由MD4演化而来.该算法广泛应用于互联网网站的用户数据加密,能够将用户密码加密为128位的长整数.数据库并不明文存储用户密码,而是在用户登录时将输入密码字符串进行MD5加密,与数据库中所存储的MD

JAVA实现MD5加密算法

java MD5加密算法:   package com.task.util; import java.security.NoSuchAlgorithmException; //生成32小的md5加密数据 public class MD5 { public String getMD5(byte[] source) { String s = null; char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a'

iOS中MD5加密算法的介绍和使用_IOS

前言 软件开发过程中,对数据进行加密是保证数据安全的重要手段,常见的加密有Base64加密和MD5加密.Base64加密是可逆的,MD5加密目前来说一般是不可逆的. MD5生成的是固定的128bit,即128个0和1的二进制位,而在实际应用开发中,通常是以16进制输出的,所以正好就是32位的16进制,说白了也就是32个16进制的数字. MD5主要特点是 不可逆,相同数据的MD5值肯定一样,不同数据的MD5值不一样(也不是绝对的,但基本是不能一样的). MD5算法还具有以下性质:       1.

Android编程之MD5加密算法实例分析_Android

本文实例分析了Android编程之MD5加密算法.分享给大家供大家参考,具体如下: Android MD5加密算与J2SE平台一模一样,因为Android 平台支持 java.security.MessageDigest这个包.实际上与J2SE平台一模一样. 算法签名: 复制代码 代码如下: String getMD5(String val) throws NoSuchAlgorithmException 输入一个String(需要加密的文本),得到一个加密输出String(加密后的文本) pa

java自带的MessageDigest实现文本的md5加密算法_java

本篇使用java自带的MessageDigest实现对文本的md5加密算法,具体代码如下: /** *@Description: 将字符串转化为MD5 */ package cn.yicha.novel.util; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class ParseMD5 { /** * @param str * @return * @Descr

java,android,MD5加密算法的实现代码(16位,32位)_java

如下所示: import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Md5 { public static String getMD5(String val) throws NoSuchAlgorithmException{ MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update

Java与C++实现相同的MD5加密算法简单实例_java

1.Java版 package com.lyz.utils.common; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; /** * MD5加密 * @author liuyazhuang */ public class MD5Hash { public static String md5