byte[] data = new byte[] { 65, 66, 67, 68 }; fixed (byte* pData = data) { // Access the first byte of data using pointer arithmetic byte* pByte = pData; Console.WriteLine(*pByte); // Output: 65 }
using System.Security.Cryptography; // Generate a random 32-byte key byte[] key = new byte[32]; using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider()) rng.GetBytes(key); // Encrypt data using AES symmetric encryption with CBC mode byte[] data = new byte[] { 65, 66, 67, 68 }; using (Aes aes = Aes.Create()) { aes.Key = key; aes.Mode = CipherMode.CBC; aes.Padding = PaddingMode.PKCS7; aes.GenerateIV(); using (ICryptoTransform encryptor = aes.CreateEncryptor()) { byte[] encrypted = new byte[data.Length]; fixed (byte* pData = data) fixed (byte* pEncrypted = encrypted) encryptor.TransformBlock(pData, 0, data.Length, pEncrypted, 0); } }This example shows how to use a byte* pointer to transform data using AES symmetric encryption. The `fixed` keyword is used to pin the data and encrypted arrays in memory while the pointer is being used by the `TransformBlock` method. Package/library: This code is part of the .NET Core runtime library and uses the `System.Security.Cryptography` namespace.