Exemplo n.º 1
0
    public void Test1()
    {
        const int DataN = 100;
        const int PassN = 80;

        var data = new byte[DataN];

        for (var i = 0; i < DataN; i++)
        {
            data[i] = (byte)i;
        }

        var pass = new string[PassN];
        var sb   = new StringBuilder();

        for (var i = 0; i < PassN; i++)
        {
            pass[i] = sb.ToString();
            sb.Append((char)('!' + i));
        }

        for (var i = 0; i < DataN; i++)
        {
            var dataSpan = data.AsSpan(0, i);
            for (var j = 0; j < PassN; j++)
            {
                var encrypted = PasswordEncrypt.Encrypt(dataSpan, pass[j]);
                PasswordEncrypt.TryDecrypt(encrypted, pass[j], out var decrypted).IsTrue();
                dataSpan.SequenceEqual(decrypted.Span).IsTrue();
            }
        }
    }