首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有Base64型十六进制的经典ASP

具有Base64型十六进制的经典ASP
EN

Stack Overflow用户
提问于 2020-12-04 20:16:58
回答 1查看 701关注 0票数 5

这个用sha256加密的代码

代码语言:javascript
复制
7353cf97ed9471d8b1ca180b6277f855f27214668d40d3b0134b8c91c8bb51a8

我用Base64编码时的结果

NzM1M2NmOTdlZDk0NzFkOGIxY2ExODBiNjI3N2Y4NTVmMjcyMTQ2NjhkNDBkM2IwMTM0YjhjOTFjOGJiNTFhOA==

但我想得到这样的结果。

代码语言:javascript
复制
c1PPl+2UcdixyhgLYnf4VfJyFGaNQNOwE0uMkci7Uag=

https://emn178.github.io/online-tools/base64_encode.html我可以在这个在线的转换器站点上得到这个结果。(您必须选择十六进制输入类型)

我使用的base64代码:

代码语言:javascript
复制
Function Base64Encode(sText)
    Dim oXML, oNode
    Set oXML = CreateObject("Msxml2.DOMDocument.3.0")
    Set oNode = oXML.CreateElement("base64")
    oNode.dataType = "bin.base64"
    oNode.nodeTypedValue = Stream_StringToBinary(sText)
    Base64Encode = oNode.text
    Set oNode = Nothing
    Set oXML = Nothing
End Function
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 = Stream_BinaryToString(oNode.nodeTypedValue)
    Set oNode = Nothing
    Set oXML = Nothing
End Function
Private Function Stream_StringToBinary(Text)
  Const adTypeText = 2
  Const adTypeBinary = 1
  Dim BinaryStream 'As New Stream
  Set BinaryStream = CreateObject("ADODB.Stream")
  BinaryStream.Type = adTypeText
  BinaryStream.CharSet = "us-ascii"
  BinaryStream.Open
  BinaryStream.WriteText Text
  BinaryStream.Position = 0
  BinaryStream.Type = adTypeBinary
  BinaryStream.Position = 0
  Stream_StringToBinary = BinaryStream.Read
  Set BinaryStream = Nothing
End Function
Private Function Stream_BinaryToString(Binary)
  Const adTypeText = 2
  Const adTypeBinary = 1
  Dim BinaryStream 'As New Stream
  Set BinaryStream = CreateObject("ADODB.Stream")
  BinaryStream.Type = adTypeBinary
  BinaryStream.Open
  BinaryStream.Write Binary
  BinaryStream.Position = 0
  BinaryStream.Type = adTypeText
  BinaryStream.CharSet = "us-ascii"
  Stream_BinaryToString = BinaryStream.ReadText
  Set BinaryStream = Nothing
End Function

如何处理经典的asp?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-05 02:16:54

您必须首先解码十六进制字符串。

获得相应的原始值后,可以将其转换为Base64字符串。

代码语言:javascript
复制
Function HexStringToBytes(hexString)
    With CreateObject("MSXML2.DOMDocument")
        .LoadXml "<node/>"
        With .DocumentElement
            .DataType = "bin.hex"
            .Text = hexString
            HexStringToBytes = .NodeTypedValue
        End With
    End With
End Function

Function BytesToBase64String(bytes)
    With CreateObject("MSXML2.DOMDocument")
        .LoadXml "<node/>"
        With .DocumentElement
            .DataType = "bin.base64"
            .NodeTypedValue = bytes
            BytesToBase64String = Replace(.Text, vbLf, "")
        End With
    End With
End Function

Function HexStringToBase64String(hexString)
    Dim bytes, base64string
    
    bytes = HexStringToBytes(hexString)
    base64string = BytesToBase64String(bytes)
    
    HexStringToBase64String = base64string
End Function

hexStr = "7353cf97ed9471d8b1ca180b6277f855f27214668d40d3b0134b8c91c8bb51a8"

base64str = HexStringToBase64String(hexStr)

'Response.Write(base64str) 'prints c1PPl+2UcdixyhgLYnf4VfJyFGaNQNOwE0uMkci7Uag=
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65150128

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档