{"action":"created","comment":{"url":"https://api.github.com/repos/ryotan/kaba-vault/pulls/comments/63393432","id":63393432,"diff_hunk":"@@ -12,65 +14,207 @@\n import java.security.NoSuchAlgorithmException;\n import java.security.spec.InvalidKeySpecException;\n \n-public class PBE {\n-\n+/**\n+ * Utility class for PBE encryption/decryption.\n+ *\n+ * @author ryotan\n+ * @since 1.0.0\n+ */\n+public final class PBE {\n+\n+    /**\n+     * PBE encryption algorithm name.\n+     */\n     private static final String ENCRYPTION_ALGORITHM = \"PBEWithMD5AndDES\";\n-    private static final byte[] SALT = new byte[]{\n+\n+    /**\n+     * Default salt bytes of PBE encryption.\n+     */\n+    private static final byte[] DEFAULT_SALT = new byte[]{\n             (byte) 0xd8, (byte) 0x3d, (byte) 0xde, (byte) 0x0b, (byte) 0xd8, (byte) 0xd8, (byte) 0xd8, (byte) 0xd8\n     };\n \n+    /**\n+     * Default iteration count of PBE encryption.\n+     */\n+    private static final int DEFAULT_ITERATION_COUNT = 50;\n+\n+\n+    /**\n+     * Returns default PBE encrypter.\n+     *\n+     * @return default PBE encrypter\n+     */\n     public static Encrypter getEncrypter() {\n-        return new Encrypter(SALT, 50);\n+        return getEncrypter(DEFAULT_SALT, DEFAULT_ITERATION_COUNT);\n     }\n \n+    /**\n+     * Returns PBE encrypter whose salt is {@code salt} and iterationCount is {@code iterationCount}.\n+     *\n+     * @param salt           salt of PBE encryption\n+     * @param iterationCount iteration count of PBE encryption\n+     * @return PBE encrypter\n+     */\n+    public static Encrypter getEncrypter(byte[] salt, int iterationCount) {\n+        byte[] copied = new byte[salt.length];\n+        System.arraycopy(salt, 0, copied, 0, salt.length);\n+        return new Encrypter(copied, iterationCount);\n+    }\n+\n+    /**\n+     * Returns default PBE decrypter.\n+     *\n+     * @return default PBE decrypter\n+     */\n     public static Decrypter getDecrypter() {\n-        return new Decrypter(SALT, 50);\n+        return getDecrypter(DEFAULT_SALT, DEFAULT_ITERATION_COUNT);\n+    }\n+\n+    /**\n+     * Returns PBE decrypter whose salt is {@code salt} and iterationCount is {@code iterationCount}.\n+     *\n+     * @param salt           salt of PBE decryption\n+     * @param iterationCount iteration count of PBE decryption\n+     * @return PBE decrypter\n+     */\n+    public static Decrypter getDecrypter(byte[] salt, int iterationCount) {\n+        byte[] copied = new byte[salt.length];\n+        System.arraycopy(salt, 0, copied, 0, salt.length);\n+        return new Decrypter(copied, iterationCount);\n     }\n \n-    private static Cipher getCipher(int mode, char[] password, byte[] salt, int iterationCount) throws NoSuchAlgorithmException,\n-            InvalidKeySpecException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeyException {\n+    /**\n+     * Returns {@link Cipher} for PBE encryption/decryption.\n+     *\n+     * @param mode           encryption({@link Cipher#ENCRYPT_MODE})/decryption({@link Cipher#DECRYPT_MODE})\n+     * @param password       password of PBE\n+     * @param salt           salt of PBE\n+     * @param iterationCount iteration count of PBE\n+     * @return {@link Cipher} for PBE encryption/decryption\n+     * @throws NoSuchAlgorithmException if the running JRE does not support \"{@value ENCRYPTION_ALGORITHM}\"\n+     * @throws InvalidKeyException      if the given key size exceeds the maximum allowable key size\n+     */\n+    private static Cipher getCipher(int mode, char[] password, byte[] salt, int iterationCount) throws NoSuchAlgorithmException, InvalidKeyException {\n         PBEKeySpec keySpec = new PBEKeySpec(password);\n         SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ENCRYPTION_ALGORITHM);\n-        SecretKey key = keyFactory.generateSecret(keySpec);\n+        SecretKey key;\n+        try {\n+            key = keyFactory.generateSecret(keySpec);","path":"src/main/java/pw/itr0/kaba/encrypt/PBE.java","position":106,"original_position":106,"commit_id":"af4d6eb2c4cdafb3a2d8d51422d1560eb1cd54f8","original_commit_id":"af4d6eb2c4cdafb3a2d8d51422d1560eb1cd54f8","user":{"login":"ryotan","id":17810,"avatar_url":"https://avatars.githubusercontent.com/u/17810?v=3","gravatar_id":"","url":"https://api.github.com/users/ryotan","html_url":"https://github.com/ryotan","followers_url":"https://api.github.com/users/ryotan/followers","following_url":"https://api.github.com/users/ryotan/following{/other_user}","gists_url":"https://api.github.com/users/ryotan/gists{/gist_id}","starred_url":"https://api.github.com/users/ryotan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryotan/subscriptions","organizations_url":"https://api.github.com/users/ryotan/orgs","repos_url":"https://api.github.com/users/ryotan/repos","events_url":"https://api.github.com/users/ryotan/events{/privacy}","received_events_url":"https://api.github.com/users/ryotan/received_events","type":"User","site_admin":false},"body":"![Codacy](https://www.codacy.com/assets/images/favicon.png) Issue found: [Found 'DU'-anomaly for variable 'key' (lines '103'-'122').](https://www.codacy.com/app/ryotan/kaba-vault/file/2578430306/issues/source?bid=3298589&fileBranchId=3301306#l103)","created_at":"2016-05-16T17:44:10Z","updated_at":"2016-05-16T17:44:10Z","html_url":"https://github.com/ryotan/kaba-vault/pull/2#discussion_r63393432","pull_request_url":"https://api.github.com/repos/ryotan/kaba-vault/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/ryotan/kaba-vault/pulls/comments/63393432"},"html":{"href":"https://github.com/ryotan/kaba-vault/pull/2#discussion_r63393432"},"pull_request":{"href":"https://api.github.com/repos/ryotan/kaba-vault/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/ryotan/kaba-vault/pulls/2","id":70209049,"html_url":"https://github.com/ryotan/kaba-vault/pull/2","diff_url":"https://github.com/ryotan/kaba-vault/pull/2.diff","patch_url":"https://github.com/ryotan/kaba-vault/pull/2.patch","issue_url":"https://api.github.com/repos/ryotan/kaba-vault/issues/2","number":2,"state":"open","locked":false,"title":"[WIP] improve code quality.","user":{"login":"ryotan","id":17810,"avatar_url":"https://avatars.githubusercontent.com/u/17810?v=3","gravatar_id":"","url":"https://api.github.com/users/ryotan","html_url":"https://github.com/ryotan","followers_url":"https://api.github.com/users/ryotan/followers","following_url":"https://api.github.com/users/ryotan/following{/other_user}","gists_url":"https://api.github.com/users/ryotan/gists{/gist_id}","starred_url":"https://api.github.com/users/ryotan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryotan/subscriptions","organizations_url":"https://api.github.com/users/ryotan/orgs","repos_url":"https://api.github.com/users/ryotan/repos","events_url":"https://api.github.com/users/ryotan/events{/privacy}","received_events_url":"https://api.github.com/users/ryotan/received_events","type":"User","site_admin":false},"body":"* Utility class should be final.\r\n* Array should be copied before setting into field.","created_at":"2016-05-16T15:00:08Z","updated_at":"2016-05-16T17:44:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5406bcd12f26087bfdbc3aa5e5eee32d5757d85f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ryotan/kaba-vault/pulls/2/commits","review_comments_url":"https://api.github.com/repos/ryotan/kaba-vault/pulls/2/comments","review_comment_url":"https://api.github.com/repos/ryotan/kaba-vault/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ryotan/kaba-vault/issues/2/comments","statuses_url":"https://api.github.com/repos/ryotan/kaba-vault/statuses/af4d6eb2c4cdafb3a2d8d51422d1560eb1cd54f8","head":{"label":"ryotan:chore/improve-code-quality","ref":"chore/improve-code-quality","sha":"af4d6eb2c4cdafb3a2d8d51422d1560eb1cd54f8","user":{"login":"ryotan","id":17810,"avatar_url":"https://avatars.githubusercontent.com/u/17810?v=3","gravatar_id":"","url":"https://api.github.com/users/ryotan","html_url":"https://github.com/ryotan","followers_url":"https://api.github.com/users/ryotan/followers","following_url":"https://api.github.com/users/ryotan/following{/other_user}","gists_url":"https://api.github.com/users/ryotan/gists{/gist_id}","starred_url":"https://api.github.com/users/ryotan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryotan/subscriptions","organizations_url":"https://api.github.com/users/ryotan/orgs","repos_url":"https://api.github.com/users/ryotan/repos","events_url":"https://api.github.com/users/ryotan/events{/privacy}","received_events_url":"https://api.github.com/users/ryotan/received_events","type":"User","site_admin":false},"repo":{"id":58669681,"name":"kaba-vault","full_name":"ryotan/kaba-vault","owner":{"login":"ryotan","id":17810,"avatar_url":"https://avatars.githubusercontent.com/u/17810?v=3","gravatar_id":"","url":"https://api.github.com/users/ryotan","html_url":"https://github.com/ryotan","followers_url":"https://api.github.com/users/ryotan/followers","following_url":"https://api.github.com/users/ryotan/following{/other_user}","gists_url":"https://api.github.com/users/ryotan/gists{/gist_id}","starred_url":"https://api.github.com/users/ryotan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryotan/subscriptions","organizations_url":"https://api.github.com/users/ryotan/orgs","repos_url":"https://api.github.com/users/ryotan/repos","events_url":"https://api.github.com/users/ryotan/events{/privacy}","received_events_url":"https://api.github.com/users/ryotan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ryotan/kaba-vault","description":null,"fork":false,"url":"https://api.github.com/repos/ryotan/kaba-vault","forks_url":"https://api.github.com/repos/ryotan/kaba-vault/forks","keys_url":"https://api.github.com/repos/ryotan/kaba-vault/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ryotan/kaba-vault/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ryotan/kaba-vault/teams","hooks_url":"https://api.github.com/repos/ryotan/kaba-vault/hooks","issue_events_url":"https://api.github.com/repos/ryotan/kaba-vault/issues/events{/number}","events_url":"https://api.github.com/repos/ryotan/kaba-vault/events","assignees_url":"https://api.github.com/repos/ryotan/kaba-vault/assignees{/user}","branches_url":"https://api.github.com/repos/ryotan/kaba-vault/branches{/branch}","tags_url":"https://api.github.com/repos/ryotan/kaba-vault/tags","blobs_url":"https://api.github.com/repos/ryotan/kaba-vault/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ryotan/kaba-vault/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ryotan/kaba-vault/git/refs{/sha}","trees_url":"https://api.github.com/repos/ryotan/kaba-vault/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ryotan/kaba-vault/statuses/{sha}","languages_url":"https://api.github.com/repos/ryotan/kaba-vault/languages","stargazers_url":"https://api.github.com/repos/ryotan/kaba-vault/stargazers","contributors_url":"https://api.github.com/repos/ryotan/kaba-vault/contributors","subscribers_url":"https://api.github.com/repos/ryotan/kaba-vault/subscribers","subscription_url":"https://api.github.com/repos/ryotan/kaba-vault/subscription","commits_url":"https://api.github.com/repos/ryotan/kaba-vault/commits{/sha}","git_commits_url":"https://api.github.com/repos/ryotan/kaba-vault/git/commits{/sha}","comments_url":"https://api.github.com/repos/ryotan/kaba-vault/comments{/number}","issue_comment_url":"https://api.github.com/repos/ryotan/kaba-vault/issues/comments{/number}","contents_url":"https://api.github.com/repos/ryotan/kaba-vault/contents/{+path}","compare_url":"https://api.github.com/repos/ryotan/kaba-vault/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ryotan/kaba-vault/merges","archive_url":"https://api.github.com/repos/ryotan/kaba-vault/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ryotan/kaba-vault/downloads","issues_url":"https://api.github.com/repos/ryotan/kaba-vault/issues{/number}","pulls_url":"https://api.github.com/repos/ryotan/kaba-vault/pulls{/number}","milestones_url":"https://api.github.com/repos/ryotan/kaba-vault/milestones{/number}","notifications_url":"https://api.github.com/repos/ryotan/kaba-vault/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ryotan/kaba-vault/labels{/name}","releases_url":"https://api.github.com/repos/ryotan/kaba-vault/releases{/id}","deployments_url":"https://api.github.com/repos/ryotan/kaba-vault/deployments","created_at":"2016-05-12T19:12:06Z","updated_at":"2016-05-14T20:42:29Z","pushed_at":"2016-05-16T17:42:16Z","git_url":"git://github.com/ryotan/kaba-vault.git","ssh_url":"git@github.com:ryotan/kaba-vault.git","clone_url":"https://github.com/ryotan/kaba-vault.git","svn_url":"https://github.com/ryotan/kaba-vault","homepage":null,"size":21,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"ryotan:master","ref":"master","sha":"b2697624b64c49abd006b5277934744b3d9a12af","user":{"login":"ryotan","id":17810,"avatar_url":"https://avatars.githubusercontent.com/u/17810?v=3","gravatar_id":"","url":"https://api.github.com/users/ryotan","html_url":"https://github.com/ryotan","followers_url":"https://api.github.com/users/ryotan/followers","following_url":"https://api.github.com/users/ryotan/following{/other_user}","gists_url":"https://api.github.com/users/ryotan/gists{/gist_id}","starred_url":"https://api.github.com/users/ryotan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryotan/subscriptions","organizations_url":"https://api.github.com/users/ryotan/orgs","repos_url":"https://api.github.com/users/ryotan/repos","events_url":"https://api.github.com/users/ryotan/events{/privacy}","received_events_url":"https://api.github.com/users/ryotan/received_events","type":"User","site_admin":false},"repo":{"id":58669681,"name":"kaba-vault","full_name":"ryotan/kaba-vault","owner":{"login":"ryotan","id":17810,"avatar_url":"https://avatars.githubusercontent.com/u/17810?v=3","gravatar_id":"","url":"https://api.github.com/users/ryotan","html_url":"https://github.com/ryotan","followers_url":"https://api.github.com/users/ryotan/followers","following_url":"https://api.github.com/users/ryotan/following{/other_user}","gists_url":"https://api.github.com/users/ryotan/gists{/gist_id}","starred_url":"https://api.github.com/users/ryotan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryotan/subscriptions","organizations_url":"https://api.github.com/users/ryotan/orgs","repos_url":"https://api.github.com/users/ryotan/repos","events_url":"https://api.github.com/users/ryotan/events{/privacy}","received_events_url":"https://api.github.com/users/ryotan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ryotan/kaba-vault","description":null,"fork":false,"url":"https://api.github.com/repos/ryotan/kaba-vault","forks_url":"https://api.github.com/repos/ryotan/kaba-vault/forks","keys_url":"https://api.github.com/repos/ryotan/kaba-vault/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ryotan/kaba-vault/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ryotan/kaba-vault/teams","hooks_url":"https://api.github.com/repos/ryotan/kaba-vault/hooks","issue_events_url":"https://api.github.com/repos/ryotan/kaba-vault/issues/events{/number}","events_url":"https://api.github.com/repos/ryotan/kaba-vault/events","assignees_url":"https://api.github.com/repos/ryotan/kaba-vault/assignees{/user}","branches_url":"https://api.github.com/repos/ryotan/kaba-vault/branches{/branch}","tags_url":"https://api.github.com/repos/ryotan/kaba-vault/tags","blobs_url":"https://api.github.com/repos/ryotan/kaba-vault/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ryotan/kaba-vault/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ryotan/kaba-vault/git/refs{/sha}","trees_url":"https://api.github.com/repos/ryotan/kaba-vault/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ryotan/kaba-vault/statuses/{sha}","languages_url":"https://api.github.com/repos/ryotan/kaba-vault/languages","stargazers_url":"https://api.github.com/repos/ryotan/kaba-vault/stargazers","contributors_url":"https://api.github.com/repos/ryotan/kaba-vault/contributors","subscribers_url":"https://api.github.com/repos/ryotan/kaba-vault/subscribers","subscription_url":"https://api.github.com/repos/ryotan/kaba-vault/subscription","commits_url":"https://api.github.com/repos/ryotan/kaba-vault/commits{/sha}","git_commits_url":"https://api.github.com/repos/ryotan/kaba-vault/git/commits{/sha}","comments_url":"https://api.github.com/repos/ryotan/kaba-vault/comments{/number}","issue_comment_url":"https://api.github.com/repos/ryotan/kaba-vault/issues/comments{/number}","contents_url":"https://api.github.com/repos/ryotan/kaba-vault/contents/{+path}","compare_url":"https://api.github.com/repos/ryotan/kaba-vault/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ryotan/kaba-vault/merges","archive_url":"https://api.github.com/repos/ryotan/kaba-vault/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ryotan/kaba-vault/downloads","issues_url":"https://api.github.com/repos/ryotan/kaba-vault/issues{/number}","pulls_url":"https://api.github.com/repos/ryotan/kaba-vault/pulls{/number}","milestones_url":"https://api.github.com/repos/ryotan/kaba-vault/milestones{/number}","notifications_url":"https://api.github.com/repos/ryotan/kaba-vault/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ryotan/kaba-vault/labels{/name}","releases_url":"https://api.github.com/repos/ryotan/kaba-vault/releases{/id}","deployments_url":"https://api.github.com/repos/ryotan/kaba-vault/deployments","created_at":"2016-05-12T19:12:06Z","updated_at":"2016-05-14T20:42:29Z","pushed_at":"2016-05-16T17:42:16Z","git_url":"git://github.com/ryotan/kaba-vault.git","ssh_url":"git@github.com:ryotan/kaba-vault.git","clone_url":"https://github.com/ryotan/kaba-vault.git","svn_url":"https://github.com/ryotan/kaba-vault","homepage":null,"size":21,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ryotan/kaba-vault/pulls/2"},"html":{"href":"https://github.com/ryotan/kaba-vault/pull/2"},"issue":{"href":"https://api.github.com/repos/ryotan/kaba-vault/issues/2"},"comments":{"href":"https://api.github.com/repos/ryotan/kaba-vault/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/ryotan/kaba-vault/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/ryotan/kaba-vault/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ryotan/kaba-vault/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/ryotan/kaba-vault/statuses/af4d6eb2c4cdafb3a2d8d51422d1560eb1cd54f8"}}}}