{"action":"created","issue":{"url":"https://api.github.com/repos/sdrapkin/SecurityDriven.Inferno/issues/8","repository_url":"https://api.github.com/repos/sdrapkin/SecurityDriven.Inferno","labels_url":"https://api.github.com/repos/sdrapkin/SecurityDriven.Inferno/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/sdrapkin/SecurityDriven.Inferno/issues/8/comments","events_url":"https://api.github.com/repos/sdrapkin/SecurityDriven.Inferno/issues/8/events","html_url":"https://github.com/sdrapkin/SecurityDriven.Inferno/issues/8","id":153220837,"number":8,"title":"How to add additional authenticated data to AEAD","user":{"login":"veikkoeeva","id":5158694,"avatar_url":"https://avatars.githubusercontent.com/u/5158694?v=3","gravatar_id":"","url":"https://api.github.com/users/veikkoeeva","html_url":"https://github.com/veikkoeeva","followers_url":"https://api.github.com/users/veikkoeeva/followers","following_url":"https://api.github.com/users/veikkoeeva/following{/other_user}","gists_url":"https://api.github.com/users/veikkoeeva/gists{/gist_id}","starred_url":"https://api.github.com/users/veikkoeeva/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/veikkoeeva/subscriptions","organizations_url":"https://api.github.com/users/veikkoeeva/orgs","repos_url":"https://api.github.com/users/veikkoeeva/repos","events_url":"https://api.github.com/users/veikkoeeva/events{/privacy}","received_events_url":"https://api.github.com/users/veikkoeeva/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-05-05T12:16:57Z","updated_at":"2016-05-05T15:44:15Z","closed_at":null,"body":"Hi!\r\n\r\nVery interesting library! I'm currently doing self-studies with cryptography and came across your clean looking library with clear principles listed. I'm not sure if this question belongs here or some other forum, such as Stackoverflow, but here goes.\r\n\r\nI'm currently learning AEAD with additional authenticated data, AAD, or AD, as mentioned also at [SecurityDriven.Inferno site](http://securitydriven.net/inferno/). It looks like something goes wrong, since in the following `aeadWithAad` is zero length. Moreover, I'm not exactly sure if the following is the right way to achieve storing authenticated metadata so that if the data is saved, based on the data I can use it to choose the right key to decrypt the contents, naturally first only checking the hash, preferably without first reading all the contents.\r\n\r\nI'm not sure if this questions belongs here or some other forum (Stackoverflow?). A bit premature perhaps, but do you accept PRs, say, for tests? If it makes sense, I can in time turn this question to a test.\r\n\r\n```\r\nusing SecurityDriven.Inferno;\r\nusing System;\r\nusing System.IO;\r\nusing System.Security.Cryptography;\r\nusing System.Text;\r\n\r\n\r\nnamespace Test\r\n{\r\n    public static class Program\r\n    {       \r\n        public static void Main()\r\n        {            \r\n            const string toBeEncrypted1 = \"ThisIsTheText1\";\r\n            const string toBeEncrypted2 = \"ThisIsTheText2\";\r\n\r\n            var aeadWithAad = Encrypt(toBeEncrypted1, ChooseKey(0), \"0|||\");\r\n            var aeadWithAadString = Convert.ToBase64String(aeadWithAad);\r\n\r\n            Console.WriteLine(aeadWithAadString);            \r\n        }\r\n\r\n\r\n        private static byte[] Encrypt(string contentsToBeEncrypted, string theEncryptionKey, string additionalAuthenticatedData)\r\n        {\r\n            using(var plainTextStream = new MemoryStream(Encoding.UTF8.GetBytes(contentsToBeEncrypted)))\r\n            {\r\n                plainTextStream.Seek(0, SeekOrigin.Begin);\r\n                using(var encryptedStream = new MemoryStream())\r\n                {\r\n                    var aadBytes = Encoding.UTF8.GetBytes(additionalAuthenticatedData);\r\n                    var aadData = new ArraySegment<byte>(aadBytes, 0, aadBytes.Length);\r\n                    using(var encTransform = new EtM_EncryptTransform(Encoding.UTF8.GetBytes(theEncryptionKey), aadData))\r\n                    {\r\n                        using(var cryptoStream = new CryptoStream(encryptedStream, encTransform, CryptoStreamMode.Write))\r\n                        {\r\n                            plainTextStream.CopyTo(cryptoStream);\r\n                            cryptoStream.Flush();\r\n                            encryptedStream.Flush();\r\n                            plainTextStream.Flush();\r\n                            return encryptedStream.ToArray();\r\n                        }\r\n                    }\r\n                }\r\n            }\r\n        }\r\n\r\n\r\n        private static string ChooseKey(int keyChooser)\r\n        {\r\n            const string theEncryptionKey1 = \"TheSecretEncryptionKey1\";\r\n            const string theEncryptionKey2 = \"TheSecretEncryptionKey2\";\r\n            const string theAuthenticationKey1 = \"TheSecretOrPublicAuthenticationKey1\";\r\n            const string theAuthenticationKey2 = \"TheSecretOrPublicAuthenticationKey2\";\r\n\r\n            if(keyChooser == 0)\r\n            {\r\n                return theAuthenticationKey1;    \r\n            }\r\n            else if(keyChooser == 1)\r\n            {\r\n                return theAuthenticationKey2;\r\n            }\r\n\r\n            throw new ArgumentOutOfRangeException(nameof(keyChooser));\r\n        }\r\n```"},"comment":{"url":"https://api.github.com/repos/sdrapkin/SecurityDriven.Inferno/issues/comments/217190436","html_url":"https://github.com/sdrapkin/SecurityDriven.Inferno/issues/8#issuecomment-217190436","issue_url":"https://api.github.com/repos/sdrapkin/SecurityDriven.Inferno/issues/8","id":217190436,"user":{"login":"veikkoeeva","id":5158694,"avatar_url":"https://avatars.githubusercontent.com/u/5158694?v=3","gravatar_id":"","url":"https://api.github.com/users/veikkoeeva","html_url":"https://github.com/veikkoeeva","followers_url":"https://api.github.com/users/veikkoeeva/followers","following_url":"https://api.github.com/users/veikkoeeva/following{/other_user}","gists_url":"https://api.github.com/users/veikkoeeva/gists{/gist_id}","starred_url":"https://api.github.com/users/veikkoeeva/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/veikkoeeva/subscriptions","organizations_url":"https://api.github.com/users/veikkoeeva/orgs","repos_url":"https://api.github.com/users/veikkoeeva/repos","events_url":"https://api.github.com/users/veikkoeeva/events{/privacy}","received_events_url":"https://api.github.com/users/veikkoeeva/received_events","type":"User","site_admin":false},"created_at":"2016-05-05T15:44:15Z","updated_at":"2016-05-05T15:44:15Z","body":"@sdrapkin Oh, you were quick! Thanks, it really helped! Heh, I fell for the old-fashioned one...\r\n\r\nCan I take your time a bit still and ask what would be the proper way to add plain-text, authenticated metadata? Now that I made some progress, it appears I have no success in adding that. For instance, that `0|||` would be `0x48 0x128 0x128 0x128`, but I don't see it anywhere in `aeadWithAad`. If one desires to do such a thing, should AEAD be constructred from the primitives?"}}