{"action":"created","comment":{"url":"https://api.github.com/repos/ChengXiangLi/shadowmask/pulls/comments/80605492","pull_request_review_id":1652723,"id":80605492,"diff_hunk":"@@ -0,0 +1,134 @@\n+package org.shadowmask.core.mask.rules;\n+\n+import java.io.UnsupportedEncodingException;\n+import java.nio.charset.Charset;\n+import java.security.MessageDigest;\n+import java.security.NoSuchAlgorithmException;\n+import java.security.InvalidKeyException;\n+import java.security.InvalidAlgorithmParameterException;\n+import java.security.spec.InvalidKeySpecException;\n+import java.security.SecureRandom;\n+import java.util.Base64;\n+import javax.crypto.*;\n+import javax.crypto.spec.IvParameterSpec;\n+import javax.crypto.spec.SecretKeySpec;\n+\n+public class AESCipher extends CipherEngine {\n+    private static final int IV_LENGTH = 16;\n+    // private static SecureRandom rand = new SecureRandom();\n+    // private static byte[] seed = rand.generateSeed(IV_LENGTH);\n+    // private static KeyGenerator keygen_;\n+    // private static byte[] iv_ = new byte[IV_LENGTH];\n+    private SecretKeySpec skey_spec_;\n+    private static byte[] iv_ = \"odjyvjdhgksefncx\".getBytes();\n+    private static IvParameterSpec ivspec_ = new IvParameterSpec(iv_);\n+\n+    public AESCipher() {\n+        this.method = \"AES\";\n+    }\n+\n+    /*********\n+    static {\n+      try {\n+        keygen_ = KeyGenerator.getInstance(this.method);\n+\n+        keygen_.init(128);\n+        skey_ = keygen_.generateKey();\n+\n+        rand.setSeed(seed);\n+        rand.nextBytes(iv_);\n+        ivspec_ = new IvParameterSpec(iv_);\n+      } catch(NoSuchAlgorithmException e) {\n+        e.printStackTrace();\n+      }\n+    }\n+    ***********/\n+\n+    public String evaluate(String content, int mode, String key) {\n+      if (content == null) return null;\n+      if (key == null || key != null && (key.length() % 8) != 0) {\n+        throw new RuntimeException(\"Please input correct encrypting/decrypting key!\\n\" +\n+            \"Key length is the times of 8!\");\n+      }\n+      // validate key and geberate the secret key\n+      try {\n+        skey_spec_ = new SecretKeySpec(key.toString().getBytes(\"UTF-8\"), this.method);\n+      }catch(UnsupportedEncodingException e) {\n+        e.printStackTrace();\n+      }\n+\n+      String result = null;\n+      switch(mode) {\n+        case Cipher.ENCRYPT_MODE:\n+          result = encrypt(content.getBytes());\n+          System.out.println(\"Encrypted text is \" + result.toString());\n+          break;\n+        case Cipher.DECRYPT_MODE:\n+          result = decrypt(Base64.getDecoder().decode(content.toString()));\n+          System.out.println(\"Decrypted text is \" + result.toString());\n+          break;\n+        default:\n+          throw new RuntimeException(\"Unknown mode! [1: encryption, 2: decryption]\");\n+      }\n+      return result;\n+    }\n+\n+\n+    protected String encrypt(byte[] content) {\n+      String result = null;\n+      try {\n+        Cipher aesCipher = Cipher.getInstance(\"AES/CBC/PKCS5Padding\");\n+        aesCipher.init(Cipher.ENCRYPT_MODE, skey_spec_, ivspec_);\n+\n+        result = Base64.getEncoder().encodeToString(aesCipher.doFinal(content));\n+        return result;\n+      } catch(NoSuchAlgorithmException e) {\n+        e.printStackTrace();","path":"core/src/main/java/org/shadowmask/core/mask/rules/AESCipher.java","position":86,"original_position":86,"commit_id":"906fd46cdf340145ad8223036fb05099031cbb4e","original_commit_id":"906fd46cdf340145ad8223036fb05099031cbb4e","user":{"login":"ChengXiangLi","id":4425616,"avatar_url":"https://avatars.githubusercontent.com/u/4425616?v=3","gravatar_id":"","url":"https://api.github.com/users/ChengXiangLi","html_url":"https://github.com/ChengXiangLi","followers_url":"https://api.github.com/users/ChengXiangLi/followers","following_url":"https://api.github.com/users/ChengXiangLi/following{/other_user}","gists_url":"https://api.github.com/users/ChengXiangLi/gists{/gist_id}","starred_url":"https://api.github.com/users/ChengXiangLi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChengXiangLi/subscriptions","organizations_url":"https://api.github.com/users/ChengXiangLi/orgs","repos_url":"https://api.github.com/users/ChengXiangLi/repos","events_url":"https://api.github.com/users/ChengXiangLi/events{/privacy}","received_events_url":"https://api.github.com/users/ChengXiangLi/received_events","type":"User","site_admin":false},"body":"1. should we throw the exception instead of just returning null here?\r\n2. we should log the error message instead of printing it.","created_at":"2016-09-27T01:07:29Z","updated_at":"2016-09-27T01:07:29Z","html_url":"https://github.com/ChengXiangLi/shadowmask/pull/4#discussion_r80605492","pull_request_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/ChengXiangLi/shadowmask/pulls/comments/80605492"},"html":{"href":"https://github.com/ChengXiangLi/shadowmask/pull/4#discussion_r80605492"},"pull_request":{"href":"https://api.github.com/repos/ChengXiangLi/shadowmask/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/ChengXiangLi/shadowmask/pulls/4","id":86727813,"html_url":"https://github.com/ChengXiangLi/shadowmask/pull/4","diff_url":"https://github.com/ChengXiangLi/shadowmask/pull/4.diff","patch_url":"https://github.com/ChengXiangLi/shadowmask/pull/4.patch","issue_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/issues/4","number":4,"state":"open","locked":false,"title":"Hive engine","user":{"login":"timmyyao","id":20180459,"avatar_url":"https://avatars.githubusercontent.com/u/20180459?v=3","gravatar_id":"","url":"https://api.github.com/users/timmyyao","html_url":"https://github.com/timmyyao","followers_url":"https://api.github.com/users/timmyyao/followers","following_url":"https://api.github.com/users/timmyyao/following{/other_user}","gists_url":"https://api.github.com/users/timmyyao/gists{/gist_id}","starred_url":"https://api.github.com/users/timmyyao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timmyyao/subscriptions","organizations_url":"https://api.github.com/users/timmyyao/orgs","repos_url":"https://api.github.com/users/timmyyao/repos","events_url":"https://api.github.com/users/timmyyao/events{/privacy}","received_events_url":"https://api.github.com/users/timmyyao/received_events","type":"User","site_admin":false},"body":"The code split of hive-engine part has been completed.","created_at":"2016-09-26T11:51:00Z","updated_at":"2016-09-27T01:07:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"eabf4897fa0e70bbba3a355ad1ed945d161646a2","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/pulls/4/commits","review_comments_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/pulls/4/comments","review_comment_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/issues/4/comments","statuses_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/statuses/906fd46cdf340145ad8223036fb05099031cbb4e","head":{"label":"timmyyao:hive-engine","ref":"hive-engine","sha":"906fd46cdf340145ad8223036fb05099031cbb4e","user":{"login":"timmyyao","id":20180459,"avatar_url":"https://avatars.githubusercontent.com/u/20180459?v=3","gravatar_id":"","url":"https://api.github.com/users/timmyyao","html_url":"https://github.com/timmyyao","followers_url":"https://api.github.com/users/timmyyao/followers","following_url":"https://api.github.com/users/timmyyao/following{/other_user}","gists_url":"https://api.github.com/users/timmyyao/gists{/gist_id}","starred_url":"https://api.github.com/users/timmyyao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timmyyao/subscriptions","organizations_url":"https://api.github.com/users/timmyyao/orgs","repos_url":"https://api.github.com/users/timmyyao/repos","events_url":"https://api.github.com/users/timmyyao/events{/privacy}","received_events_url":"https://api.github.com/users/timmyyao/received_events","type":"User","site_admin":false},"repo":{"id":68579847,"name":"shadowmask","full_name":"timmyyao/shadowmask","owner":{"login":"timmyyao","id":20180459,"avatar_url":"https://avatars.githubusercontent.com/u/20180459?v=3","gravatar_id":"","url":"https://api.github.com/users/timmyyao","html_url":"https://github.com/timmyyao","followers_url":"https://api.github.com/users/timmyyao/followers","following_url":"https://api.github.com/users/timmyyao/following{/other_user}","gists_url":"https://api.github.com/users/timmyyao/gists{/gist_id}","starred_url":"https://api.github.com/users/timmyyao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timmyyao/subscriptions","organizations_url":"https://api.github.com/users/timmyyao/orgs","repos_url":"https://api.github.com/users/timmyyao/repos","events_url":"https://api.github.com/users/timmyyao/events{/privacy}","received_events_url":"https://api.github.com/users/timmyyao/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/timmyyao/shadowmask","description":"Shadowmask is an open source project for data anonymation of big data.","fork":true,"url":"https://api.github.com/repos/timmyyao/shadowmask","forks_url":"https://api.github.com/repos/timmyyao/shadowmask/forks","keys_url":"https://api.github.com/repos/timmyyao/shadowmask/keys{/key_id}","collaborators_url":"https://api.github.com/repos/timmyyao/shadowmask/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/timmyyao/shadowmask/teams","hooks_url":"https://api.github.com/repos/timmyyao/shadowmask/hooks","issue_events_url":"https://api.github.com/repos/timmyyao/shadowmask/issues/events{/number}","events_url":"https://api.github.com/repos/timmyyao/shadowmask/events","assignees_url":"https://api.github.com/repos/timmyyao/shadowmask/assignees{/user}","branches_url":"https://api.github.com/repos/timmyyao/shadowmask/branches{/branch}","tags_url":"https://api.github.com/repos/timmyyao/shadowmask/tags","blobs_url":"https://api.github.com/repos/timmyyao/shadowmask/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/timmyyao/shadowmask/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/timmyyao/shadowmask/git/refs{/sha}","trees_url":"https://api.github.com/repos/timmyyao/shadowmask/git/trees{/sha}","statuses_url":"https://api.github.com/repos/timmyyao/shadowmask/statuses/{sha}","languages_url":"https://api.github.com/repos/timmyyao/shadowmask/languages","stargazers_url":"https://api.github.com/repos/timmyyao/shadowmask/stargazers","contributors_url":"https://api.github.com/repos/timmyyao/shadowmask/contributors","subscribers_url":"https://api.github.com/repos/timmyyao/shadowmask/subscribers","subscription_url":"https://api.github.com/repos/timmyyao/shadowmask/subscription","commits_url":"https://api.github.com/repos/timmyyao/shadowmask/commits{/sha}","git_commits_url":"https://api.github.com/repos/timmyyao/shadowmask/git/commits{/sha}","comments_url":"https://api.github.com/repos/timmyyao/shadowmask/comments{/number}","issue_comment_url":"https://api.github.com/repos/timmyyao/shadowmask/issues/comments{/number}","contents_url":"https://api.github.com/repos/timmyyao/shadowmask/contents/{+path}","compare_url":"https://api.github.com/repos/timmyyao/shadowmask/compare/{base}...{head}","merges_url":"https://api.github.com/repos/timmyyao/shadowmask/merges","archive_url":"https://api.github.com/repos/timmyyao/shadowmask/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/timmyyao/shadowmask/downloads","issues_url":"https://api.github.com/repos/timmyyao/shadowmask/issues{/number}","pulls_url":"https://api.github.com/repos/timmyyao/shadowmask/pulls{/number}","milestones_url":"https://api.github.com/repos/timmyyao/shadowmask/milestones{/number}","notifications_url":"https://api.github.com/repos/timmyyao/shadowmask/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/timmyyao/shadowmask/labels{/name}","releases_url":"https://api.github.com/repos/timmyyao/shadowmask/releases{/id}","deployments_url":"https://api.github.com/repos/timmyyao/shadowmask/deployments","created_at":"2016-09-19T07:22:07Z","updated_at":"2016-09-19T07:22:08Z","pushed_at":"2016-09-26T11:47:03Z","git_url":"git://github.com/timmyyao/shadowmask.git","ssh_url":"git@github.com:timmyyao/shadowmask.git","clone_url":"https://github.com/timmyyao/shadowmask.git","svn_url":"https://github.com/timmyyao/shadowmask","homepage":null,"size":59,"stargazers_count":0,"watchers_count":0,"language":"Java","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":"ChengXiangLi:master","ref":"master","sha":"ca9803e3017eeadc4e26cd5355789ed227fdf03d","user":{"login":"ChengXiangLi","id":4425616,"avatar_url":"https://avatars.githubusercontent.com/u/4425616?v=3","gravatar_id":"","url":"https://api.github.com/users/ChengXiangLi","html_url":"https://github.com/ChengXiangLi","followers_url":"https://api.github.com/users/ChengXiangLi/followers","following_url":"https://api.github.com/users/ChengXiangLi/following{/other_user}","gists_url":"https://api.github.com/users/ChengXiangLi/gists{/gist_id}","starred_url":"https://api.github.com/users/ChengXiangLi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChengXiangLi/subscriptions","organizations_url":"https://api.github.com/users/ChengXiangLi/orgs","repos_url":"https://api.github.com/users/ChengXiangLi/repos","events_url":"https://api.github.com/users/ChengXiangLi/events{/privacy}","received_events_url":"https://api.github.com/users/ChengXiangLi/received_events","type":"User","site_admin":false},"repo":{"id":68568558,"name":"shadowmask","full_name":"ChengXiangLi/shadowmask","owner":{"login":"ChengXiangLi","id":4425616,"avatar_url":"https://avatars.githubusercontent.com/u/4425616?v=3","gravatar_id":"","url":"https://api.github.com/users/ChengXiangLi","html_url":"https://github.com/ChengXiangLi","followers_url":"https://api.github.com/users/ChengXiangLi/followers","following_url":"https://api.github.com/users/ChengXiangLi/following{/other_user}","gists_url":"https://api.github.com/users/ChengXiangLi/gists{/gist_id}","starred_url":"https://api.github.com/users/ChengXiangLi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChengXiangLi/subscriptions","organizations_url":"https://api.github.com/users/ChengXiangLi/orgs","repos_url":"https://api.github.com/users/ChengXiangLi/repos","events_url":"https://api.github.com/users/ChengXiangLi/events{/privacy}","received_events_url":"https://api.github.com/users/ChengXiangLi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ChengXiangLi/shadowmask","description":"Shadowmask is an open source project for data anonymation of big data.","fork":false,"url":"https://api.github.com/repos/ChengXiangLi/shadowmask","forks_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/forks","keys_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/teams","hooks_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/hooks","issue_events_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/issues/events{/number}","events_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/events","assignees_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/assignees{/user}","branches_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/branches{/branch}","tags_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/tags","blobs_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/git/refs{/sha}","trees_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/statuses/{sha}","languages_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/languages","stargazers_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/stargazers","contributors_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/contributors","subscribers_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/subscribers","subscription_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/subscription","commits_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/commits{/sha}","git_commits_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/git/commits{/sha}","comments_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/comments{/number}","issue_comment_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/issues/comments{/number}","contents_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/contents/{+path}","compare_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/merges","archive_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/downloads","issues_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/issues{/number}","pulls_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/pulls{/number}","milestones_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/milestones{/number}","notifications_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/labels{/name}","releases_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/releases{/id}","deployments_url":"https://api.github.com/repos/ChengXiangLi/shadowmask/deployments","created_at":"2016-09-19T04:16:29Z","updated_at":"2016-09-21T01:27:07Z","pushed_at":"2016-09-26T11:51:00Z","git_url":"git://github.com/ChengXiangLi/shadowmask.git","ssh_url":"git@github.com:ChengXiangLi/shadowmask.git","clone_url":"https://github.com/ChengXiangLi/shadowmask.git","svn_url":"https://github.com/ChengXiangLi/shadowmask","homepage":null,"size":41,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":1,"forks":3,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ChengXiangLi/shadowmask/pulls/4"},"html":{"href":"https://github.com/ChengXiangLi/shadowmask/pull/4"},"issue":{"href":"https://api.github.com/repos/ChengXiangLi/shadowmask/issues/4"},"comments":{"href":"https://api.github.com/repos/ChengXiangLi/shadowmask/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/ChengXiangLi/shadowmask/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/ChengXiangLi/shadowmask/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ChengXiangLi/shadowmask/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/ChengXiangLi/shadowmask/statuses/906fd46cdf340145ad8223036fb05099031cbb4e"}}}}
{"actor":{"display_login":"ChengXiangLi"}}