使用 BASE 64 在 c# 中编码文本,并在 vb6 中解码该文本使用 BASE64 解码

问题描述 投票:0回答:0

如何使用vb6 Base64解码解码回以下编码字符串? “QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODkrLyAg”到

请同时提供 VB6 中针对以下 vb6 函数的 Base64 解码功能以及 c# 中的 BASE64 解码功能。

Const sBASE_64_CHARACTERS="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Function Base64Encode(ByVal asContents)
    Dim lnPosition
    Dim lsResult
    Dim Char1
    Dim Char2
    Dim Char3
    Dim Char4
    Dim Byte1
    Dim Byte2
    Dim Byte3
    Dim SaveBits1
    Dim SaveBits2
    Dim lsGroupBinary
    Dim lsGroup64
    

    If Len(asContents) Mod 3 > 0 Then asContents = asContents & String(3 - (Len(asContents) Mod 3), " ")
    lsResult = ""

    For lnPosition = 1 To Len(asContents) Step 3
        lsGroup64 = ""
        lsGroupBinary = Mid(asContents, lnPosition, 3)

        Byte1 = Asc(Mid(lsGroupBinary, 1, 1)): SaveBits1 = Byte1 And 3
        Byte2 = Asc(Mid(lsGroupBinary, 2, 1)): SaveBits2 = Byte2 And 15
        Byte3 = Asc(Mid(lsGroupBinary, 3, 1))

        Char1 = Mid(sBASE_64_CHARACTERS, ((Byte1 And 252) \ 4) + 1, 1)
        Char2 = Mid(sBASE_64_CHARACTERS, (((Byte2 And 240) \ 16) Or (SaveBits1 * 16) And &HFF) + 1, 1)
        Char3 = Mid(sBASE_64_CHARACTERS, (((Byte3 And 192) \ 64) Or (SaveBits2 * 4) And &HFF) + 1, 1)
        Char4 = Mid(sBASE_64_CHARACTERS, (Byte3 And 63) + 1, 1)
        lsGroup64 = Char1 & Char2 & Char3 & Char4

        lsResult = lsResult + lsGroup64
    Next

    Base64Encode = lsResult
    
End Function

我只需要使用 vb6 和 c# 示例(如果可能)将给定编码值的解码结果解码回来。

c# encoding base64 vb6 decoding
© www.soinside.com 2019 - 2024. All rights reserved.