欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp base64编码中文

程序员文章站 2022-04-14 10:15:12
在网上找了很久,终于找到一个可以用的!   <%       function base64encode(sstring)    &...
在网上找了很久,终于找到一个可以用的!
 
<%
 
 
 
function base64encode(sstring)
 
    if sstring = "" or isnull(sstring) then
 
        base64encode = ""
 
        exit function
 
    end if
 
    dim xml_dom, node
 
    set xml_dom = createobject("microsoft.xmldom")
 
 
 
    with xml_dom
 
        .loadxml ("<?xml version='1.0' ?> <root/>")
 
        set node = xml_dom.createelement("mytext")
 
        with node
 
            .datatype = "bin.base64"
 
            .nodetypedvalue = gb2312_stream(sstring)
 
            base64encode = .text
 
        end with
 
        xml_dom.documentelement.appendchild node
 
    end with
 
    set xml_dom = nothing
 
end function
 
 
 
function base64uncode(sstring)
 
    if sstring = "" or isnull(sstring) then
 
        base64uncode = ""
 
        exit function
 
    end if
 
    dim xml_dom, node
 
    set xml_dom = createobject("microsoft.xmldom")
 
    with xml_dom
 
        .loadxml ("<?xml version='1.0' ?> <root/>")
 
        set node = xml_dom.createelement("mytext")
 
        with node
 
            .datatype = "bin.base64"
 
            .text = sstring
 
            base64uncode = stream_gb2312(.nodetypedvalue)
 
        end with
 
        xml_dom.documentelement.appendchild node
 
    end with
 
    set xml_dom = nothing
 
end function
 
 
 
function gb2312_stream(sstring)
 
 
 
    dim dr
 
    set dr = createobject("adodb.stream")
 
    with dr
 
        .mode = 3
 
        .type = 2
 
        .open
 
        .charset = "gb2312"
 
        .writetext sstring
 
        .position = 0
 
        .type = 1
 
        gb2312_stream = .read
 
        .close
 
    end with
 
    set dr = nothing www.2cto.com
 
end function
 
 
 
function stream_gb2312(sstream)
 
    dim dr
 
    set dr = createobject("adodb.stream")
 
    with dr
 
        .mode = 3
 
        .type = 1
 
        .open
 
        .write sstream
 
        .position = 0
 
        .type = 2
 
        .charset = "gb2312"
 
        stream_gb2312 = .readtext
 
        .close
 
    end with
 
    set dr = nothing
 
end function
 
%>