4using System.Threading.Tasks;
13 [CollectionName(
"AttachmentCache")]
15 [Index(
"AttachmentId")]
60 public long Size {
get;
set; }
65 public byte[]
Salt {
get;
set; }
75 using FileStream AttachmentFile = File.OpenRead(this.
FileName);
76 Aes Aes = Aes.Create();
80 Aes.Mode = CipherMode.CBC;
81 Aes.Padding = PaddingMode.Zeros;
83 byte[] Key =
new byte[32];
84 byte[] IV =
new byte[16];
86 Buffer.BlockCopy(this.
Salt, 0, Key, 0, 32);
87 Buffer.BlockCopy(this.
Salt, 32, IV, 0, 16);
89 using ICryptoTransform Decryptor = Aes.CreateDecryptor(Key, IV);
90 using CryptoStream DecryptedAttachmentFile =
new CryptoStream(AttachmentFile, Decryptor, CryptoStreamMode.Read);
92 if (this.
Size >
int.MaxValue)
93 throw new InvalidOperationException(
"Attachment size exceeds maximum array size.");
95 return await DecryptedAttachmentFile.ReadAllAsync((
int)this.
Size);
string ContentType
Internet Content-Type of attachment.
byte[] Salt
Salt used for encryption.
string LocalAttachmentId
If the attachment represents a local attachment, this property contains the Object ID of the attachme...
long Size
Attachment size.
string FileName
Local File name to encrypted file.
async Task< byte[]> LoadContent()
Loads the content of the attachment.
DateTime Created
When item was created (UTC).
string AttachmentId
Attachment ID
DateTime Expires
When item expires (UTC).
TypeNameSerialization
How the type name should be serialized.