Symmetrical encryption decryption module

xiaoxiao2021-03-06  59

Imports System.Text

Imports system.security.cryptography

Module Modsecurity

Function Entext (Byval TEXT AS STRING, BYVAL SKEY As String) AS String

Text = text.tolower

DIM DES AS New DescryptoServiceProvider

DIM INPUTBYTEARRAY () AS BYTE

INPUTBYTEARRAY = encoding.default.getbytes (text)

DES.KEY = asciiencoding.ascii.getbytes (left (System.Web.Security.FormSauthentication.HashPasswordforStoringInConfigfile (SKEY, "MD5"), 8))

DES.IV = asciiencoding.ascii.getbytes (Left (System.Web.Security.FormSauthentication.HashPasswordforStoringInconfigfile (SKEY, MD5 "), 8)

DIM MS as new system.io.MemoryStream

DIM CS AS New CryptostReam (MS, DES.CREATEENCRYPTOR, CRYPTOSTREAMMODE.WRITE)

CS.Write (InputByteArray, 0, InputByteaRray.Length)

cs.flushfinalblock ()

DIM RET AS New StringBuilder

DIM B AS BYTE

For Each B in ms.toarray ()

RET.APpendFormat ("{0: x2}", b)

NEXT

Return Ret.Tostring ()

END FUNCTION

Function Detext (Byval Text As String, Byval Skey As String) AS String

DIM DES AS New DescryptoServiceProvider

Dim Len As Integer

Len = text.length / 2 - 1

DIM INPUTBYTEARRAY (LEN) AS BYTE

DIM X, I as integer

For x = 0 to Len

I = Convert.Toint32 (Text.Substring (x * 2, 2), 16)

InputByteArray (x) = ctype (i, byte)

NEXT

DES.KEY = asciiencoding.ascii.getbytes (left (System.Web.Security.FormSauthentication.HashPasswordforStoringInConfigfile (SKEY, "MD5"), 8))

DES.IV = asciiencoding.ascii.getbytes (Left (System.Web.Security.FormSauthentication.HashPasswordforStoringInconfigfile (SKEY, MD5 "), 8)

DIM MS as new system.io.MemoryStream

DIM CS AS New CryptostReam (MS, DES.CREATEDECRYPTOR, CRYPTOSTREAMMODE.WRITE)

CS.Write (InputByteArray, 0, InputByteaRray.Length)

cs.flushfinalblock () return encoding.default.getstring (ms.toarray)

END FUNCTION

End module

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

New Post(0)