MD5加密算法的VB6.0類模塊實例_第1頁
MD5加密算法的VB6.0類模塊實例_第2頁
MD5加密算法的VB6.0類模塊實例_第3頁
MD5加密算法的VB6.0類模塊實例_第4頁
MD5加密算法的VB6.0類模塊實例_第5頁
已閱讀5頁,還剩7頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

MD5加密算法的VB6.0類模塊實例Form1窗體及代碼:OptionExplicitPrivateSubCommand1_Click()Dimc1AsNewClass1DimmAsStringText2.Text=c1.DigestStrToHexStr(Text1.Text)EndSubPrivateSubForm_Load()Text1.Text=""Text2.Text=""EndSub調(diào)用的類模塊代碼如下:OptionExplicitPrivateConstOFFSET_4=4294967296#PrivateConstMAXINT_4=2147483647PrivateConstS11=7PrivateConstS12=12PrivateConstS13=17PrivateConstS14=22PrivateConstS21=5PrivateConstS22=9PrivateConstS23=14PrivateConstS24=20PrivateConstS31=4PrivateConstS32=11PrivateConstS33=16PrivateConstS34=23PrivateConstS41=6PrivateConstS42=10PrivateConstS43=15PrivateConstS44=21'='=ClassVariables'=PrivatePrivateByteCounterAsLongPrivateByteBuffer(63)AsByte'='=ClassProperties'=PropertyGetRegisterA()AsStringRegisterA=State(1)EndPropertyPropertyGetRegisterB()AsStringRegisterB=State(2)EndPropertyPropertyGetRegisterC()AsStringRegisterC=State(3)EndPropertyPropertyGetRegisterD()AsStringRegisterD=State(4)EndProperty'='=ClassFunctions'=''Functiontoquicklydigestafileintoahexstring'PublicFunctionDigestFileToHexStr(FileNameAsString)AsStringOpenFileNameForBinaryAccessReadAs#1MD5InitDoWhileNotEOF(1)Get#1,,ByteBufferIfLoc(1)<LOF(1)ThenByteCounter=ByteCounter+64MD5TransformByteBufferEndIfLoopByteCounter=ByteCounter+(LOF(1)Mod64)Close#1MD5FinalDigestFileToHexStr=GetValuesEndFunction''Functiontodigestatextstringandoutputtheresultasastring'ofhexadecimalcharacters.'PublicFunctionDigestStrToHexStr(SourceStringAsString)AsStringMD5InitMD5UpdateLen(SourceString),StringToArray(SourceString)MD5FinalDigestStrToHexStr=GetValuesEndFunction''Autilityfunctionwhichconvertsastringintoanarrayof'bytes.'PrivateFunctionStringToArray(InStringAsString)AsByte()DimIAsIntegerDimbytBuffer()AsByteReDimbytBuffer(Len(InString))ForI=0ToLen(InString)-1bytBuffer(I)=Asc(Mid(InString,I+1,1))NextIStringToArray=bytBufferEndFunction''Concatenatethefourstatevaulesintoonestring'PublicFunctionGetValues()AsStringGetValues=LongToString(State(1))&LongToString(State(2))&LongToString(State(3))&LongToString(State(4))EndFunction''ConvertaLongtoaHexstring'PrivateFunctionLongToString(NumAsLong)AsStringDimaAsByteDimbAsByteDimcAsByteDimdAsBytea=NumAnd&HFF&Ifa<16ThenLongToString="0"&Hex(a)ElseLongToString=Hex(a)EndIfb=(NumAnd&HFF00&)\256Ifb<16ThenLongToString=LongToString&"0"&Hex(b)ElseLongToString=LongToString&Hex(b)EndIfc=(NumAnd&HFF0000)\65536Ifc<16ThenLongToString=LongToString&"0"&Hex(c)ElseLongToString=LongToString&Hex(c)EndIfIfNum<0Thend=((NumAnd&H7F000000)\16777216)Or&H80&Elsed=(NumAnd&HFF000000)\16777216EndIfIfd<16ThenLongToString=LongToString&"0"&Hex(d)ElseLongToString=LongToString&Hex(d)EndIfEndFunction''Initializetheclass'Thismustbecalledbeforeadigestcalculationisstarted'PublicSubMD5Init()ByteCounter=0State(1)=UnsignedToLong(1732584193#)State(2)=UnsignedToLong(4023233417#)State(3)=UnsignedToLong(2562383102#)State(4)=UnsignedToLong(271733878#)EndSub''MD5Final'PublicSubMD5Final()DimdblBitsAsDoubleDimpadding(72)AsByteDimlngBytesBufferedAsLongpadding(0)=&H80dblBits=ByteCounter*8'PadoutlngBytesBuffered=ByteCounterMod64IflngBytesBuffered<=56ThenMD5Update56-lngBytesBuffered,paddingElseMD5Update120-ByteCounter,paddingEndIfpadding(0)=UnsignedToLong(dblBits)And&HFF&padding(1)=UnsignedToLong(dblBits)\256And&HFF&padding(2)=UnsignedToLong(dblBits)\65536And&HFF&padding(3)=UnsignedToLong(dblBits)\16777216And&HFF&padding(4)=0padding(5)=0padding(6)=0padding(7)=0MD5Update8,paddingEndSub'Breakupinputstreaminto64bytechunks'PublicSubMD5Update(InputLenAsLong,InputBuffer()AsByte)DimIIAsIntegerDimIAsIntegerDimJAsIntegerDimKAsIntegerDimlngBufferedBytesAsLongDimlngBufferRemainingAsLongDimlngRemAsLonglngBufferedBytes=ByteCounterMod64lngBufferRemaining=64-lngBufferedBytesByteCounter=ByteCounter+InputLen'UseupoldbufferresultsfirstIfInputLen>=lngBufferRemainingThenForII=0TolngBufferRemaining-1ByteBuffer(lngBufferedBytes+II)=InputBuffer(II)NextIIMD5TransformByteBufferlngRem=(InputLen)Mod64'Thetransferisamultipleof64letsdosometransformationsForI=lngBufferRemainingToInputLen-II-lngRemStep64ForJ=0To63ByteBuffer(J)=InputBuffer(I+J)NextJMD5TransformByteBufferNextIlngBufferedBytes=0ElseI=0EndIf'BufferanyremaininginputForK=0ToInputLen-I-1ByteBuffer(lngBufferedBytes+K)=InputBuffer(I+K)NextKEndSub''MD5Transform'PrivateSubMD5Transform(Buffer()AsByte)Dimx(16)AsLongDimaAsLongDimbAsLongDimcAsLongDimdAsLonga=State(1)b=State(2)c=State(3)d=State(4)Decode64,x,Buffer'Round1FFa,b,c,d,x(0),S11,-680876936FFd,a,b,c,x(1),S12,-389564586FFc,d,a,b,x(2),S13,606105819FFb,c,d,a,x(3),S14,-1044525330FFa,b,c,d,x(4),S11,-176418897FFd,a,b,c,x(5),S12,1200080426FFc,d,a,b,x(6),S13,-1473231341FFb,c,d,a,x(7),S14,-45705983FFa,b,c,d,x(8),S11,1770035416FFd,a,b,c,x(9),S12,-1958414417FFc,d,a,b,x(10),S13,-42063FFb,c,d,a,x(11),S14,-1990404162FFa,b,c,d,x(12),S11,1804603682FFd,a,b,c,x(13),S12,-40341101FFc,d,a,b,x(14),S13,-1502002290FFb,c,d,a,x(15),S14,1236535329'Round2GGa,b,c,d,x(1),S21,-165796510GGd,a,b,c,x(6),S22,-1069501632GGc,d,a,b,x(11),S23,643717713GGb,c,d,a,x(0),S24,-373897302GGa,b,c,d,x(5),S21,-701558691GGd,a,b,c,x(10),S22,38016083GGc,d,a,b,x(15),S23,-660478335GGb,c,d,a,x(4),S24,-405537848GGa,b,c,d,x(9),S21,568446438GGd,a,b,c,x(14),S22,-1019803690GGc,d,a,b,x(3),S23,-187363961GGb,c,d,a,x(8),S24,1163531501GGa,b,c,d,x(13),S21,-1444681467GGd,a,b,c,x(2),S22,-51403784GGc,d,a,b,x(7),S23,1735328473GGb,c,d,a,x(12),S24,-1926607734'Round3HHa,b,c,d,x(5),S31,-378558HHd,a,b,c,x(8),S32,-2022574463HHc,d,a,b,x(11),S33,1839030562HHb,c,d,a,x(14),S34,-35309556HHa,b,c,d,x(1),S31,-1530992060HHd,a,b,c,x(4),S32,1272893353HHc,d,a,b,x(7),S33,-155497632HHb,c,d,a,x(10),S34,-1094730640HHa,b,c,d,x(13),S31,681279174HHd,a,b,c,x(0),S32,-358537222HHc,d,a,b,x(3),S33,-722521979HHb,c,d,a,x(6),S34,76029189HHa,b,c,d,x(9),S31,-640364487HHd,a,b,c,x(12),S32,-421815835HHc,d,a,b,x(15),S33,530742520HHb,c,d,a,x(2),S34,-995338651'Round4IIa,b,c,d,x(0),S41,-198630844IId,a,b,c,x(7),S42,1126891415IIc,d,a,b,x(14),S43,-1416354905IIb,c,d,a,x(5),S44,-57434055IIa,b,c,d,x(12),S41,1700485571IId,a,b,c,x(3),S42,-1894986606IIc,d,a,b,x(10),S43,-1051523IIb,c,d,a,x(1),S44,-2054922799IIa,b,c,d,x(8),S41,1873313359IId,a,b,c,x(15),S42,-30611744IIc,d,a,b,x(6),S43,-1560198380IIb,c,d,a,x(13),S44,1309151649IIa,b,c,d,x(4),S41,-145523070IId,a,b,c,x(11),S42,-1120210379IIc,d,a,b,x(2),S43,718787259IIb,c,d,a,x(9),S44,-343485551State(1)=LongOverflowAdd(State(1),a)State(2)=LongOverflowAdd(State(2),b)State(3)=LongOverflowAdd(State(3),c)State(4)=LongOverflowAdd(State(4),d)'/*Zeroizesensitiveinformation.'*/'MD5_memset((POINTER)x,0,sizeof(x));EndSubPrivateSubDecode(LengthAsInteger,OutputBuffer()AsLong,InputBuffer()AsByte)DimintDblIndexAsIntegerDimintByteIndexAsIntegerDimdblSumAsDoubleintDblIndex=0ForintByteIndex=0ToLength-1Step4dblSum=InputBuffer(intByteIndex)+_InputBuffer(intByteIndex+1)*256#+_InputBuffer(intByteIndex+2)*65536#+_InputBuffer(intByteIndex+3)*16777216#OutputBuffer(intDblIndex)=UnsignedToLong(dblSum)intDblIndex=intDblIndex+1NextintByteIndexEndSub''FF,GG,HH,andIItransformationsforrounds1,2,3,and4.'Rotationisseparatefromadditiontopreventrecomputation.'PrivateFunctionFF(aAsLong,_bAsLong,_cAsLong,_dAsLong,_xAsLong,_sAsLong,_acAsLong)AsLonga=LongOverflowAdd4(a,(bAndc)Or(Not(b)Andd),x,ac)a=LongLeftRotate(a,s)a=LongOverflowAdd(a,b)EndFunctionPrivateFunctionGG(aAsLong,_bAsLong,_cAsLong,_dAsLong,_xAsLong,_sAsLong,_acAsLong)AsLonga=LongOverflowAdd4(a,(bAndd)Or(cAndNot(d)),x,ac)a=LongLeftRotate(a,s)a=LongOverflowAdd(a,b)EndFunctionPrivateFunctionHH(aAsLong,_bAsLong,_cAsLong,_dAsLong,_xAsLong,_sAsLong,_acAsLong)AsLonga=LongOverflowAdd4(a,bXorcXord,x,ac)a=LongLeftRotate(a,s)a=LongOverflowAdd(a,b)EndFunctionPrivateFunctionII(aAsLong,_bAsLong,_cAsLong,_dAsLong,_xAsLong,_sAsLong,_acAsLong)AsLonga=LongOverflowAdd4(a,cXor(bOrNot(d)),x,ac)a=LongLeftRotate(a,s)a=LongOverflowAdd(a,b)EndFunction''Rotatealongtotheright'FunctionLongLeftRotate(valueAsLong,bitsAsLong)AsLongDimlngSignAsLongDimlngIAsLongbits=bitsMod32Ifbits=0ThenLongLeftRotate=value:ExitFunctionForlngI=1TobitslngSign=valueAnd&HC0000000value=(valueAnd&H3FFFFFFF)*2value=valueOr((lngSign<0)And1)Or(CBool(lngSignAnd_&H40000000)And&H80000000)NextLongLeftRotate=valueEndFunction''FunctiontoaddtwounsignednumberstogetherasinC.'Overflowsareignored!'PrivateFunctionLongOverflowAdd(Val1AsLong,Val2AsLong)AsLongDimlngHighWordAsLongDimlngLowWordAsLongDimlngOverflowAsLonglngLowWord=(Val1And&HFFFF&)+(Val2And&HFFFF&)lngOverflow=lngLowWord\65536lngHighWord=(((Val1And&HFFFF0000)\65536)+((Val2And&HFFFF0000)\65536)+lngOverflow)And&HFFFF&LongOverflowAdd=UnsignedToLong((lngHighWord*65536#)+(lngLow

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論