{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/corefx/pulls/comments/41167902","id":41167902,"diff_hunk":"@@ -0,0 +1,48 @@\n+// Copyright (c) Microsoft. All rights reserved.\n+// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n+\n+using System;\n+using System.Collections.Generic;\n+using System.Globalization;\n+using System.Security.Cryptography;\n+\n+namespace Test.Cryptography\n+{\n+    internal static class CryptoUtils\n+    {\n+        internal static byte[] Encrypt(this SymmetricAlgorithm alg, byte[] plainText, int blockSizeMultipler = 1)\n+        {\n+            return alg.CreateEncryptor().Transform(plainText, blockSizeMultipler);\n+        }\n+\n+        internal static byte[] Decrypt(this SymmetricAlgorithm alg, byte[] cipher, int blockSizeMultipler = 1)\n+        {\n+            return alg.CreateDecryptor().Transform(cipher, blockSizeMultipler);\n+        }\n+\n+        internal static byte[] Transform(this ICryptoTransform transform, byte[] input, int blockSizeMultipler = 1)\n+        {\n+            List<byte> output = new List<byte>(input.Length);\n+            int blockSize = transform.InputBlockSize * blockSizeMultipler;\n+            for (int i = 0; i <= input.Length; i += blockSize)\n+            {\n+                int count = Math.Min(blockSize, input.Length - i);\n+                if (count >= blockSize)\n+                {\n+                    byte[] buffer = new byte[blockSize];\n+                    int numBytesWritten = transform.TransformBlock(input, i, count, buffer, 0);\n+                    Array.Resize(ref buffer, numBytesWritten);\n+                    output.AddRange(buffer);\n+                }\n+                else\n+                {\n+                    byte[] finalBlock = transform.TransformFinalBlock(input, i, count);","path":"src/Common/tests/Cryptography/CryptoUtils.cs","position":39,"original_position":39,"commit_id":"206ea57ff2d23d4ea0abbc9b23f2f96d26692779","original_commit_id":"c7f6f6c7c6313368a8275b4a9020bb4530561daf","user":{"login":"bartonjs","id":10642668,"avatar_url":"https://avatars.githubusercontent.com/u/10642668?v=3","gravatar_id":"","url":"https://api.github.com/users/bartonjs","html_url":"https://github.com/bartonjs","followers_url":"https://api.github.com/users/bartonjs/followers","following_url":"https://api.github.com/users/bartonjs/following{/other_user}","gists_url":"https://api.github.com/users/bartonjs/gists{/gist_id}","starred_url":"https://api.github.com/users/bartonjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bartonjs/subscriptions","organizations_url":"https://api.github.com/users/bartonjs/orgs","repos_url":"https://api.github.com/users/bartonjs/repos","events_url":"https://api.github.com/users/bartonjs/events{/privacy}","received_events_url":"https://api.github.com/users/bartonjs/received_events","type":"User","site_admin":false},"body":"I guess I don't understand what blockSizeMultiplier is supposed to be doing.\r\n\r\nTransform(\"hi\".ToBytes(), 10) is the same as Transform(\"hi\".ToBytes(), 1), in that both just call TransformFinalBlock.\r\n\r\nAnd since blocksize isn't decremented during looping, Transform(new byte[4096], 1) is just going to call TransformBlock over and over, but never TransformFinalBlock.","created_at":"2015-10-05T16:52:57Z","updated_at":"2015-10-05T16:52:57Z","html_url":"https://github.com/dotnet/corefx/pull/3640#discussion_r41167902","pull_request_url":"https://api.github.com/repos/dotnet/corefx/pulls/3640","_links":{"self":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/comments/41167902"},"html":{"href":"https://github.com/dotnet/corefx/pull/3640#discussion_r41167902"},"pull_request":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/3640"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/corefx/pulls/3640","id":46790032,"html_url":"https://github.com/dotnet/corefx/pull/3640","diff_url":"https://github.com/dotnet/corefx/pull/3640.diff","patch_url":"https://github.com/dotnet/corefx/pull/3640.patch","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/3640","number":3640,"state":"open","locked":false,"title":"Implement AesCng and TripleDESCng","user":{"login":"AtsushiKan","id":13223578,"avatar_url":"https://avatars.githubusercontent.com/u/13223578?v=3","gravatar_id":"","url":"https://api.github.com/users/AtsushiKan","html_url":"https://github.com/AtsushiKan","followers_url":"https://api.github.com/users/AtsushiKan/followers","following_url":"https://api.github.com/users/AtsushiKan/following{/other_user}","gists_url":"https://api.github.com/users/AtsushiKan/gists{/gist_id}","starred_url":"https://api.github.com/users/AtsushiKan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AtsushiKan/subscriptions","organizations_url":"https://api.github.com/users/AtsushiKan/orgs","repos_url":"https://api.github.com/users/AtsushiKan/repos","events_url":"https://api.github.com/users/AtsushiKan/events{/privacy}","received_events_url":"https://api.github.com/users/AtsushiKan/received_events","type":"User","site_admin":false},"body":"Implement AesCng and TripleDESCng.\r\n\r\nThis code is derived from the internal CNG-based Aes implementation in SSC.Algorithms\r\nbut the factoring has been redone so that the padding logic, cipher algorithm and the\r\nunderlying provider are now properly separated.\r\n\r\nUniversalCryptoEncryptor and UniversalCryptoDecryptor implement the public-facing\r\nICryptoTransform interface and do the padding/depadding.\r\n\r\nThey are parameterized by a BasicSymmetricCipher which implements the unpadded transform\r\nand encapsulates the cipher algorithm and underlying crypto technology (CNG or OpenSSL or\r\nwhatever.)\r\n\r\nBasicSymmetricCipherCng is the CNG-based implementation of that, and\r\nis parameterized by the algorithm (AES or 3DES.)\r\n\r\n(The existing Aes implementations in Algorithms could be rewritten in terms of these\r\nbut I'm not doing that now. We don't even know that we'll keep those inside\r\nSSC.Algorithms, in which case, redoing them would be throwaway work. I've put the agnostic\r\ncode in the Common folder just in case.)\r\n\r\nBeefed up the shared Aes tests with a few more code-coverage tests, but what's there\r\nseems pretty comprehensive already.\r\n\r\nTripleDES tests exercise the basic cipher. No need to do more code-coverage with these\r\nas AesCng and TripleDES are the virtually the same class on the managed side.\r\n\r\ncc @bartonjs \r\n","created_at":"2015-10-05T14:49:27Z","updated_at":"2015-10-05T16:52:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"df493dd2a2e3b8cc7d1549a861bc355a3924e5c9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/corefx/pulls/3640/commits","review_comments_url":"https://api.github.com/repos/dotnet/corefx/pulls/3640/comments","review_comment_url":"https://api.github.com/repos/dotnet/corefx/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/3640/comments","statuses_url":"https://api.github.com/repos/dotnet/corefx/statuses/206ea57ff2d23d4ea0abbc9b23f2f96d26692779","head":{"label":"AtsushiKan:scng","ref":"scng","sha":"206ea57ff2d23d4ea0abbc9b23f2f96d26692779","user":{"login":"AtsushiKan","id":13223578,"avatar_url":"https://avatars.githubusercontent.com/u/13223578?v=3","gravatar_id":"","url":"https://api.github.com/users/AtsushiKan","html_url":"https://github.com/AtsushiKan","followers_url":"https://api.github.com/users/AtsushiKan/followers","following_url":"https://api.github.com/users/AtsushiKan/following{/other_user}","gists_url":"https://api.github.com/users/AtsushiKan/gists{/gist_id}","starred_url":"https://api.github.com/users/AtsushiKan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AtsushiKan/subscriptions","organizations_url":"https://api.github.com/users/AtsushiKan/orgs","repos_url":"https://api.github.com/users/AtsushiKan/repos","events_url":"https://api.github.com/users/AtsushiKan/events{/privacy}","received_events_url":"https://api.github.com/users/AtsushiKan/received_events","type":"User","site_admin":false},"repo":{"id":38702362,"name":"corefx","full_name":"AtsushiKan/corefx","owner":{"login":"AtsushiKan","id":13223578,"avatar_url":"https://avatars.githubusercontent.com/u/13223578?v=3","gravatar_id":"","url":"https://api.github.com/users/AtsushiKan","html_url":"https://github.com/AtsushiKan","followers_url":"https://api.github.com/users/AtsushiKan/followers","following_url":"https://api.github.com/users/AtsushiKan/following{/other_user}","gists_url":"https://api.github.com/users/AtsushiKan/gists{/gist_id}","starred_url":"https://api.github.com/users/AtsushiKan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AtsushiKan/subscriptions","organizations_url":"https://api.github.com/users/AtsushiKan/orgs","repos_url":"https://api.github.com/users/AtsushiKan/repos","events_url":"https://api.github.com/users/AtsushiKan/events{/privacy}","received_events_url":"https://api.github.com/users/AtsushiKan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/AtsushiKan/corefx","description":"This repo contains the .NET Core foundational libraries, called CoreFX. It includes classes for collections, file systems, console, XML, async and many others.","fork":true,"url":"https://api.github.com/repos/AtsushiKan/corefx","forks_url":"https://api.github.com/repos/AtsushiKan/corefx/forks","keys_url":"https://api.github.com/repos/AtsushiKan/corefx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/AtsushiKan/corefx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/AtsushiKan/corefx/teams","hooks_url":"https://api.github.com/repos/AtsushiKan/corefx/hooks","issue_events_url":"https://api.github.com/repos/AtsushiKan/corefx/issues/events{/number}","events_url":"https://api.github.com/repos/AtsushiKan/corefx/events","assignees_url":"https://api.github.com/repos/AtsushiKan/corefx/assignees{/user}","branches_url":"https://api.github.com/repos/AtsushiKan/corefx/branches{/branch}","tags_url":"https://api.github.com/repos/AtsushiKan/corefx/tags","blobs_url":"https://api.github.com/repos/AtsushiKan/corefx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/AtsushiKan/corefx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/AtsushiKan/corefx/git/refs{/sha}","trees_url":"https://api.github.com/repos/AtsushiKan/corefx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/AtsushiKan/corefx/statuses/{sha}","languages_url":"https://api.github.com/repos/AtsushiKan/corefx/languages","stargazers_url":"https://api.github.com/repos/AtsushiKan/corefx/stargazers","contributors_url":"https://api.github.com/repos/AtsushiKan/corefx/contributors","subscribers_url":"https://api.github.com/repos/AtsushiKan/corefx/subscribers","subscription_url":"https://api.github.com/repos/AtsushiKan/corefx/subscription","commits_url":"https://api.github.com/repos/AtsushiKan/corefx/commits{/sha}","git_commits_url":"https://api.github.com/repos/AtsushiKan/corefx/git/commits{/sha}","comments_url":"https://api.github.com/repos/AtsushiKan/corefx/comments{/number}","issue_comment_url":"https://api.github.com/repos/AtsushiKan/corefx/issues/comments{/number}","contents_url":"https://api.github.com/repos/AtsushiKan/corefx/contents/{+path}","compare_url":"https://api.github.com/repos/AtsushiKan/corefx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/AtsushiKan/corefx/merges","archive_url":"https://api.github.com/repos/AtsushiKan/corefx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/AtsushiKan/corefx/downloads","issues_url":"https://api.github.com/repos/AtsushiKan/corefx/issues{/number}","pulls_url":"https://api.github.com/repos/AtsushiKan/corefx/pulls{/number}","milestones_url":"https://api.github.com/repos/AtsushiKan/corefx/milestones{/number}","notifications_url":"https://api.github.com/repos/AtsushiKan/corefx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/AtsushiKan/corefx/labels{/name}","releases_url":"https://api.github.com/repos/AtsushiKan/corefx/releases{/id}","created_at":"2015-07-07T17:03:52Z","updated_at":"2015-07-09T21:54:04Z","pushed_at":"2015-10-05T16:39:54Z","git_url":"git://github.com/AtsushiKan/corefx.git","ssh_url":"git@github.com:AtsushiKan/corefx.git","clone_url":"https://github.com/AtsushiKan/corefx.git","svn_url":"https://github.com/AtsushiKan/corefx","homepage":"http://dotnet.github.io/core/","size":34748,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dotnet:master","ref":"master","sha":"c02d33b18398199f6acc17d375dab154e9a1df66","user":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"repo":{"id":26295345,"name":"corefx","full_name":"dotnet/corefx","owner":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dotnet/corefx","description":"This repo contains the .NET Core foundational libraries, called CoreFX. It includes classes for collections, file systems, console, XML, async and many others.","fork":false,"url":"https://api.github.com/repos/dotnet/corefx","forks_url":"https://api.github.com/repos/dotnet/corefx/forks","keys_url":"https://api.github.com/repos/dotnet/corefx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/corefx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/corefx/teams","hooks_url":"https://api.github.com/repos/dotnet/corefx/hooks","issue_events_url":"https://api.github.com/repos/dotnet/corefx/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/corefx/events","assignees_url":"https://api.github.com/repos/dotnet/corefx/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/corefx/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/corefx/tags","blobs_url":"https://api.github.com/repos/dotnet/corefx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/corefx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/corefx/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/corefx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/corefx/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/corefx/languages","stargazers_url":"https://api.github.com/repos/dotnet/corefx/stargazers","contributors_url":"https://api.github.com/repos/dotnet/corefx/contributors","subscribers_url":"https://api.github.com/repos/dotnet/corefx/subscribers","subscription_url":"https://api.github.com/repos/dotnet/corefx/subscription","commits_url":"https://api.github.com/repos/dotnet/corefx/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/corefx/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/corefx/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/corefx/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/corefx/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/corefx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/corefx/merges","archive_url":"https://api.github.com/repos/dotnet/corefx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/corefx/downloads","issues_url":"https://api.github.com/repos/dotnet/corefx/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/corefx/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/corefx/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/corefx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/corefx/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/corefx/releases{/id}","created_at":"2014-11-06T23:42:48Z","updated_at":"2015-10-05T09:46:51Z","pushed_at":"2015-10-05T16:39:54Z","git_url":"git://github.com/dotnet/corefx.git","ssh_url":"git@github.com:dotnet/corefx.git","clone_url":"https://github.com/dotnet/corefx.git","svn_url":"https://github.com/dotnet/corefx","homepage":"http://dotnet.github.io/core/","size":75587,"stargazers_count":8419,"watchers_count":8419,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1833,"mirror_url":null,"open_issues_count":640,"forks":1833,"open_issues":640,"watchers":8419,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/3640"},"html":{"href":"https://github.com/dotnet/corefx/pull/3640"},"issue":{"href":"https://api.github.com/repos/dotnet/corefx/issues/3640"},"comments":{"href":"https://api.github.com/repos/dotnet/corefx/issues/3640/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/3640/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/3640/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/corefx/statuses/206ea57ff2d23d4ea0abbc9b23f2f96d26692779"}}}}