任何人都可以告诉我如何解码经典ASP中的base64编码图像吗?该图像由Java org.apache base64类编码。 Java使用RFC 2045进行base64解码。
答案 0 :(得分:2)
<%
Set objXML = Server.CreateObject("MSXml2.DOMDocument")
Set objDocElem = objXML.createElement("Base64Data")
objDocElem.DataType = "bin.base64"
objDocElem.text = "/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAUD" 'encodedString
'Save to disk
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objStream.Write objDocElem.NodeTypedValue
objStream.SaveToFile "abc.jpg", 2
set objStream = Nothing
'Or send to browser
Response.ContentType = "image/jpeg"
Response.AddHeader "Content-Disposition", "attachment; filename=abc.jpg";
Response.BinaryWrite objDocElem.NodeTypedValue
Set objXML = Nothing
Set objDocElem = Nothing
%>
答案 1 :(得分:1)
您可以使用Capicom COM对象。我一直在使用它来反向(base64编码)。 这就是我要做的事情(如果你有一个大循环,你最好在循环外完成CreateObject,但在简单的情况下应该这样做):
Function Base64Decode(encodedString)
Dim caputil : Set caputil = CreateObject("CAPICOM.Utilities")
If len(encodedString) > 0 Then
Base64Decode = caputil.Base64Decode(encodedString)
Else
Base64Decode = ""
End If
Set caputil = Nothing
End Property
参考:http://msdn.microsoft.com/en-us/library/aa388176(v=vs.85).aspx
顺便说一下,可以从MS站点下载capicom.dll:http://www.microsoft.com/downloads/en/details.aspx?FamilyID=860ee43a-a843-462f-abb5-ff88ea5896f6