为什么Debian和AS400给出不同的base64编码字符串

Why Debian and AS400 are giving different base64 encoded strings?

本文关键字:base64 编码 编码字符 字符串 Debian AS400 为什么      更新时间:2023-10-16

我使用gSOAP来使用服务,并且我将基本身份验证字符串编码为两个不同的字符串,一个来自linux 32位,另一个来自AS400。代码是一样的。我想这可能是使用EBCDIC的AS400,但我将其转换为ASCII,它给出了相同的结果。有人遇到过同样的问题吗?

这是Linux编码字符串:

c2FudGFuZGVyY29uc3VtZXI6Z2Vyc29hMg==

这是AS400编码字符串:

ooGVo4GVhIWZg5aVoqSUhZl6h4WZopaB8g==

编码代码:

if (!t)
    t = (char*)soap_malloc(soap, output_length /*(n + 2) / 3 *
                                                * 4 + 1 */);
if (!t)
    return NULL;
p = t;
for (int i = 0, j = 0; i < input_length;) {
    uint32_t octet_a = i < input_length ? (unsigned char)s[i++] : 0;
    uint32_t octet_b = i < input_length ? (unsigned char)s[i++] : 0;
    uint32_t octet_c = i < input_length ? (unsigned char)s[i++] : 0;
    uint32_t triple = (octet_a << 0x10) + (octet_b << 0x08) + octet_c;
    t[j++] = encoding_table[(triple >> 3 * 6) & 0x3F];
    t[j++] = encoding_table[(triple >> 2 * 6) & 0x3F];
    t[j++] = encoding_table[(triple >> 1 * 6) & 0x3F];
    t[j++] = encoding_table[(triple >> 0 * 6) & 0x3F];
}
for (int i = 0; i < mod_table[input_length % 3]; i++)
    t[output_length - 1 - i] = '=';
t[output_length - mod_table[input_length % 3] + 2] = '';

来自Linux系统的代码运行良好。AS400不起作用。我猜这是一些AS400编码问题,但我不确定,我对AS400系统的访问有限,所以我不能追踪很多。

这是因为您正在转换一个字节序列,该字节序列表示用EBCDIC编码的文本。

第一个字符串是以下字节:

115,97,110,116,97,110,100,101,114,99,111,110,115,117,109,101,114,58,103,101,114,115,111,97,50

在ASCII中解码为santanderconsumer:gersoa2。顺便说一下,你现在必须更改密码。

第二个Base64字符串是以下字节:

162,129,149,163,129,149,132,133,153,131,150,149,162,164,148,133,153,122,135,133,153,162,150,129,242

检查https://en.wikipedia.org/wiki/EBCDIC上的EBCDIC表,可以看到这是同一个字符串。