相关疑难解决方法(0)

如何使用FromBase64String创建长度为16的byte []

我需要创建一个byte[]长度为16.(一个字节数组,有128位用作AES加密中的密钥).

以下是有效的字符串

"AAECAwQFBgcICQoLDA0ODw=="
Run Code Online (Sandbox Code Playgroud)

确定字符串是否为128位的算法是什么?或者是反复试验是创建这种128位字符串的唯一方法吗?

    static void Main(string[] args)
    {
        string firstString = "AAECAwQFBgcICQoLDA0ODw=="; //String Length = 24
        string secondString = "ABCDEFGHIJKLMNOPQRSTUVWX"; //String Length = 24
        int test = secondString.Length;

        byte[] firstByteArray = Convert.FromBase64String((firstString));
        byte[] secondByteArray = Convert.FromBase64String((secondString));

        int firstLength = firstByteArray.Length;
        int secondLength = secondByteArray.Length;


        Console.WriteLine("First Length: " + firstLength.ToString());
        Console.WriteLine("Second Length: " + secondLength.ToString());

        Console.ReadLine();
    }
Run Code Online (Sandbox Code Playgroud)

调查结果:

对于256位,我们需要256/6 = 42.66个字符.这四舍五入到43个字符.[使其可被4整除=]

对于512位,我们需要512/6 = 85.33个字符.这是四舍五入到86 char.[使其可被4整除==]

对于128位,我们需要128/6 = 21.33个字符.这被舍入到22个字符.[使其可被4整除==]

.net c# encryption base64 cryptography

3
推荐指数
1
解决办法
5044
查看次数

标签 统计

.net ×1

base64 ×1

c# ×1

cryptography ×1

encryption ×1