代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
ASP
】
改良版MD5、SHA256多重加密
作者:
Dezai.CN
/ 发布于
2012/10/24
/
1363
改良版MD5、SHA256多重加密
<div style="text-align: left;"><span style="background-color: rgb(221, 237, 251); color: rgb(51, 51, 51); font-family: Arial, Tahoma, Verdana, sans-serif; font-size: 14px; line-height: 25px;"><%<span style="background-color: rgb(221, 237, 251); color: rgb(51, 51, 51); font-family: Arial, Tahoma, Verdana, sans-serif; font-size: 14px; line-height: 25px;"></span></div> <div class="codebody" id="code62913" style="padding: 0px 3px 0px 5px; margin: 0px auto 3px; border: 1px solid rgb(0, 153, 204); width: 598px; background-color: rgb(221, 237, 251); clear: both; font-size: 14px; line-height: 25px; color: rgb(51, 51, 51); font-family: Arial, Tahoma, Verdana, sans-serif; text-align: left;">Private Const BITS_TO_A_BYTE = 8<br style="padding: 0px; margin: 0px;"> Private Const BYTES_TO_A_WORD = 4<br style="padding: 0px; margin: 0px;"> Private Const BITS_TO_A_WORD = 32<br style="padding: 0px; margin: 0px;"> Class Cls_Encrypt<br style="padding: 0px; margin: 0px;"> Private MD5_m_lOnBits(30)<br style="padding: 0px; margin: 0px;"> Private MD5_m_l2Power(30)<br style="padding: 0px; margin: 0px;"> Private SHA256_m_lOnBits(30)<br style="padding: 0px; margin: 0px;"> Private SHA256_m_l2Power(30)<br style="padding: 0px; margin: 0px;"> Private SHA256_K(63)<br style="padding: 0px; margin: 0px;"> Private Sub Class_Initialize<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(0) = CLng(1)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(1) = CLng(3)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(2) = CLng(7)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(3) = CLng(15)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(4) = CLng(31)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(5) = CLng(63)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(6) = CLng(127)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(7) = CLng(255)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(8) = CLng(511)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(9) = CLng(1023)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(10) = CLng(2047)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(11) = CLng(4095)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(12) = CLng(8191)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(13) = CLng(16383)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(14) = CLng(32767)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(15) = CLng(65535)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(16) = CLng(131071)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(17) = CLng(262143)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(18) = CLng(524287)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(19) = CLng(1048575)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(20) = CLng(2097151)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(21) = CLng(4194303)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(22) = CLng(8388607)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(23) = CLng(16777215)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(24) = CLng(33554431)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(25) = CLng(67108863)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(26) = CLng(134217727)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(27) = CLng(268435455)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(28) = CLng(536870911)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(29) = CLng(1073741823)<br style="padding: 0px; margin: 0px;"> MD5_m_lOnBits(30) = CLng(2147483647)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(0) = CLng(1)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(1) = CLng(2)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(2) = CLng(4)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(3) = CLng(8)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(4) = CLng(16)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(5) = CLng(32)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(6) = CLng(64)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(7) = CLng(128)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(8) = CLng(256)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(9) = CLng(512)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(10) = CLng(1024)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(11) = CLng(2048)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(12) = CLng(4096)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(13) = CLng(8192)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(14) = CLng(16384)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(15) = CLng(32768)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(16) = CLng(65536)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(17) = CLng(131072)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(18) = CLng(262144)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(19) = CLng(524288)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(20) = CLng(1048576)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(21) = CLng(2097152)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(22) = CLng(4194304)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(23) = CLng(8388608)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(24) = CLng(16777216)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(25) = CLng(33554432)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(26) = CLng(67108864)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(27) = CLng(134217728)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(28) = CLng(268435456)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(29) = CLng(536870912)<br style="padding: 0px; margin: 0px;"> MD5_m_l2Power(30) = CLng(1073741824)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(0) = CLng(1)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(1) = CLng(3)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(2) = CLng(7)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(3) = CLng(15)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(4) = CLng(31)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(5) = CLng(63)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(6) = CLng(127)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(7) = CLng(255)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(8) = CLng(511)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(9) = CLng(1023)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(10) = CLng(2047)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(11) = CLng(4095)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(12) = CLng(8191)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(13) = CLng(16383)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(14) = CLng(32767)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(15) = CLng(65535)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(16) = CLng(131071)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(17) = CLng(262143)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(18) = CLng(524287)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(19) = CLng(1048575)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(20) = CLng(2097151)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(21) = CLng(4194303)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(22) = CLng(8388607)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(23) = CLng(16777215)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(24) = CLng(33554431)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(25) = CLng(67108863)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(26) = CLng(134217727)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(27) = CLng(268435455)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(28) = CLng(536870911)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(29) = CLng(1073741823)<br style="padding: 0px; margin: 0px;"> SHA256_m_lOnBits(30) = CLng(2147483647)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(0) = CLng(1)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(1) = CLng(2)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(2) = CLng(4)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(3) = CLng(8)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(4) = CLng(16)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(5) = CLng(32)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(6) = CLng(64)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(7) = CLng(128)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(8) = CLng(256)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(9) = CLng(512)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(10) = CLng(1024)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(11) = CLng(2048)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(12) = CLng(4096)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(13) = CLng(8192)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(14) = CLng(16384)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(15) = CLng(32768)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(16) = CLng(65536)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(17) = CLng(131072)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(18) = CLng(262144)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(19) = CLng(524288)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(20) = CLng(1048576)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(21) = CLng(2097152)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(22) = CLng(4194304)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(23) = CLng(8388608)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(24) = CLng(16777216)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(25) = CLng(33554432)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(26) = CLng(67108864)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(27) = CLng(134217728)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(28) = CLng(268435456)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(29) = CLng(536870912)<br style="padding: 0px; margin: 0px;"> SHA256_m_l2Power(30) = CLng(1073741824)<br style="padding: 0px; margin: 0px;"> SHA256_K(0) = &H428A2F98<br style="padding: 0px; margin: 0px;"> SHA256_K(1) = &H71374491<br style="padding: 0px; margin: 0px;"> SHA256_K(2) = &HB5C0FBCF<br style="padding: 0px; margin: 0px;"> SHA256_K(3) = &HE9B5DBA5<br style="padding: 0px; margin: 0px;"> SHA256_K(4) = &H3956C25B<br style="padding: 0px; margin: 0px;"> SHA256_K(5) = &H59F111F1<br style="padding: 0px; margin: 0px;"> SHA256_K(6) = &H923F82A4<br style="padding: 0px; margin: 0px;"> SHA256_K(7) = &HAB1C5ED5<br style="padding: 0px; margin: 0px;"> SHA256_K(8) = &HD807AA98<br style="padding: 0px; margin: 0px;"> SHA256_K(9) = &H12835B01<br style="padding: 0px; margin: 0px;"> SHA256_K(10) = &H243185BE<br style="padding: 0px; margin: 0px;"> SHA256_K(11) = &H550C7DC3<br style="padding: 0px; margin: 0px;"> SHA256_K(12) = &H72BE5D74<br style="padding: 0px; margin: 0px;"> SHA256_K(13) = &H80DEB1FE<br style="padding: 0px; margin: 0px;"> SHA256_K(14) = &H9BDC06A7<br style="padding: 0px; margin: 0px;"> SHA256_K(15) = &HC19BF174<br style="padding: 0px; margin: 0px;"> SHA256_K(16) = &HE49B69C1<br style="padding: 0px; margin: 0px;"> SHA256_K(17) = &HEFBE4786<br style="padding: 0px; margin: 0px;"> SHA256_K(18) = &HFC19DC6<br style="padding: 0px; margin: 0px;"> SHA256_K(19) = &H240CA1CC<br style="padding: 0px; margin: 0px;"> SHA256_K(20) = &H2DE92C6F<br style="padding: 0px; margin: 0px;"> SHA256_K(21) = &H4A7484AA<br style="padding: 0px; margin: 0px;"> SHA256_K(22) = &H5CB0A9DC<br style="padding: 0px; margin: 0px;"> SHA256_K(23) = &H76F988DA<br style="padding: 0px; margin: 0px;"> SHA256_K(24) = &H983E5152<br style="padding: 0px; margin: 0px;"> SHA256_K(25) = &HA831C66D<br style="padding: 0px; margin: 0px;"> SHA256_K(26) = &HB00327C8<br style="padding: 0px; margin: 0px;"> SHA256_K(27) = &HBF597FC7<br style="padding: 0px; margin: 0px;"> SHA256_K(28) = &HC6E00BF3<br style="padding: 0px; margin: 0px;"> SHA256_K(29) = &HD5A79147<br style="padding: 0px; margin: 0px;"> SHA256_K(30) = &H6CA6351<br style="padding: 0px; margin: 0px;"> SHA256_K(31) = &H14292967<br style="padding: 0px; margin: 0px;"> SHA256_K(32) = &H27B70A85<br style="padding: 0px; margin: 0px;"> SHA256_K(33) = &H2E1B2138<br style="padding: 0px; margin: 0px;"> SHA256_K(34) = &H4D2C6DFC<br style="padding: 0px; margin: 0px;"> SHA256_K(35) = &H53380D13<br style="padding: 0px; margin: 0px;"> SHA256_K(36) = &H650A7354<br style="padding: 0px; margin: 0px;"> SHA256_K(37) = &H766A0ABB<br style="padding: 0px; margin: 0px;"> SHA256_K(38) = &H81C2C92E<br style="padding: 0px; margin: 0px;"> SHA256_K(39) = &H92722C85<br style="padding: 0px; margin: 0px;"> SHA256_K(40) = &HA2BFE8A1<br style="padding: 0px; margin: 0px;"> SHA256_K(41) = &HA81A664B<br style="padding: 0px; margin: 0px;"> SHA256_K(42) = &HC24B8B70<br style="padding: 0px; margin: 0px;"> SHA256_K(43) = &HC76C51A3<br style="padding: 0px; margin: 0px;"> SHA256_K(44) = &HD192E819<br style="padding: 0px; margin: 0px;"> SHA256_K(45) = &HD6990624<br style="padding: 0px; margin: 0px;"> SHA256_K(46) = &HF40E3585<br style="padding: 0px; margin: 0px;"> SHA256_K(47) = &H106AA070<br style="padding: 0px; margin: 0px;"> SHA256_K(48) = &H19A4C116<br style="padding: 0px; margin: 0px;"> SHA256_K(49) = &H1E376C08<br style="padding: 0px; margin: 0px;"> SHA256_K(50) = &H2748774C<br style="padding: 0px; margin: 0px;"> SHA256_K(51) = &H34B0BCB5<br style="padding: 0px; margin: 0px;"> SHA256_K(52) = &H391C0CB3<br style="padding: 0px; margin: 0px;"> SHA256_K(53) = &H4ED8AA4A<br style="padding: 0px; margin: 0px;"> SHA256_K(54) = &H5B9CCA4F<br style="padding: 0px; margin: 0px;"> SHA256_K(55) = &H682E6FF3<br style="padding: 0px; margin: 0px;"> SHA256_K(56) = &H748F82EE<br style="padding: 0px; margin: 0px;"> SHA256_K(57) = &H78A5636F<br style="padding: 0px; margin: 0px;"> SHA256_K(58) = &H84C87814<br style="padding: 0px; margin: 0px;"> SHA256_K(59) = &H8CC70208<br style="padding: 0px; margin: 0px;"> SHA256_K(60) = &H90BEFFFA<br style="padding: 0px; margin: 0px;"> SHA256_K(61) = &HA4506CEB<br style="padding: 0px; margin: 0px;"> SHA256_K(62) = &HBEF9A3F7<br style="padding: 0px; margin: 0px;"> SHA256_K(63) = &HC67178F2<br style="padding: 0px; margin: 0px;"> End Sub<br style="padding: 0px; margin: 0px;"> Private Sub Class_Terminate<br style="padding: 0px; margin: 0px;"> End Sub<br style="padding: 0px; margin: 0px;"> '字符传转换数组函数<br style="padding: 0px; margin: 0px;"> Private Function ConvertToWordArray(byVal sMessage)<br style="padding: 0px; margin: 0px;"> Dim lMessageLength<br style="padding: 0px; margin: 0px;"> Dim lNumberOfWords<br style="padding: 0px; margin: 0px;"> Dim lWordArray()<br style="padding: 0px; margin: 0px;"> Dim lBytePosition<br style="padding: 0px; margin: 0px;"> Dim lByteCount<br style="padding: 0px; margin: 0px;"> Dim lWordCount<br style="padding: 0px; margin: 0px;"> Const MODULUS_BITS = 512<br style="padding: 0px; margin: 0px;"> Const CONGRUENT_BITS = 448<br style="padding: 0px; margin: 0px;"> lMessageLength = Len(sMessage)<br style="padding: 0px; margin: 0px;"> lNumberOfWords = (((lMessageLength + ((MODULUS_BITS - CONGRUENT_BITS) \ BITS_TO_A_BYTE)) \ (MODULUS_BITS \ BITS_TO_A_BYTE)) + 1) * (MODULUS_BITS \ BITS_TO_A_WORD)<br style="padding: 0px; margin: 0px;"> ReDim lWordArray(lNumberOfWords - 1)<br style="padding: 0px; margin: 0px;"> lBytePosition = 0<br style="padding: 0px; margin: 0px;"> lByteCount = 0<br style="padding: 0px; margin: 0px;"> Do Until lByteCount >= lMessageLength<br style="padding: 0px; margin: 0px;"> lWordCount = lByteCount \ BYTES_TO_A_WORD<br style="padding: 0px; margin: 0px;"> lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE<br style="padding: 0px; margin: 0px;"> lWordArray(lWordCount) = lWordArray(lWordCount) or LShift(Asc(Mid(sMessage, lByteCount + 1, 1)), lBytePosition)<br style="padding: 0px; margin: 0px;"> lByteCount = lByteCount + 1<br style="padding: 0px; margin: 0px;"> Loop<br style="padding: 0px; margin: 0px;"> lWordCount = lByteCount \ BYTES_TO_A_WORD<br style="padding: 0px; margin: 0px;"> lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE<br style="padding: 0px; margin: 0px;"> lWordArray(lWordCount) = lWordArray(lWordCount) or LShift(&H80, lBytePosition)<br style="padding: 0px; margin: 0px;"> lWordArray(lNumberOfWords - 2) = LShift(lMessageLength, 3)<br style="padding: 0px; margin: 0px;"> lWordArray(lNumberOfWords - 1) = RShift(lMessageLength, 29)<br style="padding: 0px; margin: 0px;"> ConvertToWordArray = lWordArray<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> <br style="padding: 0px; margin: 0px;"> '字符串左移位主函数<br style="padding: 0px; margin: 0px;"> Private Function LShift(byVal lValue, byVal iShiftBits)<br style="padding: 0px; margin: 0px;"> If iShiftBits = 0 Then<br style="padding: 0px; margin: 0px;"> LShift = lValue<br style="padding: 0px; margin: 0px;"> Exit Function<br style="padding: 0px; margin: 0px;"> ElseIf iShiftBits = 31 Then<br style="padding: 0px; margin: 0px;"> If lValue And 1 Then<br style="padding: 0px; margin: 0px;"> LShift = &H80000000<br style="padding: 0px; margin: 0px;"> Else<br style="padding: 0px; margin: 0px;"> LShift = 0<br style="padding: 0px; margin: 0px;"> End If<br style="padding: 0px; margin: 0px;"> Exit Function<br style="padding: 0px; margin: 0px;"> ElseIf iShiftBits < 0 or iShiftBits > 31 Then<br style="padding: 0px; margin: 0px;"> Err.Raise 6<br style="padding: 0px; margin: 0px;"> End If<br style="padding: 0px; margin: 0px;"> If (lValue And MD5_m_l2Power(31 - iShiftBits)) Then<br style="padding: 0px; margin: 0px;"> LShift = ((lValue And MD5_m_lOnBits(31 - (iShiftBits + 1))) * MD5_m_l2Power(iShiftBits)) or &H80000000<br style="padding: 0px; margin: 0px;"> Else<br style="padding: 0px; margin: 0px;"> LShift = ((lValue And MD5_m_lOnBits(31 - iShiftBits)) * MD5_m_l2Power(iShiftBits))<br style="padding: 0px; margin: 0px;"> End If<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> '字符串右移位主函数<br style="padding: 0px; margin: 0px;"> Private Function RShift(byVal lValue, byVal iShiftBits)<br style="padding: 0px; margin: 0px;"> If iShiftBits = 0 Then<br style="padding: 0px; margin: 0px;"> RShift = lValue<br style="padding: 0px; margin: 0px;"> Exit Function<br style="padding: 0px; margin: 0px;"> ElseIf iShiftBits = 31 Then<br style="padding: 0px; margin: 0px;"> If lValue And &H80000000 Then<br style="padding: 0px; margin: 0px;"> RShift = 1<br style="padding: 0px; margin: 0px;"> Else<br style="padding: 0px; margin: 0px;"> RShift = 0<br style="padding: 0px; margin: 0px;"> End If<br style="padding: 0px; margin: 0px;"> Exit Function<br style="padding: 0px; margin: 0px;"> ElseIf iShiftBits < 0 or iShiftBits > 31 Then<br style="padding: 0px; margin: 0px;"> Err.Raise 6<br style="padding: 0px; margin: 0px;"> End If<br style="padding: 0px; margin: 0px;"> RShift = (lValue And &H7FFFFFFE) \ MD5_m_l2Power(iShiftBits)<br style="padding: 0px; margin: 0px;"> If (lValue And &H80000000) Then<br style="padding: 0px; margin: 0px;"> RShift = (RShift or (&H40000000 \ MD5_m_l2Power(iShiftBits - 1)))<br style="padding: 0px; margin: 0px;"> End If<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> '字符串偏移转换,通过左右移位函数实现<br style="padding: 0px; margin: 0px;"> Private Function RotateLeft(byVal lValue, byVal iShiftBits)<br style="padding: 0px; margin: 0px;"> RotateLeft = LShift(lValue, iShiftBits) or RShift(lValue, (32 - iShiftBits))<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> '追加无符号16进制编码<br style="padding: 0px; margin: 0px;"> Private Function AddUnsigned(byVal lX, byVal lY)<br style="padding: 0px; margin: 0px;"> Dim lX4<br style="padding: 0px; margin: 0px;"> Dim lY4<br style="padding: 0px; margin: 0px;"> Dim lX8<br style="padding: 0px; margin: 0px;"> Dim lY8<br style="padding: 0px; margin: 0px;"> Dim lResult<br style="padding: 0px; margin: 0px;"> lX8 = lX And &H80000000<br style="padding: 0px; margin: 0px;"> lY8 = lY And &H80000000<br style="padding: 0px; margin: 0px;"> lX4 = lX And &H40000000<br style="padding: 0px; margin: 0px;"> lY4 = lY And &H40000000<br style="padding: 0px; margin: 0px;"> lResult = (lX And &H3FFFFFFF) + (lY And &H3FFFFFFF)<br style="padding: 0px; margin: 0px;"> If lX4 And lY4 Then<br style="padding: 0px; margin: 0px;"> lResult = lResult Xor &H80000000 Xor lX8 Xor lY8<br style="padding: 0px; margin: 0px;"> ElseIf lX4 or lY4 Then<br style="padding: 0px; margin: 0px;"> If lResult And &H40000000 Then<br style="padding: 0px; margin: 0px;"> lResult = lResult Xor &HC0000000 Xor lX8 Xor lY8<br style="padding: 0px; margin: 0px;"> Else<br style="padding: 0px; margin: 0px;"> lResult = lResult Xor &H40000000 Xor lX8 Xor lY8<br style="padding: 0px; margin: 0px;"> End If<br style="padding: 0px; margin: 0px;"> Else<br style="padding: 0px; margin: 0px;"> lResult = lResult Xor lX8 Xor lY8<br style="padding: 0px; margin: 0px;"> End If<br style="padding: 0px; margin: 0px;"> AddUnsigned = lResult<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> <br style="padding: 0px; margin: 0px;"> 'MD5_FF,MD5_GG,MD5_HH,MD5_II MD5主编码函数<br style="padding: 0px; margin: 0px;"> Private Sub MD5_FF(a, b, c, d, x, s, ac)<br style="padding: 0px; margin: 0px;"> a = AddUnsigned(a, AddUnsigned(AddUnsigned(MD5_F(b, c, d), x), ac))<br style="padding: 0px; margin: 0px;"> a = RotateLeft(a, s)<br style="padding: 0px; margin: 0px;"> a = AddUnsigned(a, b)<br style="padding: 0px; margin: 0px;"> End Sub<br style="padding: 0px; margin: 0px;"> Private Sub MD5_GG(a, b, c, d, x, s, ac)<br style="padding: 0px; margin: 0px;"> a = AddUnsigned(a, AddUnsigned(AddUnsigned(MD5_G(b, c, d), x), ac))<br style="padding: 0px; margin: 0px;"> a = RotateLeft(a, s)<br style="padding: 0px; margin: 0px;"> a = AddUnsigned(a, b)<br style="padding: 0px; margin: 0px;"> End Sub<br style="padding: 0px; margin: 0px;"> Private Sub MD5_HH(a, b, c, d, x, s, ac)<br style="padding: 0px; margin: 0px;"> a = AddUnsigned(a, AddUnsigned(AddUnsigned(MD5_H(b, c, d), x), ac))<br style="padding: 0px; margin: 0px;"> a = RotateLeft(a, s)<br style="padding: 0px; margin: 0px;"> a = AddUnsigned(a, b)<br style="padding: 0px; margin: 0px;"> End Sub<br style="padding: 0px; margin: 0px;"> Private Sub MD5_II(a, b, c, d, x, s, ac)<br style="padding: 0px; margin: 0px;"> a = AddUnsigned(a, AddUnsigned(AddUnsigned(MD5_I(b, c, d), x), ac))<br style="padding: 0px; margin: 0px;"> a = RotateLeft(a, s)<br style="padding: 0px; margin: 0px;"> a = AddUnsigned(a, b)<br style="padding: 0px; margin: 0px;"> End Sub<br style="padding: 0px; margin: 0px;"> <br style="padding: 0px; margin: 0px;"> 'MD5_F,MD5_G,MD5_H,MD5_I MD5辅编码函数<br style="padding: 0px; margin: 0px;"> Private Function MD5_F(x, y, z)<br style="padding: 0px; margin: 0px;"> MD5_F = (x And y) or ((Not x) And z)<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> Private Function MD5_G(x, y, z)<br style="padding: 0px; margin: 0px;"> MD5_G = (x And z) or (y And (Not z))<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> Private Function MD5_H(x, y, z)<br style="padding: 0px; margin: 0px;"> MD5_H = (x Xor y Xor z)<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> Private Function MD5_I(x, y, z)<br style="padding: 0px; margin: 0px;"> MD5_I = (y Xor (x or (Not z)))<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> <br style="padding: 0px; margin: 0px;"> '16进制编码转换<br style="padding: 0px; margin: 0px;"> Private Function WordToHex(byVal lValue)<br style="padding: 0px; margin: 0px;"> Dim lByte<br style="padding: 0px; margin: 0px;"> Dim lCount<br style="padding: 0px; margin: 0px;"> For lCount = 0 To 3<br style="padding: 0px; margin: 0px;"> lByte = RShift(lValue, lCount * BITS_TO_A_BYTE) And MD5_m_lOnBits(BITS_TO_A_BYTE - 1)<br style="padding: 0px; margin: 0px;"> WordToHex = WordToHex & Right("0" & Hex(lByte), 2)<br style="padding: 0px; margin: 0px;"> Next<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> <br style="padding: 0px; margin: 0px;"> 'MD5主函数 MD5(字符串,编码位)<br style="padding: 0px; margin: 0px;"> Public Function MD5(byVal sMessage, byVal sType)<br style="padding: 0px; margin: 0px;"> Dim x<br style="padding: 0px; margin: 0px;"> Dim k<br style="padding: 0px; margin: 0px;"> Dim AA<br style="padding: 0px; margin: 0px;"> Dim BB<br style="padding: 0px; margin: 0px;"> Dim CC<br style="padding: 0px; margin: 0px;"> Dim DD<br style="padding: 0px; margin: 0px;"> Dim a<br style="padding: 0px; margin: 0px;"> Dim b<br style="padding: 0px; margin: 0px;"> Dim c<br style="padding: 0px; margin: 0px;"> Dim d<br style="padding: 0px; margin: 0px;"> Const S11 = 7<br style="padding: 0px; margin: 0px;"> Const S12 = 12<br style="padding: 0px; margin: 0px;"> Const S13 = 17<br style="padding: 0px; margin: 0px;"> Const S14 = 22<br style="padding: 0px; margin: 0px;"> Const S21 = 5<br style="padding: 0px; margin: 0px;"> Const S22 = 9<br style="padding: 0px; margin: 0px;"> Const S23 = 14<br style="padding: 0px; margin: 0px;"> Const S24 = 20<br style="padding: 0px; margin: 0px;"> Const S31 = 4<br style="padding: 0px; margin: 0px;"> Const S32 = 11<br style="padding: 0px; margin: 0px;"> Const S33 = 16<br style="padding: 0px; margin: 0px;"> Const S34 = 23<br style="padding: 0px; margin: 0px;"> Const S41 = 6<br style="padding: 0px; margin: 0px;"> Const S42 = 10<br style="padding: 0px; margin: 0px;"> Const S43 = 15<br style="padding: 0px; margin: 0px;"> Const S44 = 21<br style="padding: 0px; margin: 0px;"> x = ConvertToWordArray(sMessage) '加密步骤1:数组转换<br style="padding: 0px; margin: 0px;"> a = &H67452301<br style="padding: 0px; margin: 0px;"> b = &HEFCDAB89<br style="padding: 0px; margin: 0px;"> c = &H98BADCFE<br style="padding: 0px; margin: 0px;"> d = &H10325476<br style="padding: 0px; margin: 0px;"> For k = 0 To UBound(x) Step 16<br style="padding: 0px; margin: 0px;"> AA = a<br style="padding: 0px; margin: 0px;"> BB = b<br style="padding: 0px; margin: 0px;"> CC = c<br style="padding: 0px; margin: 0px;"> DD = d<br style="padding: 0px; margin: 0px;"> '加密步骤2:编码转换<br style="padding: 0px; margin: 0px;"> MD5_FF a, b, c, d, x(k + 0), S11, &HD76AA478<br style="padding: 0px; margin: 0px;"> MD5_FF d, a, b, c, x(k + 1), S12, &HE8C7B756<br style="padding: 0px; margin: 0px;"> MD5_FF c, d, a, b, x(k + 2), S13, &H242070DB<br style="padding: 0px; margin: 0px;"> MD5_FF b, c, d, a, x(k + 3), S14, &HC1BDCEEE<br style="padding: 0px; margin: 0px;"> MD5_FF a, b, c, d, x(k + 4), S11, &HF57C0FAF<br style="padding: 0px; margin: 0px;"> MD5_FF d, a, b, c, x(k + 5), S12, &H4787C62A<br style="padding: 0px; margin: 0px;"> MD5_FF c, d, a, b, x(k + 6), S13, &HA8304613<br style="padding: 0px; margin: 0px;"> MD5_FF b, c, d, a, x(k + 7), S14, &HFD469501<br style="padding: 0px; margin: 0px;"> MD5_FF a, b, c, d, x(k + 8), S11, &H698098D8<br style="padding: 0px; margin: 0px;"> MD5_FF d, a, b, c, x(k + 9), S12, &H8B44F7AF<br style="padding: 0px; margin: 0px;"> MD5_FF c, d, a, b, x(k + 10), S13, &HFFFF5BB1<br style="padding: 0px; margin: 0px;"> MD5_FF b, c, d, a, x(k + 11), S14, &H895CD7BE<br style="padding: 0px; margin: 0px;"> MD5_FF a, b, c, d, x(k + 12), S11, &H6B901122<br style="padding: 0px; margin: 0px;"> MD5_FF d, a, b, c, x(k + 13), S12, &HFD987193<br style="padding: 0px; margin: 0px;"> MD5_FF c, d, a, b, x(k + 14), S13, &HA679438E<br style="padding: 0px; margin: 0px;"> MD5_FF b, c, d, a, x(k + 15), S14, &H49B40821<br style="padding: 0px; margin: 0px;"> MD5_GG a, b, c, d, x(k + 1), S21, &HF61E2562<br style="padding: 0px; margin: 0px;"> MD5_GG d, a, b, c, x(k + 6), S22, &HC040B340<br style="padding: 0px; margin: 0px;"> MD5_GG c, d, a, b, x(k + 11), S23, &H265E5A51<br style="padding: 0px; margin: 0px;"> MD5_GG b, c, d, a, x(k + 0), S24, &HE9B6C7AA<br style="padding: 0px; margin: 0px;"> MD5_GG a, b, c, d, x(k + 5), S21, &HD62F105D<br style="padding: 0px; margin: 0px;"> MD5_GG d, a, b, c, x(k + 10), S22, &H2441453<br style="padding: 0px; margin: 0px;"> MD5_GG c, d, a, b, x(k + 15), S23, &HD8A1E681<br style="padding: 0px; margin: 0px;"> MD5_GG b, c, d, a, x(k + 4), S24, &HE7D3FBC8<br style="padding: 0px; margin: 0px;"> MD5_GG a, b, c, d, x(k + 9), S21, &H21E1CDE6<br style="padding: 0px; margin: 0px;"> MD5_GG d, a, b, c, x(k + 14), S22, &HC33707D6<br style="padding: 0px; margin: 0px;"> MD5_GG c, d, a, b, x(k + 3), S23, &HF4D50D87<br style="padding: 0px; margin: 0px;"> MD5_GG b, c, d, a, x(k + 8), S24, &H455A14ED<br style="padding: 0px; margin: 0px;"> MD5_GG a, b, c, d, x(k + 13), S21, &HA9E3E905<br style="padding: 0px; margin: 0px;"> MD5_GG d, a, b, c, x(k + 2), S22, &HFCEFA3F8<br style="padding: 0px; margin: 0px;"> MD5_GG c, d, a, b, x(k + 7), S23, &H676F02D9<br style="padding: 0px; margin: 0px;"> MD5_GG b, c, d, a, x(k + 12), S24, &H8D2A4C8A<br style="padding: 0px; margin: 0px;"> MD5_HH a, b, c, d, x(k + 5), S31, &HFFFA3942<br style="padding: 0px; margin: 0px;"> MD5_HH d, a, b, c, x(k + 8), S32, &H8771F681<br style="padding: 0px; margin: 0px;"> MD5_HH c, d, a, b, x(k + 11), S33, &H6D9D6122<br style="padding: 0px; margin: 0px;"> MD5_HH b, c, d, a, x(k + 14), S34, &HFDE5380C<br style="padding: 0px; margin: 0px;"> MD5_HH a, b, c, d, x(k + 1), S31, &HA4BEEA44<br style="padding: 0px; margin: 0px;"> MD5_HH d, a, b, c, x(k + 4), S32, &H4BDECFA9<br style="padding: 0px; margin: 0px;"> MD5_HH c, d, a, b, x(k + 7), S33, &HF6BB4B60<br style="padding: 0px; margin: 0px;"> MD5_HH b, c, d, a, x(k + 10), S34, &HBEBFBC70<br style="padding: 0px; margin: 0px;"> MD5_HH a, b, c, d, x(k + 13), S31, &H289B7EC6<br style="padding: 0px; margin: 0px;"> MD5_HH d, a, b, c, x(k + 0), S32, &HEAA127FA<br style="padding: 0px; margin: 0px;"> MD5_HH c, d, a, b, x(k + 3), S33, &HD4EF3085<br style="padding: 0px; margin: 0px;"> MD5_HH b, c, d, a, x(k + 6), S34, &H4881D05<br style="padding: 0px; margin: 0px;"> MD5_HH a, b, c, d, x(k + 9), S31, &HD9D4D039<br style="padding: 0px; margin: 0px;"> MD5_HH d, a, b, c, x(k + 12), S32, &HE6DB99E5<br style="padding: 0px; margin: 0px;"> MD5_HH c, d, a, b, x(k + 15), S33, &H1FA27CF8<br style="padding: 0px; margin: 0px;"> MD5_HH b, c, d, a, x(k + 2), S34, &HC4AC5665<br style="padding: 0px; margin: 0px;"> MD5_II a, b, c, d, x(k + 0), S41, &HF4292244<br style="padding: 0px; margin: 0px;"> MD5_II d, a, b, c, x(k + 7), S42, &H432AFF97<br style="padding: 0px; margin: 0px;"> MD5_II c, d, a, b, x(k + 14), S43, &HAB9423A7<br style="padding: 0px; margin: 0px;"> MD5_II b, c, d, a, x(k + 5), S44, &HFC93A039<br style="padding: 0px; margin: 0px;"> MD5_II a, b, c, d, x(k + 12), S41, &H655B59C3<br style="padding: 0px; margin: 0px;"> MD5_II d, a, b, c, x(k + 3), S42, &H8F0CCC92<br style="padding: 0px; margin: 0px;"> MD5_II c, d, a, b, x(k + 10), S43, &HFFEFF47D<br style="padding: 0px; margin: 0px;"> MD5_II b, c, d, a, x(k + 1), S44, &H85845DD1<br style="padding: 0px; margin: 0px;"> MD5_II a, b, c, d, x(k + 8), S41, &H6FA87E4F<br style="padding: 0px; margin: 0px;"> MD5_II d, a, b, c, x(k + 15), S42, &HFE2CE6E0<br style="padding: 0px; margin: 0px;"> MD5_II c, d, a, b, x(k + 6), S43, &HA3014314<br style="padding: 0px; margin: 0px;"> MD5_II b, c, d, a, x(k + 13), S44, &H4E0811A1<br style="padding: 0px; margin: 0px;"> MD5_II a, b, c, d, x(k + 4), S41, &HF7537E82<br style="padding: 0px; margin: 0px;"> MD5_II d, a, b, c, x(k + 11), S42, &HBD3AF235<br style="padding: 0px; margin: 0px;"> MD5_II c, d, a, b, x(k + 2), S43, &H2AD7D2BB<br style="padding: 0px; margin: 0px;"> MD5_II b, c, d, a, x(k + 9), S44, &HEB86D391<br style="padding: 0px; margin: 0px;"> '加密步骤3:追加无符号转换<br style="padding: 0px; margin: 0px;"> a = AddUnsigned(a, AA)<br style="padding: 0px; margin: 0px;"> b = AddUnsigned(b, BB)<br style="padding: 0px; margin: 0px;"> c = AddUnsigned(c, CC)<br style="padding: 0px; margin: 0px;"> d = AddUnsigned(d, DD)<br style="padding: 0px; margin: 0px;"> Next<br style="padding: 0px; margin: 0px;"> If sType = 32 Then<br style="padding: 0px; margin: 0px;"> '加密步骤4:分割合并各8位16进制转换<br style="padding: 0px; margin: 0px;"> MD5 = LCase(WordToHex(a) & WordToHex(b) & WordToHex(c) & WordToHex(d))<br style="padding: 0px; margin: 0px;"> Else<br style="padding: 0px; margin: 0px;"> MD5 = LCase(WordToHex(b) & WordToHex(c))<br style="padding: 0px; margin: 0px;"> End If<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> Private Function SHA256_LShift(byVal lValue, byVal iShiftBits)<br style="padding: 0px; margin: 0px;"> If iShiftBits = 0 Then<br style="padding: 0px; margin: 0px;"> SHA256_LShift = lValue<br style="padding: 0px; margin: 0px;"> Exit Function<br style="padding: 0px; margin: 0px;"> ElseIf iShiftBits = 31 Then<br style="padding: 0px; margin: 0px;"> If lValue And 1 Then<br style="padding: 0px; margin: 0px;"> SHA256_LShift = &H80000000<br style="padding: 0px; margin: 0px;"> Else<br style="padding: 0px; margin: 0px;"> SHA256_LShift = 0<br style="padding: 0px; margin: 0px;"> End If<br style="padding: 0px; margin: 0px;"> Exit Function<br style="padding: 0px; margin: 0px;"> ElseIf iShiftBits < 0 or iShiftBits > 31 Then<br style="padding: 0px; margin: 0px;"> Err.Raise 6<br style="padding: 0px; margin: 0px;"> End If<br style="padding: 0px; margin: 0px;"> If (lValue And SHA256_m_l2Power(31 - iShiftBits)) Then<br style="padding: 0px; margin: 0px;"> SHA256_LShift = ((lValue And SHA256_m_lOnBits(31 - (iShiftBits + 1))) * SHA256_m_l2Power(iShiftBits)) or &H80000000<br style="padding: 0px; margin: 0px;"> Else<br style="padding: 0px; margin: 0px;"> SHA256_LShift = ((lValue And SHA256_m_lOnBits(31 - iShiftBits)) * SHA256_m_l2Power(iShiftBits))<br style="padding: 0px; margin: 0px;"> End If<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> Private Function SHA256_RShift(byVal lValue, byVal iShiftBits)<br style="padding: 0px; margin: 0px;"> If iShiftBits = 0 Then<br style="padding: 0px; margin: 0px;"> SHA256_RShift = lValue<br style="padding: 0px; margin: 0px;"> Exit Function<br style="padding: 0px; margin: 0px;"> ElseIf iShiftBits = 31 Then<br style="padding: 0px; margin: 0px;"> If lValue And &H80000000 Then<br style="padding: 0px; margin: 0px;"> SHA256_RShift = 1<br style="padding: 0px; margin: 0px;"> Else<br style="padding: 0px; margin: 0px;"> SHA256_RShift = 0<br style="padding: 0px; margin: 0px;"> End If<br style="padding: 0px; margin: 0px;"> Exit Function<br style="padding: 0px; margin: 0px;"> ElseIf iShiftBits < 0 or iShiftBits > 31 Then<br style="padding: 0px; margin: 0px;"> Err.Raise 6<br style="padding: 0px; margin: 0px;"> End If<br style="padding: 0px; margin: 0px;"> SHA256_RShift = (lValue And &H7FFFFFFE) \ SHA256_m_l2Power(iShiftBits)<br style="padding: 0px; margin: 0px;"> If (lValue And &H80000000) Then<br style="padding: 0px; margin: 0px;"> SHA256_RShift = (SHA256_RShift or (&H40000000 \ SHA256_m_l2Power(iShiftBits - 1)))<br style="padding: 0px; margin: 0px;"> End If<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> Private Function SHA256_AddUnsigned(byVal lX, byVal lY)<br style="padding: 0px; margin: 0px;"> Dim lX4<br style="padding: 0px; margin: 0px;"> Dim lY4<br style="padding: 0px; margin: 0px;"> Dim lX8<br style="padding: 0px; margin: 0px;"> Dim lY8<br style="padding: 0px; margin: 0px;"> Dim lResult<br style="padding: 0px; margin: 0px;"> lX8 = lX And &H80000000<br style="padding: 0px; margin: 0px;"> lY8 = lY And &H80000000<br style="padding: 0px; margin: 0px;"> lX4 = lX And &H40000000<br style="padding: 0px; margin: 0px;"> lY4 = lY And &H40000000<br style="padding: 0px; margin: 0px;"> lResult = (lX And &H3FFFFFFF) + (lY And &H3FFFFFFF)<br style="padding: 0px; margin: 0px;"> If lX4 And lY4 Then<br style="padding: 0px; margin: 0px;"> lResult = lResult Xor &H80000000 Xor lX8 Xor lY8<br style="padding: 0px; margin: 0px;"> ElseIf lX4 or lY4 Then<br style="padding: 0px; margin: 0px;"> If lResult And &H40000000 Then<br style="padding: 0px; margin: 0px;"> lResult = lResult Xor &HC0000000 Xor lX8 Xor lY8<br style="padding: 0px; margin: 0px;"> Else<br style="padding: 0px; margin: 0px;"> lResult = lResult Xor &H40000000 Xor lX8 Xor lY8<br style="padding: 0px; margin: 0px;"> End If<br style="padding: 0px; margin: 0px;"> Else<br style="padding: 0px; margin: 0px;"> lResult = lResult Xor lX8 Xor lY8<br style="padding: 0px; margin: 0px;"> End If<br style="padding: 0px; margin: 0px;"> SHA256_AddUnsigned = lResult<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> Private Function SHA256_CH(x, y, z)<br style="padding: 0px; margin: 0px;"> SHA256_Ch = ((x And y) Xor ((Not x) And z))<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> Private Function SHA256_Maj(x, y, z)<br style="padding: 0px; margin: 0px;"> SHA256_Maj = ((x And y) Xor (x And z) Xor (y And z))<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> Private Function SHA256_S(x, n)<br style="padding: 0px; margin: 0px;"> SHA256_S = (SHA256_RShift(x, (n And SHA256_m_lOnBits(4))) or SHA256_LShift(x, (32 - (n And SHA256_m_lOnBits(4)))))<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> Private Function SHA256_R(x, n)<br style="padding: 0px; margin: 0px;"> SHA256_R = SHA256_RShift(x, cLng(n And SHA256_m_lOnBits(4)))<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> Private Function SHA256_Sigma0(x)<br style="padding: 0px; margin: 0px;"> SHA256_Sigma0 = (SHA256_S(x, 2) Xor SHA256_S(x, 13) Xor SHA256_S(x, 22))<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> Private Function SHA256_Sigma1(x)<br style="padding: 0px; margin: 0px;"> SHA256_Sigma1 = (SHA256_S(x, 6) Xor SHA256_S(x, 11) Xor SHA256_S(x, 25))<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> Private Function SHA256_Gamma0(x)<br style="padding: 0px; margin: 0px;"> SHA256_Gamma0 = (SHA256_S(x, 7) Xor SHA256_S(x, 18) Xor SHA256_R(x, 3))<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> Private Function SHA256_Gamma1(x)<br style="padding: 0px; margin: 0px;"> SHA256_Gamma1 = (SHA256_S(x, 17) Xor SHA256_S(x, 19) Xor SHA256_R(x, 10))<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> Private Function SHA256_ConvertToWordArray(byVal sMessage)<br style="padding: 0px; margin: 0px;"> Dim lMessageLength<br style="padding: 0px; margin: 0px;"> Dim lNumberOfWords<br style="padding: 0px; margin: 0px;"> Dim lWordArray()<br style="padding: 0px; margin: 0px;"> Dim lBytePosition<br style="padding: 0px; margin: 0px;"> Dim lByteCount<br style="padding: 0px; margin: 0px;"> Dim lWordCount<br style="padding: 0px; margin: 0px;"> Dim lByte<br style="padding: 0px; margin: 0px;"> Const MODULUS_BITS = 512<br style="padding: 0px; margin: 0px;"> Const CONGRUENT_BITS = 448<br style="padding: 0px; margin: 0px;"> lMessageLength = Len(sMessage)<br style="padding: 0px; margin: 0px;"> lNumberOfWords = (((lMessageLength + ((MODULUS_BITS - CONGRUENT_BITS) \ BITS_TO_A_BYTE)) \ (MODULUS_BITS \ BITS_TO_A_BYTE)) + 1) * (MODULUS_BITS \ BITS_TO_A_WORD)<br style="padding: 0px; margin: 0px;"> ReDim lWordArray(lNumberOfWords - 1)<br style="padding: 0px; margin: 0px;"> lBytePosition = 0<br style="padding: 0px; margin: 0px;"> lByteCount = 0<br style="padding: 0px; margin: 0px;"> Do Until lByteCount >= lMessageLength<br style="padding: 0px; margin: 0px;"> lWordCount = lByteCount \ BYTES_TO_A_WORD<br style="padding: 0px; margin: 0px;"> lBytePosition = (3 - (lByteCount Mod BYTES_TO_A_WORD)) * BITS_TO_A_BYTE<br style="padding: 0px; margin: 0px;"> lByte = AscB(Mid(sMessage, lByteCount + 1, 1))<br style="padding: 0px; margin: 0px;"> lWordArray(lWordCount) = lWordArray(lWordCount) or SHA256_LShift(lByte, lBytePosition)<br style="padding: 0px; margin: 0px;"> lByteCount = lByteCount + 1<br style="padding: 0px; margin: 0px;"> Loop<br style="padding: 0px; margin: 0px;"> lWordCount = lByteCount \ BYTES_TO_A_WORD<br style="padding: 0px; margin: 0px;"> lBytePosition = (3 - (lByteCount Mod BYTES_TO_A_WORD)) * BITS_TO_A_BYTE<br style="padding: 0px; margin: 0px;"> lWordArray(lWordCount) = lWordArray(lWordCount) or SHA256_LShift(&H80, lBytePosition)<br style="padding: 0px; margin: 0px;"> lWordArray(lNumberOfWords - 1) = SHA256_LShift(lMessageLength, 3)<br style="padding: 0px; margin: 0px;"> lWordArray(lNumberOfWords - 2) = SHA256_RShift(lMessageLength, 29)<br style="padding: 0px; margin: 0px;"> SHA256_ConvertToWordArray = lWordArray<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> <br style="padding: 0px; margin: 0px;"> ' ==========================================================================================<br style="padding: 0px; margin: 0px;"> ' SHA256 加密算法<br style="padding: 0px; margin: 0px;"> ' ========================================================================================<br style="padding: 0px; margin: 0px;"> ' 调用方法:<br style="padding: 0px; margin: 0px;"> ' SHA256(sMessage, p_Len)<br style="padding: 0px; margin: 0px;"> ' p_Len控制生成字符串长度,1为8位,2为16位,最大取值为8,即加密后长度为64位<br style="padding: 0px; margin: 0px;"> ' 控制 8 位\16 位\24 位\32 位\40 位\48 位\56 位\64 位加密<br style="padding: 0px; margin: 0px;"> Public Function SHA256(byVal sMessage, byVal p_Len)<br style="padding: 0px; margin: 0px;"> Dim HASH(7)<br style="padding: 0px; margin: 0px;"> Dim M<br style="padding: 0px; margin: 0px;"> Dim W(63)<br style="padding: 0px; margin: 0px;"> Dim a<br style="padding: 0px; margin: 0px;"> Dim b<br style="padding: 0px; margin: 0px;"> Dim c<br style="padding: 0px; margin: 0px;"> Dim d<br style="padding: 0px; margin: 0px;"> Dim e<br style="padding: 0px; margin: 0px;"> Dim f<br style="padding: 0px; margin: 0px;"> Dim g<br style="padding: 0px; margin: 0px;"> Dim h<br style="padding: 0px; margin: 0px;"> Dim i<br style="padding: 0px; margin: 0px;"> Dim j<br style="padding: 0px; margin: 0px;"> Dim T1<br style="padding: 0px; margin: 0px;"> Dim T2<br style="padding: 0px; margin: 0px;"> HASH(0) = &H6A09E667<br style="padding: 0px; margin: 0px;"> HASH(1) = &HBB67AE85<br style="padding: 0px; margin: 0px;"> HASH(2) = &H3C6EF372<br style="padding: 0px; margin: 0px;"> HASH(3) = &HA54FF53A<br style="padding: 0px; margin: 0px;"> HASH(4) = &H510E527F<br style="padding: 0px; margin: 0px;"> HASH(5) = &H9B05688C<br style="padding: 0px; margin: 0px;"> HASH(6) = &H1F83D9AB<br style="padding: 0px; margin: 0px;"> HASH(7) = &H5BE0CD19<br style="padding: 0px; margin: 0px;"> M = SHA256_ConvertToWordArray(sMessage)<br style="padding: 0px; margin: 0px;"> For i = 0 To UBound(M) Step 16<br style="padding: 0px; margin: 0px;"> a = HASH(0)<br style="padding: 0px; margin: 0px;"> b = HASH(1)<br style="padding: 0px; margin: 0px;"> c = HASH(2)<br style="padding: 0px; margin: 0px;"> d = HASH(3)<br style="padding: 0px; margin: 0px;"> e = HASH(4)<br style="padding: 0px; margin: 0px;"> f = HASH(5)<br style="padding: 0px; margin: 0px;"> g = HASH(6)<br style="padding: 0px; margin: 0px;"> h = HASH(7)<br style="padding: 0px; margin: 0px;"> For j = 0 To 63<br style="padding: 0px; margin: 0px;"> If j < 16 Then<br style="padding: 0px; margin: 0px;"> W(j) = M(j + i)<br style="padding: 0px; margin: 0px;"> Else<br style="padding: 0px; margin: 0px;"> W(j) = SHA256_AddUnsigned(SHA256_AddUnsigned(SHA256_AddUnsigned(SHA256_Gamma1(W(j - 2)), W(j - 7)), SHA256_Gamma0(W(j - 15))), W(j - 16))<br style="padding: 0px; margin: 0px;"> End If<br style="padding: 0px; margin: 0px;"> T1 = SHA256_AddUnsigned(SHA256_AddUnsigned(SHA256_AddUnsigned(SHA256_AddUnsigned(h, SHA256_Sigma1(e)), SHA256_CH(e, f, g)), SHA256_K(j)), W(j))<br style="padding: 0px; margin: 0px;"> T2 = SHA256_AddUnsigned(SHA256_Sigma0(a), SHA256_Maj(a, b, c))<br style="padding: 0px; margin: 0px;"> h = g<br style="padding: 0px; margin: 0px;"> g = f<br style="padding: 0px; margin: 0px;"> f = e<br style="padding: 0px; margin: 0px;"> e = SHA256_AddUnsigned(d, T1)<br style="padding: 0px; margin: 0px;"> d = c<br style="padding: 0px; margin: 0px;"> c = b<br style="padding: 0px; margin: 0px;"> b = a<br style="padding: 0px; margin: 0px;"> a = SHA256_AddUnsigned(T1, T2)<br style="padding: 0px; margin: 0px;"> Next<br style="padding: 0px; margin: 0px;"> HASH(0) = SHA256_AddUnsigned(a, HASH(0))<br style="padding: 0px; margin: 0px;"> HASH(1) = SHA256_AddUnsigned(b, HASH(1))<br style="padding: 0px; margin: 0px;"> HASH(2) = SHA256_AddUnsigned(c, HASH(2))<br style="padding: 0px; margin: 0px;"> HASH(3) = SHA256_AddUnsigned(d, HASH(3))<br style="padding: 0px; margin: 0px;"> HASH(4) = SHA256_AddUnsigned(e, HASH(4))<br style="padding: 0px; margin: 0px;"> HASH(5) = SHA256_AddUnsigned(f, HASH(5))<br style="padding: 0px; margin: 0px;"> HASH(6) = SHA256_AddUnsigned(g, HASH(6))<br style="padding: 0px; margin: 0px;"> HASH(7) = SHA256_AddUnsigned(h, HASH(7))<br style="padding: 0px; margin: 0px;"> Next<br style="padding: 0px; margin: 0px;"> SHA256 = ""<br style="padding: 0px; margin: 0px;"> If p_Len >= 8 Then p_Len = 8<br style="padding: 0px; margin: 0px;"> If p_Len <= 0 Then p_Len = 2<br style="padding: 0px; margin: 0px;"> For i = 0 To p_Len - 1<br style="padding: 0px; margin: 0px;"> SHA256 = SHA256 & Right("00000000" & Hex(HASH(i)), 8)<br style="padding: 0px; margin: 0px;"> Next<br style="padding: 0px; margin: 0px;"> SHA256 = LCase(SHA256)<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> <br style="padding: 0px; margin: 0px;"> Public Function EncryptMode(ByVal p_String, ByVal p_Type)<br style="padding: 0px; margin: 0px;"> Dim E1s, E2s<br style="padding: 0px; margin: 0px;"> E1s = 16 ' 第一次或者MD5算法加密的长度 16位MD5 加密长度<br style="padding: 0px; margin: 0px;"> E2s = 2 ' 第二次或者SHA256算法加密的长度 2*8=16位SHA256 加密长度,最大加密长度为8*8=64位<br style="padding: 0px; margin: 0px;"> If Not IsNumeric(p_Type) Then<br style="padding: 0px; margin: 0px;"> p_Type = 1<br style="padding: 0px; margin: 0px;"> ElseIf p_Type > 7 or p_Type < 0 Then '判断方案数,根据p_Type最大值判断<br style="padding: 0px; margin: 0px;"> p_Type = 1<br style="padding: 0px; margin: 0px;"> End If<br style="padding: 0px; margin: 0px;"> If Not IsNumeric(E1s) Then<br style="padding: 0px; margin: 0px;"> E1s = 16<br style="padding: 0px; margin: 0px;"> ElseIf E1s <> 16 And E1s <> 32 Then<br style="padding: 0px; margin: 0px;"> E1s = 16<br style="padding: 0px; margin: 0px;"> End If<br style="padding: 0px; margin: 0px;"> If Not IsNumeric(E2s) Then<br style="padding: 0px; margin: 0px;"> E2s = 2<br style="padding: 0px; margin: 0px;"> ElseIf E2s > 8 or E2s < 0 Then<br style="padding: 0px; margin: 0px;"> E2s = 2<br style="padding: 0px; margin: 0px;"> End If<br style="padding: 0px; margin: 0px;"> ' ==========================================<br style="padding: 0px; margin: 0px;"> ' 初次布置使用的时候最好调整加密方案,现在最多8种方案<br style="padding: 0px; margin: 0px;"> ' 加密后字符串长度为16位,使用中可自行调整<br style="padding: 0px; margin: 0px;"> ' ==========================================<br style="padding: 0px; margin: 0px;"> Select Case p_Type<br style="padding: 0px; margin: 0px;"> Case 0 ' MD5 算法<br style="padding: 0px; margin: 0px;"> EncryptMode = MD5(p_String, E1s)<br style="padding: 0px; margin: 0px;"> Case 1 ' SHA256 算法<br style="padding: 0px; margin: 0px;"> EncryptMode = SHA256(p_String, E2s)<br style="padding: 0px; margin: 0px;"> Case 2 ' 先 MD5 后 SHA256<br style="padding: 0px; margin: 0px;"> EncryptMode = SHA256(MD5(p_String, E1s), E2s)<br style="padding: 0px; margin: 0px;"> Case 3 ' 先 SHA256 后 MD5<br style="padding: 0px; margin: 0px;"> EncryptMode = MD5(SHA256(p_String, E2s), E1s)<br style="padding: 0px; margin: 0px;"> Case 4 ' 两次MD5<br style="padding: 0px; margin: 0px;"> EncryptMode = MD5(MD5(p_String, E1s), E2s)<br style="padding: 0px; margin: 0px;"> Case 5 ' 两次SHA256<br style="padding: 0px; margin: 0px;"> EncryptMode = SHA256(SHA256(p_String, E1s), E2s)<br style="padding: 0px; margin: 0px;"> Case 6 ' 前8位 MD5 算法 后8位 SHA256 算法<br style="padding: 0px; margin: 0px;"> EncryptMode = Left(MD5(p_String, E1s), 8) & Right(SHA256(p_String, E2s), 8)<br style="padding: 0px; margin: 0px;"> Case 7 ' 前8位 SHA256 算法 后8位 MD5 算法<br style="padding: 0px; margin: 0px;"> EncryptMode = Left(SHA256(p_String, E2s), 8) & Right(MD5(p_String, E1s), 8)<br style="padding: 0px; margin: 0px;"> End Select<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> ' ============================================<br style="padding: 0px; margin: 0px;"> ' 全站密码类通用加密函数<br style="padding: 0px; margin: 0px;"> ' ============================================<br style="padding: 0px; margin: 0px;"> Public Function PassWordEnt(ByVal p_String)<br style="padding: 0px; margin: 0px;"> If p_String = "" or IsNull(p_String) Then p_String = 1<br style="padding: 0px; margin: 0px;"> ' 取密码最后一个字符的AscW值与8的余数作为加密方案系数<br style="padding: 0px; margin: 0px;"> PassWordEnt = EncryptMode(p_String, AscW(LCase(Right(p_String, 1))) Mod 8)<br style="padding: 0px; margin: 0px;"> End Function<br style="padding: 0px; margin: 0px;"> End Class<br style="padding: 0px; margin: 0px;"> %></div> <div style="text-align: left;"><br style="padding: 0px; margin: 0px; color: rgb(51, 51, 51); font-family: Arial, Tahoma, Verdana, sans-serif; font-size: 14px; line-height: 25px; background-color: rgb(247, 252, 255);"> <span style="color: rgb(51, 51, 51); font-family: Arial, Tahoma, Verdana, sans-serif; font-size: 14px; line-height: 25px; background-color: rgb(247, 252, 255);">演示:</span></div> <div class="codetitle" style="padding: 0px 3px; margin: 3px auto 0px; border-left-color: rgb(0, 153, 204); border-left-width: 1px; border-left-style: solid; width: 600px; background-color: rgb(242, 246, 251); clear: both; font-size: 14px; border-top-color: rgb(0, 153, 204); border-top-width: 1px; border-top-style: solid; border-right-color: rgb(0, 153, 204); border-right-width: 1px; border-right-style: solid; line-height: 25px; color: rgb(51, 51, 51); font-family: Arial, Tahoma, Verdana, sans-serif; text-align: left;"><span style="padding: 0px; margin: 0px; float: right; cursor: pointer;"><u style="padding: 0px; margin: 0px;">复制代码</u></span>代码如下:</div> <div class="codebody" id="code54627" style="padding: 0px 3px 0px 5px; margin: 0px auto 3px; border: 1px solid rgb(0, 153, 204); width: 598px; background-color: rgb(221, 237, 251); clear: both; font-size: 14px; line-height: 25px; color: rgb(51, 51, 51); font-family: Arial, Tahoma, Verdana, sans-serif; text-align: left;"><br style="padding: 0px; margin: 0px;"> <!--#include file="cls_Encrypt.asp"--><br style="padding: 0px; margin: 0px;"> <%<br style="padding: 0px; margin: 0px;"> Dim o<br style="padding: 0px; margin: 0px;"> Set o = new Cls_Encrypt<br style="padding: 0px; margin: 0px;"> Response.write "MD5算法:" & o.EncryptMode("admin",0) & ""<br style="padding: 0px; margin: 0px;"> Response.write "SHA256算法:" & o.EncryptMode("admin",1) & ""<br style="padding: 0px; margin: 0px;"> Response.write "先MD5后SHA256:" & o.EncryptMode("admin",2) & ""<br style="padding: 0px; margin: 0px;"> Response.write "先SHA256后MD5:" & o.EncryptMode("admin",3) & ""<br style="padding: 0px; margin: 0px;"> Response.write "两次MD5:" & o.EncryptMode("admin",4) & ""<br style="padding: 0px; margin: 0px;"> Response.write "两次SHA256:" & o.EncryptMode("admin",5) & ""<br style="padding: 0px; margin: 0px;"> Response.write "前8位MD5算法后8位SHA256算法:" & o.EncryptMode("admin",6) & ""<br style="padding: 0px; margin: 0px;"> Response.write "前8位SHA256算法后8位MD5算法:" & o.EncryptMode("admin",7) & "<hr />"<br style="padding: 0px; margin: 0px;"> Response.write "取密码最后一个字符的AscW值与8的余数作为加密方案系数:" & o.PassWordEnt("admin") & "<hr />"<br style="padding: 0px; margin: 0px;"> Response.write "16位MD5加密:" & o.md5("admin",16) & ""<br style="padding: 0px; margin: 0px;"> Response.write "32位MD5加密:" & o.md5("admin",32) & "<hr />"<br style="padding: 0px; margin: 0px;"> Response.write "8位SHA256加密:" & o.sha256("admin",1) & ""<br style="padding: 0px; margin: 0px;"> Response.write "16位SHA256加密:" & o.sha256("admin",2) & ""<br style="padding: 0px; margin: 0px;"> Response.write "24位SHA256加密:" & o.sha256("admin",3) & ""<br style="padding: 0px; margin: 0px;"> Response.write "32位SHA256加密:" & o.sha256("admin",4) & ""<br style="padding: 0px; margin: 0px;"> Response.write "40位SHA256加密:" & o.sha256("admin",5) & ""<br style="padding: 0px; margin: 0px;"> Response.write "48位SHA256加密:" & o.sha256("admin",6) & ""<br style="padding: 0px; margin: 0px;"> Response.write "56位SHA256加密:" & o.sha256("admin",7) & ""<br style="padding: 0px; margin: 0px;"> Response.write "64位SHA256加密:" & o.sha256("admin",8) & ""<br style="padding: 0px; margin: 0px;"> Set o = nothing<br style="padding: 0px; margin: 0px;"> %></div>
试试其它关键字
6多重加密
同语言下
.
二进制输出
.
查找text文本中指定字符或词所在句子
.
阻止浏览器冒泡事件,兼容firefox和ie
.
xmlhttp 读取文件
.
定时跳转页面
.
除asp中所有超链接
.
获取Session
.
打包时自定义应用程序的快捷方式与卸载
.
获取局域网中可用SQL Server服务器
.
判断汉字字数
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3