WB3*_*000 4 c# encryption bytearray aes
我目前有一个函数[C#],它接受一个byte []和一个对齐来设置它,但在加密过程中,每隔一段时间就抛出一个错误.
private byte[] AlignByteArray(byte[] content, int alignto)
{
long thelength = content.Length - 1;
long remainder = 1;
while (remainder != 0)
{
thelength += 1;
remainder = thelength % alignto;
}
Array.Resize(ref content, (int)thelength);
return content;
}
Run Code Online (Sandbox Code Playgroud)
有没有人看到该功能有任何问题?我收到的错误是AES加密期间内容大小无效,表明它没有正确填充.
pli*_*nth 10
这是一个简单的解决方案:
private static void PadToMultipleOf(ref byte[] src, int pad)
{
int len = (src.Length + pad - 1) / pad * pad;
Array.Resize(ref src, len);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7062 次 |
| 最近记录: |