当前位置: 网学 > 编程文档 > ASP > 正文

ASP 改良版MD5、SHA256多重加密类(二次及多次)

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 13/06/16
lWordCount) or SHA256_LShift(lByte, lBytePosition)
lByteCount = lByteCount + 1
Loop
lWordCount = lByteCount \ BYTES_TO_A_WORD
lBytePosition = (3 - (lByteCount Mod BYTES_TO_A_WORD)) * BITS_TO_A_BYTE
lWordArray(lWordCount) = lWordArray(lWordCount) or SHA256_LShift(&H80, lBytePosition)
lWordArray(lNumberOfWords - 1) = SHA256_LShift(lMessageLength, 3)
lWordArray(lNumberOfWords - 2) = SHA256_RShift(lMessageLength, 29)
SHA256_ConvertToWordArray = lWordArray
End Function

'' ==========================================================================================
'' SHA256 加密算法
'' ========================================================================================
'' 调用方法:
'' SHA256(sMessage, p_Len)
'' p_Len控制生成字符串长度,1为8位,2为16位,最大取值为8,即加密后长度为64位
'' 控制 8 位\16 位\24 位\32 位\40 位\48 位\56 位\64 位加密
Public Function SHA256(byVal sMessage, byVal p_Len)
Dim HASH(7)
Dim M
Dim W(63)
Dim a
Dim b
Dim c
Dim d
Dim e
Dim f
Dim g
Dim h
Dim i
Dim j
Dim T1
Dim T2
HASH(0) = &H6A09E667
HASH(1) = &HBB67AE85
HASH(2) = &H3C6EF372
HASH(3) = &HA54FF53A
HASH(4) = &H510E527F
HASH(5) = &H9B05688C
HASH(6) = &H1F83D9AB
HASH(7) = &H5BE0CD19
M = SHA256_ConvertToWordArray(sMessage)
For i = 0 To UBound(M) Step 16
a = HASH(0)
b = HASH(1)
c = HASH(2)
d = HASH(3)
e = HASH(4)
f = HASH(5)
g = HASH(6)
h = HASH(7)
For j = 0 To 63
If j < 16 Then
W(j) = M(j + i)
Else
W(j) = SHA256_AddUnsigned(SHA256_AddUnsigned(SHA256_AddUnsigned(SHA256_Gamma1(W(j - 2)), W(j - 7)), SHA256_Gamma0(W(j - 15))), W(j - 16))
End If
T1 = SHA256_AddUnsigned(SHA256_AddUnsigned(SHA256_AddUnsigned(SHA256_AddUnsigned(h, SHA256_Sigma1(e)), SHA256_CH(e, f, g)), SHA256_K(j)), W(j))
T2 = SHA256_AddUnsigned(SHA256_Sigma0(a), SHA256_Maj(a, b, c))
h = g
g = f
f = e
e = SHA256_AddUnsigned(d, T1)
d = c
c = b
b = a
a = SHA256_AddUnsigned(T1, T2)
Next
HASH(0) = SHA256_AddUnsigned(a, HASH(0))
HASH(1) = SHA256_AddUnsigned(b, HASH(1))
HASH(2) = SHA256_AddUnsigned(c, HASH(2))
HASH(3) = SHA256_AddUnsigned(d, HASH(3))
HASH(4) = SHA256_AddUnsigned(e, HASH(4))
HASH(5) = SHA256_AddUnsigned(f, HASH(5))
HASH(6) = SHA256_AddUnsigned(g, HASH(6))
HASH(7) = SHA256_AddUnsigned(h, HASH(7))
Next
SHA256 = ""
If p_Len >= 8 Then p_Len = 8
If p_Len <= 0 Then p_Len = 2
For i = 0 To p_Len - 1
SHA256 = SHA256 & Right("00000000" & Hex(HASH(i)), 8)
Next
SHA256 = LCase(SHA256)
End Function

Public Function EncryptMode(ByVal p_String, ByVal p_Type)
Dim E1s, E2s
E1s = 16 '' 第一次或者MD5算法加密的长度 16位MD5 加密长度
E2s = 2 '' 第二次或者SHA256算法加密的长度 2*8=16位SHA256 加密长度,最大加密长度为8*8=64位
If Not IsNumeric(p_Type) Then
p_Type = 1
ElseIf p_Type > 7 or p_Type < 0 Then ''判断方案数,根据p_Type最大值判断
p_Type = 1
End If
If Not IsNumeric(E1s) Then
E1s = 16
ElseIf E1s <> 16 And E1s <> 32 Then
E1s = 16
End If
If Not IsNumeric(E2s) Then
E2s = 2
ElseIf E2s > 8 or E2s < 0 Then
E2s = 2
End If
'' ==========================================
'' 初次布置使用的时候最好调整加密方案

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号