- Function DESEncrypt(ByVal Str,ByVal Key,ByVal Iv,ByVal Types)
- Dim UTF8,Enc,BytesText,Bytes,XML,Node,Outstr
- Set UTF8 = Server.CreateObject("System.Text.UTF8Encoding")
- Set Enc = Server.CreateObject("System.Security.Cryptography.DESCryptoServiceProvider")
- Enc.Mode = 1
- Enc.Padding = 2
- Enc.IV = UTF8.GetBytes_4(Iv)
- Enc.Key = UTF8.GetBytes_4(Key)
- BytesText = UTF8.GetBytes_4(Str)
- Bytes = Enc.CreateEncryptor().TransformFinalBlock((BytesText),0,Lenb(BytesText))
- If Types = "Base64" Then
- Set XML = Server.CreateObject("Msxml2.DOMDocument")
- Set Node = XML.CreateElement("TmpNode")
- Node.DataType = "bin.base64"
- Node.NodeTypedValue = Bytes
- Outstr = Replace(Node.Text,Chr(10),"")
- Set XML = Nothing
- Set Node = Nothing
- ElseIf Types = "Hex" Then
- Set XML = Server.CreateObject("Msxml2.DOMDocument")
- Set Node = XML.CreateElement("TmpNode")
- Node.DataType = "bin.hex"
- Node.NodeTypedValue = Bytes
- Outstr = Replace(Node.Text,Chr(10),"")
- Set XML = Nothing
- Set Node = Nothing
- End If
- DESEncrypt = Outstr
- Set Enc = Nothing
- Set UTF8 = Nothing
- End Function
- Function DESDecrypt(ByVal Str,ByVal Key,ByVal Iv,ByVal Types)
- Dim UTF8,Enc,BytesText,Bytes,XML,Node,Outstr
- Set UTF8 = Server.CreateObject("System.Text.UTF8Encoding")
- Set Enc = Server.CreateObject("System.Security.Cryptography.DESCryptoServiceProvider")
- Enc.Mode = 1
- Enc.Padding = 2
- Enc.IV = UTF8.GetBytes_4(Iv)
- Enc.Key = UTF8.GetBytes_4(Key)
- BytesText = Str
- If Types = "Base64" Then
- Set XML = Server.CreateObject("Msxml2.DOMDocument")
- Set Node = XML.CreateElement("TmpNode")
- Node.DataType = "bin.base64"
- Node.Text = BytesText
- Bytes = Node.NodeTypedValue
- Set XML = Nothing
- Set Node = Nothing
- ElseIf Types = "Hex" Then
- Set XML = Server.CreateObject("Msxml2.DOMDocument")
- Set Node = XML.CreateElement("TmpNode")
- Node.DataType = "bin.hex"
- Node.Text = BytesText
- Bytes = Node.NodeTypedValue
- Set XML = Nothing
- Set Node = Nothing
- End If
- Outstr = Enc.CreateDecryptor().TransformFinalBlock((Bytes),0,Lenb(Bytes))
- DESDecrypt = UTF8.GetString((Outstr))
- Set Enc = Nothing
- Set UTF8 = Nothing
- End Function
复制代码 |