public unsafe void EncryptSessionKey(ref WritableBuffer writer, Span <byte> ticketContent) { var tagLength = 16; lock (_key) { var contentLength = ticketContent.Length + tagLength + sizeof(long) + sizeof(Guid); var nonce = System.Threading.Interlocked.Increment(ref _nounceCounter); writer.WriteBigEndian((ushort)contentLength); writer.Ensure(contentLength); _key.IV.Slice(4).Span.Write(nonce); _key.Init(KeyMode.Encryption); writer.WriteBigEndian(_keyGuid); writer.WriteBigEndian(_nounceCounter); var amountWritten = _key.Finish(ticketContent, writer.Buffer.Span); writer.Advance(amountWritten); _key.GetTag(writer.Buffer.Span.Slice(0, tagLength)); writer.Advance(tagLength); } }
protected void WriteTag(ref WritableBuffer writer) { writer.Ensure(_key.TagSize); _key.GetTag(writer.Buffer.Span.Slice(0, _key.TagSize)); writer.Advance(_key.TagSize); }