{"action":"created","comment":{"url":"https://api.github.com/repos/CargoSense/ex_aws/pulls/comments/92181086","pull_request_review_id":12689857,"id":92181086,"diff_hunk":"@@ -0,0 +1,52 @@\n+defmodule ExAws.KMS.ClientEncryption.Result do\n+  @enforce_keys [:encrypted_data_key, :ciphertext]\n+  defstruct [:encrypted_data_key, :ciphertext]\n+end\n+\n+defmodule ExAws.KMS.ClientEncryption do\n+\n+  @doc \"Encrypts a map as json with a data key generated for the master key_id provided\"\n+  @spec encrypt(data :: Map.t(), key_id :: String.t()) :: ExAws.KMS.ClientEncryption.Result\n+  def encrypt_map(%{} = data, key_id) do\n+    config = ExAws.Config.new(:kms)\n+    json = config[:json_codec].encode!(data)\n+    encrypt(json, key_id)\n+  end\n+\n+  @doc \"Decrypts the result of a call to encrypt_map() (Note: keys will be strings)\"\n+  @spec decrypt(message :: ExAws.KMS.ClientEncryption.Result) :: Map.t()\n+  def decrypt_map(message) do\n+    plaintext = decrypt(message)\n+    config = ExAws.Config.new(:kms)\n+    {:ok, obj} = config[:json_codec].decode(plaintext)\n+    obj\n+  end\n+\n+  @doc \"Encrypts plaintext with a data key generated for the master key_id provided\"\n+  @spec encrypt(plaintext :: String.t(), key_id :: String.t()) :: ExAws.KMS.ClientEncryption.Result\n+  def encrypt(plaintext, key_id) do\n+    case  ExAws.KMS.generate_data_key(key_id, [{:key_spec, \"AES_256\"}]) |> ExAws.request do\n+      {:ok, %{\"CiphertextBlob\" => encrypted_data_key, \"KeyId\" => _, \"Plaintext\" => data_key}} ->\n+\n+\tiv    = :crypto.strong_rand_bytes(16)\n+\tstate = :crypto.stream_init(:aes_ctr, :base64.decode(data_key), iv)\n+\n+\t{_state, ciphertext} = :crypto.stream_encrypt(state, to_string(plaintext))\n+\t%ExAws.KMS.ClientEncryption.Result{encrypted_data_key: encrypted_data_key, ciphertext: :base64.encode(iv <> ciphertext)}","path":"lib/ex_aws/kms_client_encryption.ex","position":35,"original_position":35,"commit_id":"2a2609b5a1c0311f981a651f0f1a4aecd8275c94","original_commit_id":"2a2609b5a1c0311f981a651f0f1a4aecd8275c94","user":{"login":"benwilson512","id":247817,"avatar_url":"https://avatars.githubusercontent.com/u/247817?v=3","gravatar_id":"","url":"https://api.github.com/users/benwilson512","html_url":"https://github.com/benwilson512","followers_url":"https://api.github.com/users/benwilson512/followers","following_url":"https://api.github.com/users/benwilson512/following{/other_user}","gists_url":"https://api.github.com/users/benwilson512/gists{/gist_id}","starred_url":"https://api.github.com/users/benwilson512/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benwilson512/subscriptions","organizations_url":"https://api.github.com/users/benwilson512/orgs","repos_url":"https://api.github.com/users/benwilson512/repos","events_url":"https://api.github.com/users/benwilson512/events{/privacy}","received_events_url":"https://api.github.com/users/benwilson512/received_events","type":"User","site_admin":false},"body":"Also, is base64 encoding some kind of standard here or just a preference? Might someone choose base16 encoding?","created_at":"2016-12-13T14:40:35Z","updated_at":"2016-12-13T14:41:28Z","html_url":"https://github.com/CargoSense/ex_aws/pull/290#discussion_r92181086","pull_request_url":"https://api.github.com/repos/CargoSense/ex_aws/pulls/290","_links":{"self":{"href":"https://api.github.com/repos/CargoSense/ex_aws/pulls/comments/92181086"},"html":{"href":"https://github.com/CargoSense/ex_aws/pull/290#discussion_r92181086"},"pull_request":{"href":"https://api.github.com/repos/CargoSense/ex_aws/pulls/290"}}},"pull_request":{"url":"https://api.github.com/repos/CargoSense/ex_aws/pulls/290","id":95029942,"html_url":"https://github.com/CargoSense/ex_aws/pull/290","diff_url":"https://github.com/CargoSense/ex_aws/pull/290.diff","patch_url":"https://github.com/CargoSense/ex_aws/pull/290.patch","issue_url":"https://api.github.com/repos/CargoSense/ex_aws/issues/290","number":290,"state":"closed","locked":false,"title":"Added module for client side KMS encryption","user":{"login":"hamstah","id":188302,"avatar_url":"https://avatars.githubusercontent.com/u/188302?v=3","gravatar_id":"","url":"https://api.github.com/users/hamstah","html_url":"https://github.com/hamstah","followers_url":"https://api.github.com/users/hamstah/followers","following_url":"https://api.github.com/users/hamstah/following{/other_user}","gists_url":"https://api.github.com/users/hamstah/gists{/gist_id}","starred_url":"https://api.github.com/users/hamstah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hamstah/subscriptions","organizations_url":"https://api.github.com/users/hamstah/orgs","repos_url":"https://api.github.com/users/hamstah/repos","events_url":"https://api.github.com/users/hamstah/events{/privacy}","received_events_url":"https://api.github.com/users/hamstah/received_events","type":"User","site_admin":false},"body":"Hi\r\nThe new module makes it easy to use KMS for client side encryption/decryption\r\n\r\n```elixir\r\nmessage = \"waffles\"\r\nassert ExAws.KMS.ClientEncryption.encrypt(message, key_id) |> ExAws.KMS.ClientEncryption.decrypt == message\r\n```\r\n\r\nAny suggestion on how to write tests given the dependency on a valid master key?\r\n\r\nThanks\r\n","created_at":"2016-11-23T15:55:31Z","updated_at":"2016-12-13T14:41:28Z","closed_at":"2016-12-13T14:24:10Z","merged_at":"2016-12-13T14:24:10Z","merge_commit_sha":"081f29059aa0d8be01081946869b97725a18d2d9","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/CargoSense/ex_aws/pulls/290/commits","review_comments_url":"https://api.github.com/repos/CargoSense/ex_aws/pulls/290/comments","review_comment_url":"https://api.github.com/repos/CargoSense/ex_aws/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CargoSense/ex_aws/issues/290/comments","statuses_url":"https://api.github.com/repos/CargoSense/ex_aws/statuses/2a2609b5a1c0311f981a651f0f1a4aecd8275c94","head":{"label":"chingventures:client_side_kms","ref":"client_side_kms","sha":"2a2609b5a1c0311f981a651f0f1a4aecd8275c94","user":{"login":"chingventures","id":19295266,"avatar_url":"https://avatars.githubusercontent.com/u/19295266?v=3","gravatar_id":"","url":"https://api.github.com/users/chingventures","html_url":"https://github.com/chingventures","followers_url":"https://api.github.com/users/chingventures/followers","following_url":"https://api.github.com/users/chingventures/following{/other_user}","gists_url":"https://api.github.com/users/chingventures/gists{/gist_id}","starred_url":"https://api.github.com/users/chingventures/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chingventures/subscriptions","organizations_url":"https://api.github.com/users/chingventures/orgs","repos_url":"https://api.github.com/users/chingventures/repos","events_url":"https://api.github.com/users/chingventures/events{/privacy}","received_events_url":"https://api.github.com/users/chingventures/received_events","type":"Organization","site_admin":false},"repo":{"id":74564968,"name":"ex_aws","full_name":"chingventures/ex_aws","owner":{"login":"chingventures","id":19295266,"avatar_url":"https://avatars.githubusercontent.com/u/19295266?v=3","gravatar_id":"","url":"https://api.github.com/users/chingventures","html_url":"https://github.com/chingventures","followers_url":"https://api.github.com/users/chingventures/followers","following_url":"https://api.github.com/users/chingventures/following{/other_user}","gists_url":"https://api.github.com/users/chingventures/gists{/gist_id}","starred_url":"https://api.github.com/users/chingventures/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chingventures/subscriptions","organizations_url":"https://api.github.com/users/chingventures/orgs","repos_url":"https://api.github.com/users/chingventures/repos","events_url":"https://api.github.com/users/chingventures/events{/privacy}","received_events_url":"https://api.github.com/users/chingventures/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/chingventures/ex_aws","description":"A flexible, easy to use set of clients AWS APIs for Elixir","fork":true,"url":"https://api.github.com/repos/chingventures/ex_aws","forks_url":"https://api.github.com/repos/chingventures/ex_aws/forks","keys_url":"https://api.github.com/repos/chingventures/ex_aws/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chingventures/ex_aws/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chingventures/ex_aws/teams","hooks_url":"https://api.github.com/repos/chingventures/ex_aws/hooks","issue_events_url":"https://api.github.com/repos/chingventures/ex_aws/issues/events{/number}","events_url":"https://api.github.com/repos/chingventures/ex_aws/events","assignees_url":"https://api.github.com/repos/chingventures/ex_aws/assignees{/user}","branches_url":"https://api.github.com/repos/chingventures/ex_aws/branches{/branch}","tags_url":"https://api.github.com/repos/chingventures/ex_aws/tags","blobs_url":"https://api.github.com/repos/chingventures/ex_aws/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chingventures/ex_aws/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chingventures/ex_aws/git/refs{/sha}","trees_url":"https://api.github.com/repos/chingventures/ex_aws/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chingventures/ex_aws/statuses/{sha}","languages_url":"https://api.github.com/repos/chingventures/ex_aws/languages","stargazers_url":"https://api.github.com/repos/chingventures/ex_aws/stargazers","contributors_url":"https://api.github.com/repos/chingventures/ex_aws/contributors","subscribers_url":"https://api.github.com/repos/chingventures/ex_aws/subscribers","subscription_url":"https://api.github.com/repos/chingventures/ex_aws/subscription","commits_url":"https://api.github.com/repos/chingventures/ex_aws/commits{/sha}","git_commits_url":"https://api.github.com/repos/chingventures/ex_aws/git/commits{/sha}","comments_url":"https://api.github.com/repos/chingventures/ex_aws/comments{/number}","issue_comment_url":"https://api.github.com/repos/chingventures/ex_aws/issues/comments{/number}","contents_url":"https://api.github.com/repos/chingventures/ex_aws/contents/{+path}","compare_url":"https://api.github.com/repos/chingventures/ex_aws/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chingventures/ex_aws/merges","archive_url":"https://api.github.com/repos/chingventures/ex_aws/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chingventures/ex_aws/downloads","issues_url":"https://api.github.com/repos/chingventures/ex_aws/issues{/number}","pulls_url":"https://api.github.com/repos/chingventures/ex_aws/pulls{/number}","milestones_url":"https://api.github.com/repos/chingventures/ex_aws/milestones{/number}","notifications_url":"https://api.github.com/repos/chingventures/ex_aws/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chingventures/ex_aws/labels{/name}","releases_url":"https://api.github.com/repos/chingventures/ex_aws/releases{/id}","deployments_url":"https://api.github.com/repos/chingventures/ex_aws/deployments","created_at":"2016-11-23T10:15:09Z","updated_at":"2016-11-23T10:15:11Z","pushed_at":"2016-12-05T14:52:40Z","git_url":"git://github.com/chingventures/ex_aws.git","ssh_url":"git@github.com:chingventures/ex_aws.git","clone_url":"https://github.com/chingventures/ex_aws.git","svn_url":"https://github.com/chingventures/ex_aws","homepage":"https://hex.pm/packages/ex_aws","size":1057,"stargazers_count":0,"watchers_count":0,"language":"Elixir","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":"CargoSense:master","ref":"master","sha":"a13ce888b19713d8ed3cb77e9978a7803fd3bda4","user":{"login":"CargoSense","id":3963271,"avatar_url":"https://avatars.githubusercontent.com/u/3963271?v=3","gravatar_id":"","url":"https://api.github.com/users/CargoSense","html_url":"https://github.com/CargoSense","followers_url":"https://api.github.com/users/CargoSense/followers","following_url":"https://api.github.com/users/CargoSense/following{/other_user}","gists_url":"https://api.github.com/users/CargoSense/gists{/gist_id}","starred_url":"https://api.github.com/users/CargoSense/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CargoSense/subscriptions","organizations_url":"https://api.github.com/users/CargoSense/orgs","repos_url":"https://api.github.com/users/CargoSense/repos","events_url":"https://api.github.com/users/CargoSense/events{/privacy}","received_events_url":"https://api.github.com/users/CargoSense/received_events","type":"Organization","site_admin":false},"repo":{"id":24062989,"name":"ex_aws","full_name":"CargoSense/ex_aws","owner":{"login":"CargoSense","id":3963271,"avatar_url":"https://avatars.githubusercontent.com/u/3963271?v=3","gravatar_id":"","url":"https://api.github.com/users/CargoSense","html_url":"https://github.com/CargoSense","followers_url":"https://api.github.com/users/CargoSense/followers","following_url":"https://api.github.com/users/CargoSense/following{/other_user}","gists_url":"https://api.github.com/users/CargoSense/gists{/gist_id}","starred_url":"https://api.github.com/users/CargoSense/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CargoSense/subscriptions","organizations_url":"https://api.github.com/users/CargoSense/orgs","repos_url":"https://api.github.com/users/CargoSense/repos","events_url":"https://api.github.com/users/CargoSense/events{/privacy}","received_events_url":"https://api.github.com/users/CargoSense/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CargoSense/ex_aws","description":"A flexible, easy to use set of clients AWS APIs for Elixir","fork":false,"url":"https://api.github.com/repos/CargoSense/ex_aws","forks_url":"https://api.github.com/repos/CargoSense/ex_aws/forks","keys_url":"https://api.github.com/repos/CargoSense/ex_aws/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CargoSense/ex_aws/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CargoSense/ex_aws/teams","hooks_url":"https://api.github.com/repos/CargoSense/ex_aws/hooks","issue_events_url":"https://api.github.com/repos/CargoSense/ex_aws/issues/events{/number}","events_url":"https://api.github.com/repos/CargoSense/ex_aws/events","assignees_url":"https://api.github.com/repos/CargoSense/ex_aws/assignees{/user}","branches_url":"https://api.github.com/repos/CargoSense/ex_aws/branches{/branch}","tags_url":"https://api.github.com/repos/CargoSense/ex_aws/tags","blobs_url":"https://api.github.com/repos/CargoSense/ex_aws/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CargoSense/ex_aws/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CargoSense/ex_aws/git/refs{/sha}","trees_url":"https://api.github.com/repos/CargoSense/ex_aws/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CargoSense/ex_aws/statuses/{sha}","languages_url":"https://api.github.com/repos/CargoSense/ex_aws/languages","stargazers_url":"https://api.github.com/repos/CargoSense/ex_aws/stargazers","contributors_url":"https://api.github.com/repos/CargoSense/ex_aws/contributors","subscribers_url":"https://api.github.com/repos/CargoSense/ex_aws/subscribers","subscription_url":"https://api.github.com/repos/CargoSense/ex_aws/subscription","commits_url":"https://api.github.com/repos/CargoSense/ex_aws/commits{/sha}","git_commits_url":"https://api.github.com/repos/CargoSense/ex_aws/git/commits{/sha}","comments_url":"https://api.github.com/repos/CargoSense/ex_aws/comments{/number}","issue_comment_url":"https://api.github.com/repos/CargoSense/ex_aws/issues/comments{/number}","contents_url":"https://api.github.com/repos/CargoSense/ex_aws/contents/{+path}","compare_url":"https://api.github.com/repos/CargoSense/ex_aws/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CargoSense/ex_aws/merges","archive_url":"https://api.github.com/repos/CargoSense/ex_aws/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CargoSense/ex_aws/downloads","issues_url":"https://api.github.com/repos/CargoSense/ex_aws/issues{/number}","pulls_url":"https://api.github.com/repos/CargoSense/ex_aws/pulls{/number}","milestones_url":"https://api.github.com/repos/CargoSense/ex_aws/milestones{/number}","notifications_url":"https://api.github.com/repos/CargoSense/ex_aws/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CargoSense/ex_aws/labels{/name}","releases_url":"https://api.github.com/repos/CargoSense/ex_aws/releases{/id}","deployments_url":"https://api.github.com/repos/CargoSense/ex_aws/deployments","created_at":"2014-09-15T16:02:48Z","updated_at":"2016-12-12T23:59:30Z","pushed_at":"2016-12-13T14:32:51Z","git_url":"git://github.com/CargoSense/ex_aws.git","ssh_url":"git@github.com:CargoSense/ex_aws.git","clone_url":"https://github.com/CargoSense/ex_aws.git","svn_url":"https://github.com/CargoSense/ex_aws","homepage":"https://hex.pm/packages/ex_aws","size":1585,"stargazers_count":269,"watchers_count":269,"language":"Elixir","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":110,"mirror_url":null,"open_issues_count":12,"forks":110,"open_issues":12,"watchers":269,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/CargoSense/ex_aws/pulls/290"},"html":{"href":"https://github.com/CargoSense/ex_aws/pull/290"},"issue":{"href":"https://api.github.com/repos/CargoSense/ex_aws/issues/290"},"comments":{"href":"https://api.github.com/repos/CargoSense/ex_aws/issues/290/comments"},"review_comments":{"href":"https://api.github.com/repos/CargoSense/ex_aws/pulls/290/comments"},"review_comment":{"href":"https://api.github.com/repos/CargoSense/ex_aws/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CargoSense/ex_aws/pulls/290/commits"},"statuses":{"href":"https://api.github.com/repos/CargoSense/ex_aws/statuses/2a2609b5a1c0311f981a651f0f1a4aecd8275c94"}}}}
{"actor":{"display_login":"benwilson512"}}