Пример #1
0
        public void MultipleEncrypt()
        {
            var aes_cbc_1 = AESUtils.Create();
            var aes_cfb_1 = AESUtils.Create(mode: CipherMode.CFB);
            var aes_cbc_2 = AESUtils.Create();

            var value = DateTime.Now.ToString() + " 🔮🎮";

            var bytes_1 = AESUtils.EncryptToByteArray(aes_cbc_1, value);
            var bytes_2 = AESUtils.Encrypt(aes_cfb_1, bytes_1);
            var bytes_3 = AESUtils.Encrypt(aes_cbc_2, bytes_2);
            var bytes_4 = bytes_3;

            var d_bytes_4 = bytes_4;

#pragma warning disable CA1416 // 验证平台兼容性
#if !ANDROID && !__ANDROID__ && !__MOBILE__
            if (DI.Platform == Platform.Windows)
            {
                bytes_4 = ProtectedData.Protect(bytes_3, null, DataProtectionScope.LocalMachine);

                d_bytes_4 = ProtectedData.Unprotect(bytes_4, null, DataProtectionScope.LocalMachine);
            }
#endif
#pragma warning restore CA1416 // 验证平台兼容性

            var d_bytes_3 = AESUtils.Decrypt(aes_cbc_2, d_bytes_4);
            var d_bytes_2 = AESUtils.Decrypt(aes_cfb_1, d_bytes_3);
            var d_value   = AESUtils.DecryptToString(aes_cbc_1, d_bytes_2);

            TestContext.WriteLine(d_value);
        }