Using the Windows Data Protection API, it is possible to encrypt data in memory, as the following code exemplifies:
byte[] toEncrypt = UnicodeEncoding.ASCII.GetBytes("ThisIsSomeData16");
Console.WriteLine("Original data: " + UnicodeEncoding.ASCII.GetString(toEncrypt));
Console.WriteLine("Encrypting...");
// Encrypt the data in memory.
EncryptInMemoryData(toEncrypt, MemoryProtectionScope.SameLogon);
Console.WriteLine("Encrypted data: " + UnicodeEncoding.ASCII.GetString(toEncrypt));
Console.WriteLine("Decrypting...");
// Decrypt the data in memory.
DecryptInMemoryData(toEncrypt, MemoryProtectionScope.SameLogon);
Console.WriteLine("Decrypted data: " + UnicodeEncoding.ASCII.GetString(toEncrypt));
See the Microsoft reference here: https://msdn.microsoft.com/en-us/library/ms995355.aspx
However, the encypted data in this example is of equal size as the original data. Is there a way to utilize the DPAPI to encrypt data without revealing the file size of the original file? For example, hiding the generated ciphertext at a "random" spot within the key as is possible with one time pads?