ASP BASE64加密和解密- Function Base64Encode(ByVal Str)
- dim Xml, Stream, Node, Encode
- Set Xml = Server.CreateObject("Msxml2.DOMDocument")
- Set Stream = Server.CreateObject("ADODB.Stream")
- Set Node = Xml.CreateElement("TmpNode")
- Node.DataType = "bin.base64"
- Stream.Charset = "UTF-8"
- Stream.Type = 2
- Stream.Open()
- Stream.WriteText(Str)
- Stream.Position = 0
- Stream.Type = 1
- Node.NodeTypedValue = Stream.Read(-1)
- Stream.Close()
- Encode = Replace(Node.Text, Vblf, "")
- Encode = Replace(Encode, Vbcr, "")
- Base64Encode = Replace(Encode,"77u/","")
- Set Node = Nothing
- Set Stream = Nothing
- Set Xml = Nothing
- End Function
- Function Base64Decode(ByVal Str)
- Dim Val
- With Server.CreateObject("Msxml2.DOMDocument").CreateElement("TmpNode")
- .DataType = "bin.base64"
- .Text = Str
- Val = .NodeTypedValue
- End With
- With Server.CreateObject("ADODB.Stream")
- .Type = 1
- .Open
- .Write Val
- .Position = 0
- .Type = 2
- .Charset = "UTF-8"
- Base64Decode = .ReadText(-1)
- End With
- End Function
复制代码 |