ASP encryption decryption class

xiaoxiao2021-04-05  232

<% rem ################################ r Encryption decryption Rem ##########################################################################################################################################################################################################################################################################################

REM implements encryption and decryption in ASP, encryption method: According to RSAREM Contact: hnsoso@sina.comclass CLSRSA

Public PrivateKeyPublic Public City

Public Function Crypt (pLngMessage, pLngKey) On Error Resume NextDim lLngModDim lLngResultDim lLngIndexIf pLngKey Mod 2 = 0 ThenlLngResult = 1For lLngIndex = 1 To pLngKey / 2lLngMod = (pLngMessage ^ 2) Mod Modulus' Mod may error on key generationlLngResult = (lLngMod * lLngResult ) Mod Modulus If Err Then Exit FunctionNextElselLngResult = pLngMessageFor lLngIndex = 1 To pLngKey / 2lLngMod = (pLngMessage ^ 2) Mod ModulusOn error Resume Next 'Mod may error on key generationlLngResult = (lLngMod * lLngResult) Mod ModulusIf Err Then Exit FunctionNextEnd IfCrypt = lLngResultEnd Function

Public Function Encode (ByVal pStrMessage) Dim lLngIndexDim lLngMaxIndexDim lBytAsciiDim lLngEncryptedlLngMaxIndex = Len (pStrMessage) If lLngMaxIndex = 0 Then Exit FunctionFor lLngIndex = 1 To lLngMaxIndexlBytAscii = Asc (Mid (pStrMessage, lLngIndex, 1)) lLngEncrypted = Crypt (lBytAscii, PublicKey) Encode = Encode & Numbertohex (LLNGENCRYPTED, 4) NEXTEND FUNCTION

Public Function Decode (ByVal pStrMessage) Dim lBytAsciiDim lLngIndexDim lLngMaxIndexDim lLngEncryptedDataDecode = "" lLngMaxIndex = Len (pStrMessage) For lLngIndex = 1 To lLngMaxIndex Step 4lLngEncryptedData = HexToNumber (Mid (pStrMessage, lLngIndex, 4)) lBytAscii = Crypt (lLngEncryptedData, PrivateKey) Decode = Decode & chr (lbytascii) NEXTEND FUNCTION

Private Function NumberToHex (ByRef pLngNumber, ByRef pLngLength) NumberToHex = Right (String (pLngLength, "0") & Hex (pLngNumber), pLngLength) End FunctionPrivate Function HexToNumber (ByRef pStrHex) HexToNumber = CLng ( "& h" & pStrHex) End Function

END CLASS%>

<% REM encryption call

Function Encryptstr (Message) Dim LngKeyedim LngKeyddim LngKeyndim StrMessagedim Objrsa

LngKeye = "32823" LNGKEYD = "20643" LNGKEYN = "29893" StrMessage = Message

Set Objrsa = New CLSRSA

Objrsa.publicKey = lngKeyeobjrsa.modulus = lngKeynencryptstr = objrsa.encode (strmessage) set objrsa = nothingend function

REM decryption call

Function Decryptstr (Message) Dim LngKeyedim LngKeyddim LngKeyndim StrMessageDim Objrsa

LngKeye = "32823" LNGKEYD = "20643" LNGKEYN = "29893" StrMessage = Message

Set Objrsa = New CLSRSA

Objrsa.privateKey = LNGKEYDOBJRSA.MODULULULUS = LNGKEYNDECRYPTSTR = Objrsa.decode (StrMessage) set objrsa = Nothingend Function

'DIM Last, first'first = "SOHU"' response.write "Before:" & dim'Last = EncryptStr (first) After encryption, "& Last'Response.Write" decrypted after "& Decryptstr Last)

%>

转载请注明原文地址:https://www.9cbs.com/read-132051.html

New Post(0)