从Base64编码计算实际的数据大小连接codeD字符串长度 [英] Calculate actual data size from Base64 encoded string length

查看:510
本文介绍了从Base64编码计算实际的数据大小连接codeD字符串长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于数据连接codeD为Base64-CN codeD字符串,可我不知怎么计算的原始数据已通过查找了EN codeD的只有的实际长度在Base64编码恩codeD字符串的长度?

Given data encoded as a Base64-encoded string, can I somehow calculate the actual length of the raw data that has been encoded only by looking at the length of the Base64-encoded string?

我不想遍历字符串,如果没有必要的(这也包括在EN codeD字符串的字符trailling字符串操作来检查填充)。

I don't want to traverse the string if not necessary (this also includes string operations on the trailling characters of the encoded string to check for padding).

推荐答案

确切的长度不能,除非你看看填充计算。如果没有找填充,你能做的最好是由EN codeD-字符串长度乘以3/4(带连接codeD长度保证是由4整除)计算的上限长度

The exact length cannot be calculated unless you look at the padding. Without looking for padding, the best you can do is calculate an upper bound for the length by multiplying the encoded-string length with 3/4 (the encoded length is guaranteed to be exactly divisible by 4).

的上限计算从而将两种 N N + 1 ñ +2 ,其中 N 是原始数据的长度。

The upper bound calculated thus will be either N, N+1 or N+2, where N is the length of the raw data.

这篇关于从Base64编码计算实际的数据大小连接codeD字符串长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆