Converting base64 string to byte array in classic

2019-09-12 08:51发布

问题:

I want to convert base 64 string to byte array in classic asp . The code to decode base 64 string to byte array is as follows :

Function Base64Decode(ByVal vCode)
        Dim oXML, oNode
        Set oXML = CreateObject("Msxml2.DOMDocument.3.0")
        Set oNode = oXML.CreateElement("base64")
        oNode.dataType = "bin.base64"
        oNode.text = vCode
        Base64Decode = oNode.nodeTypedValue
        Set oNode = Nothing
        Set oXML = Nothing
    End Function  

When I call this function with a small string , then this function works fine . But when I call this function with a large string like as the following :

Dim simpleString
 simpleString = "MjY1MDEgICAgICAgICAgIAUNAwMAVBIZPXd3d3d3d3d3d3d3d3d3d3d3d3d3d3cHADk6Ojo6 Ojh3d3d3d3d3dw8KATsAOzo5OTg4d3d3d3d3Dg0IAgEAOzo4Nzc4OHd3d3cODgwIBQQBOjk5 ODY2Nzd3d3cNDQwKCAcDADs6OTc1NjZ3d3cNDQwKCQcEAgA7Ozs4NTY5d3cODQ0KCQcFAgA7 AAA7OTg7d3cPDQwKCQcGAwEAAAAAADs6d3cODAsKCAcGBQIAAAABAgEAd3cODQwJCAcHBgQC AQECAQAAd3cNDQwJCQkIBgQCAQEBADs7d3cPDQ0MCQcFBQQCAAABADs6d3cQDQ0MCQcGBQQC ADs7Ozo4d3cODQsLCgkIBwUDADs5Ojo2d3cLDAwMCwoJCAYDADs6Ojo2d3cMCwwNDQwKCggF AgA7Ozo3d3cNDg4ODg4NCwkHBQI7Ojg3d3cODg4ODg4ODAoIBgM7OTc3d3cODw4NDg4ODg0K BwQ5NzQyd3cODw8QEBAQEA8MCAQ6NTIwd3cODxITFBUUEhIRDQk7NDIwd3cPERYXGBoZFxcX FRMxMjEtd3cRFBkbHB4eHh0dHR8nLS8ud3d3d3d3d3d3d3d3d3d3d3d3d0dcHUk0cmEXfDNP gB4PGR4RGQxpIhFiCUlobhpURScuTmh4gl4iJXSENBxtgDeFcnM/YGt8eW1lOCGGVywAAAAA AAAAAAAMFRweJi4ySFNaWmVtdnx+gomMk5egp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zIwLy0rd3d3d3d3dwQDADg1NDMxLy0rd3d3d3d3dwQCOzc1NDMx MC4sK3d3d3d3dwQBOjg2NDIyMC4sKnd3d3d3CQUCOzk2NDIyMC4tK3d3d3d3CggEADk2MzIy MC8vLCl3d3d3CwkGATg1MjEwMC8uKyh3d3d3DgsIAjk0MjAuLS0sKih3d3d3EQ8KAzgzMC4t KystLix3d3d3FBMPBTcxLi0sKystLit3d3d3GBcUCjcwLSsrLCwrKid3d3d3d3d3d3d3d3d3 d3d3d3d3d1FLWCNfSB5vc3RWdXcmK2BeIlVBcwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAABhY255f4KEhZKYnJ+lsba7dYWHiIoAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgwOCwICFxAPDwIQEBYJ Dw8MDg0QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="
  Base64Decode(simpleString)

Then I am getting this error :

500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.

Why am I getting this error ? How can I remove this error ? Please help me to remove this error .

回答1:

Please try the code below. It may help you convert base64string to byte array.

byte[] bytes = System.Convert.FromBase64String(simpleString);