Base64编码数据的最大大小 [英] Base64 encoded data maximum size

查看:1614
本文介绍了Base64编码数据的最大大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实现对称算法 RijndaelManaged 的安全机制.我设法通过 RijndaelManaged 针对特定IV找到了最大数据量.根据我的计算,它将是128个字节.但是,我需要使用Base64将这128个字节转换为字符串.有没有一种方法可以计算出Base64编码将用来编码大小为128的输入字节数组的最大字符数?

I have a security mechanism that implements symmetric algorithm RijndaelManaged. I managed to find information what is the maximum size of encrypted data using RijndaelManaged for particular IV. According to my calculations it will be 128 bytes. However I need to convert these 128 bytes to string using Base64. Is there a way to calculate maximum number of chars that Base64 encoding will use to encode input byte array of size 128?

谢谢,帕尔夫

推荐答案

绝对- Base64 需要每3个字节代表4个字符. (填充用于二进制数据,不是3字节的整数倍.)因此128字节将始终为172个字符. (解决此问题的方法是base64在每个字符中代表6位(2 6 = 64);因此3个字节= 24位= 4个base-64字符.)

Absolutely - Base64 takes 4 characters to represent every 3 bytes. (Padding is applied for binary data which isn't an exact multiple of 3 bytes.) So 128 bytes will always be 172 characters. (The way to work this out is that base64 represents 6 bits in each character (26 = 64); therefore 3 bytes = 24 bits = 4 base-64 characters.)

这篇关于Base64编码数据的最大大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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