28,391
社区成员
发帖
与我相关
我的任务
分享
<%
Dim privateKey,Text
privateKey = "12345678"
Text = "我是中国人"
Response.Write Encrypt(Text,privateKey)
'计算结果: xnygZZ+WkN4E25y9qpdfRA==
Function Encrypt(text,privateKey)
Dim pad,bytePad,bytetext,byteKey,byteResult,ObjXml
Set ObjXml = CreateObject("MSXML.DOMDocument").createElement("a")
With CreateObject("Adodb.Stream")
.Type = 2 : .Charset = "utf-8" : .Open
.WriteText text
.Position = 0 : .Type = 1 : .Position = .Size
pad = 8 - ( (.Size - 3) Mod 8)
With ObjXml
.dataType = "bin.hex"
.text = "80" & String( (pad-1) * 2, "0")
bytePad = .nodeTypedvalue
End With
.write bytePad : .Position = 3
bytetext = .Read()
.Position = 0 : .SetEOS : .Type = 2
.WriteText privateKey & String(8,Chr(0))
.Position = 0 : .Type = 1 : .Position = 3
byteKey = .Read(8)
.Close
End With
With CreateObject("System.Security.Cryptography.DESCryptoServiceProvider")
.Mode = 2 : .Padding = 3 : .IV = byteKey : .Key = byteKey
byteResult = .CreateEncryptor().TransformFinalBlock((bytetext),0,lenb(bytetext))
.Clear
End With
With ObjXml
.dataType = "bin.base64"
.nodeTypedvalue = byteResult
Encrypt = Replace(.text,chr(10),"")
End With
Set ObjXml = Nothing
End Function
%>