<NME> JasyptPasswordEncryptor.java
<BEF> /*
 * Copyright 2009-2018, Acciente LLC
 *
 * Acciente LLC licenses this file to you under the
 * Apache License, Version 2.0 (the "License"); you
 * may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in
 * writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
 * OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing
 * permissions and limitations under the License.
 */
package com.acciente.oacc.encryptor.jasypt;

import com.acciente.oacc.encryptor.PasswordEncryptor;
import com.acciente.oacc.normalizer.TextNormalizer;

import java.io.Serializable;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public final class JasyptPasswordEncryptor implements PasswordEncryptor, Serializable {
   public static final String NAME = "jasypt";

   public static final String NAME = "jasypt";

   private static final StandardByteDigesterPool digesterPool           = new StandardByteDigesterPool();
   private static final PasswordEncoderDecoder   passwordEncoderDecoder = new PasswordEncoderDecoder();

   private final String algorithm;
   private final int    iterations;
   private final int    saltSizeBytes;
   private final int    iterations;
   private final int    saltSizeBytes;

   public static JasyptPasswordEncryptor getPasswordEncryptor() {
      return getPasswordEncryptor(DEFAULT_ALGORITHM, DEFAULT_ITERATIONS, DEFAULT_SALT_SIZE_BYTES);
   }

   public static JasyptPasswordEncryptor getPasswordEncryptor(String encryptAlgorithm,
                                                              int encryptIterations,
                                                              int encryptSaltSizeBytes) {
      return new JasyptPasswordEncryptor(encryptAlgorithm, encryptIterations, encryptSaltSizeBytes);
   }

   private JasyptPasswordEncryptor(String algorithm, int iterations, int saltSizeBytes) {
   public String encryptPassword(final char[] plainPassword) {
      if (plainPassword == null) {
         return null;
      }

      final byte[] digest = digesterPool.getStandardByteDigester(algorithm, iterations, saltSizeBytes)
            .digest(getCleanedBytes(plainPassword));

      return passwordEncoderDecoder.encode(algorithm, iterations, saltSizeBytes, digest);
   }

   @Override
   public boolean checkPassword(final char[] plainPassword,
                                final String storedPassword) {
      if (plainPassword == null) {
         return (storedPassword == null);
      }
      else if (storedPassword == null) {
         return false;
      }

      final DecodedPassword decodedPassword = passwordEncoderDecoder.decode(storedPassword);
      return digesterPool.getStandardByteDigester(decodedPassword.getAlgorithm(),
                                                  decodedPassword.getIterations(),
                                                  decodedPassword.getSaltSizeBytes())
            .matches(getCleanedBytes(plainPassword), decodedPassword.getDigest());
   }

   private static byte[] getCleanedBytes(char[] password) {
      final char[] normalizedChars = TextNormalizer.getInstance().normalizeToNfc(password);
      final ByteBuffer byteBuffer = StandardCharsets.UTF_8.encode(CharBuffer.wrap(normalizedChars));
      final byte[]     byteArray  = new byte[byteBuffer.remaining()];
      byteBuffer.get(byteArray);
      Arrays.fill(byteBuffer.array(), (byte) 0);
      return byteArray;
   }
}

<MSG> adds Javadoc comments to the JasyptPasswordEncryptor class

<DFF> @@ -26,6 +26,9 @@ import java.nio.CharBuffer;
 import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 
+/**
+ * Password encryptor implementation that uses the Jasypt digester for creating password hashes.
+ */
 public final class JasyptPasswordEncryptor implements PasswordEncryptor, Serializable {
    public static final String NAME = "jasypt";
 
@@ -40,14 +43,27 @@ public final class JasyptPasswordEncryptor implements PasswordEncryptor, Seriali
    private final int    iterations;
    private final int    saltSizeBytes;
 
+   /**
+    * Creates a password encryptor that uses the Jasypt digester for password hashing with the following default
+    * parameters (algorithm: {@value DEFAULT_ALGORITHM}; iterations: {@value DEFAULT_ITERATIONS};
+    * saltSizeBytes: {@value DEFAULT_SALT_SIZE_BYTES})
+    *
+    * @return a {@link JasyptPasswordEncryptor} instance.
+    */
    public static JasyptPasswordEncryptor getPasswordEncryptor() {
       return getPasswordEncryptor(DEFAULT_ALGORITHM, DEFAULT_ITERATIONS, DEFAULT_SALT_SIZE_BYTES);
    }
 
-   public static JasyptPasswordEncryptor getPasswordEncryptor(String encryptAlgorithm,
-                                                              int encryptIterations,
-                                                              int encryptSaltSizeBytes) {
-      return new JasyptPasswordEncryptor(encryptAlgorithm, encryptIterations, encryptSaltSizeBytes);
+   /**
+    * Creates a password encryptor that uses the Jasypt digester for password hashing with the specified values for
+    * algorithm, iterations and saltSizeBytes.
+    *
+    * @return a {@link JasyptPasswordEncryptor} instance.
+    */
+   public static JasyptPasswordEncryptor getPasswordEncryptor(String algorithm,
+                                                              int iterations,
+                                                              int saltSizeBytes) {
+      return new JasyptPasswordEncryptor(algorithm, iterations, saltSizeBytes);
    }
 
    private JasyptPasswordEncryptor(String algorithm, int iterations, int saltSizeBytes) {

{'commit': 'diff --git a/src/main/java/com/acciente/oacc/encryptor/jasypt/JasyptPasswordEncryptor.java b/src/main/java/com/acciente/oacc/encryptor/jasypt/JasyptPasswordEncryptor.java\nindex 6112694..3814292 100644\n--- a/src/main/java/com/acciente/oacc/encryptor/jasypt/JasyptPasswordEncryptor.java\n+++ b/src/main/java/com/acciente/oacc/encryptor/jasypt/JasyptPasswordEncryptor.java\n@@ -26,6 +26,9 @@ import java.nio.CharBuffer;\n import java.nio.charset.StandardCharsets;\n import java.util.Arrays;\n \n+/**\n+ * Password encryptor implementation that uses the Jasypt digester for creating password hashes.\n+ */\n public final class JasyptPasswordEncryptor implements PasswordEncryptor, Serializable {\n    public static final String NAME = "jasypt";\n \n@@ -40,14 +43,27 @@ public final class JasyptPasswordEncryptor implements PasswordEncryptor, Seriali\n    private final int    iterations;\n    private final int    saltSizeBytes;\n \n+   /**\n+    * Creates a password encryptor that uses the Jasypt digester for password hashing with the following default\n+    * parameters (algorithm: {@value DEFAULT_ALGORITHM}; iterations: {@value DEFAULT_ITERATIONS};\n+    * saltSizeBytes: {@value DEFAULT_SALT_SIZE_BYTES})\n+    *\n+    * @return a {@link JasyptPasswordEncryptor} instance.\n+    */\n    public static JasyptPasswordEncryptor getPasswordEncryptor() {\n       return getPasswordEncryptor(DEFAULT_ALGORITHM, DEFAULT_ITERATIONS, DEFAULT_SALT_SIZE_BYTES);\n    }\n \n-   public static JasyptPasswordEncryptor getPasswordEncryptor(String encryptAlgorithm,\n-                                                              int encryptIterations,\n-                                                              int encryptSaltSizeBytes) {\n-      return new JasyptPasswordEncryptor(encryptAlgorithm, encryptIterations, encryptSaltSizeBytes);\n+   /**\n+    * Creates a password encryptor that uses the Jasypt digester for password hashing with the specified values for\n+    * algorithm, iterations and saltSizeBytes.\n+    *\n+    * @return a {@link JasyptPasswordEncryptor} instance.\n+    */\n+   public static JasyptPasswordEncryptor getPasswordEncryptor(String algorithm,\n+                                                              int iterations,\n+                                                              int saltSizeBytes) {\n+      return new JasyptPasswordEncryptor(algorithm, iterations, saltSizeBytes);\n    }\n \n    private JasyptPasswordEncryptor(String algorithm, int iterations, int saltSizeBytes) {\n', 'commit_subject': 'adds Javadoc comments to the JasyptPasswordEncryptor class', 'repo_name': 'acciente/oacc-core', 'committer': {'name': 'Adinath Raveendra Raj', 'email': 'c50299027fd783cd66cca0e6c7c16e59ed7cd41d@acciente.com', 'time_sec': '1486269445', 'tz_offset': '-420', 'date': {'seconds': '1486269445'}}, 'commit_tree': 'a466a4cf6cff1bc021f74ef6e7db756e4d03c492', 'commit_message': 'adds Javadoc comments to the JasyptPasswordEncryptor class\n', 'language_name': 'Java', 'license': 'apache-2.0', 'hunks': '@@ -26,6 +26,9 @@ import java.nio.CharBuffer;\n import java.nio.charset.StandardCharsets;\n import java.util.Arrays;\n \n+/**\n+ * Password encryptor implementation that uses the Jasypt digester for creating password hashes.\n+ */\n public final class JasyptPasswordEncryptor implements PasswordEncryptor, Serializable {\n    public static final String NAME = "jasypt";\n \n@@ -40,14 +43,27 @@ public final class JasyptPasswordEncryptor implements PasswordEncryptor, Seriali\n    private final int    iterations;\n    private final int    saltSizeBytes;\n \n+   /**\n+    * Creates a password encryptor that uses the Jasypt digester for password hashing with the following default\n+    * parameters (algorithm: {@value DEFAULT_ALGORITHM}; iterations: {@value DEFAULT_ITERATIONS};\n+    * saltSizeBytes: {@value DEFAULT_SALT_SIZE_BYTES})\n+    *\n+    * @return a {@link JasyptPasswordEncryptor} instance.\n+    */\n    public static JasyptPasswordEncryptor getPasswordEncryptor() {\n       return getPasswordEncryptor(DEFAULT_ALGORITHM, DEFAULT_ITERATIONS, DEFAULT_SALT_SIZE_BYTES);\n    }\n \n-   public static JasyptPasswordEncryptor getPasswordEncryptor(String encryptAlgorithm,\n-                                                              int encryptIterations,\n-                                                              int encryptSaltSizeBytes) {\n-      return new JasyptPasswordEncryptor(encryptAlgorithm, encryptIterations, encryptSaltSizeBytes);\n+   /**\n+    * Creates a password encryptor that uses the Jasypt digester for password hashing with the specified values for\n+    * algorithm, iterations and saltSizeBytes.\n+    *\n+    * @return a {@link JasyptPasswordEncryptor} instance.\n+    */\n+   public static JasyptPasswordEncryptor getPasswordEncryptor(String algorithm,\n+                                                              int iterations,\n+                                                              int saltSizeBytes) {\n+      return new JasyptPasswordEncryptor(algorithm, iterations, saltSizeBytes);\n    }\n \n    private JasyptPasswordEncryptor(String algorithm, int iterations, int saltSizeBytes) {\n', 'addition_count': 20, 'deletion_count': 4, 'src_file': 'a/src/main/java/com/acciente/oacc/encryptor/jasypt/JasyptPasswordEncryptor.java', 'tgt_file': 'b/src/main/java/com/acciente/oacc/encryptor/jasypt/JasyptPasswordEncryptor.java', 'file_extension': '.java', 'before_file': '/*\n * Copyright 2009-2018, Acciente LLC\n *\n * Acciente LLC licenses this file to you under the\n * Apache License, Version 2.0 (the "License"); you\n * may not use this file except in compliance with the\n * License. You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in\n * writing, software distributed under the License is\n * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES\n * OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing\n * permissions and limitations under the License.\n */\npackage com.acciente.oacc.encryptor.jasypt;\n\nimport com.acciente.oacc.encryptor.PasswordEncryptor;\nimport com.acciente.oacc.normalizer.TextNormalizer;\n\nimport java.io.Serializable;\nimport java.nio.ByteBuffer;\nimport java.nio.CharBuffer;\nimport java.nio.charset.StandardCharsets;\nimport java.util.Arrays;\n\npublic final class JasyptPasswordEncryptor implements PasswordEncryptor, Serializable {\n   public static final String NAME = "jasypt";\n\n   public static final String NAME = "jasypt";\n\n   private static final StandardByteDigesterPool digesterPool           = new StandardByteDigesterPool();\n   private static final PasswordEncoderDecoder   passwordEncoderDecoder = new PasswordEncoderDecoder();\n\n   private final String algorithm;\n   private final int    iterations;\n   private final int    saltSizeBytes;\n   private final int    iterations;\n   private final int    saltSizeBytes;\n\n   public static JasyptPasswordEncryptor getPasswordEncryptor() {\n      return getPasswordEncryptor(DEFAULT_ALGORITHM, DEFAULT_ITERATIONS, DEFAULT_SALT_SIZE_BYTES);\n   }\n\n   public static JasyptPasswordEncryptor getPasswordEncryptor(String encryptAlgorithm,\n                                                              int encryptIterations,\n                                                              int encryptSaltSizeBytes) {\n      return new JasyptPasswordEncryptor(encryptAlgorithm, encryptIterations, encryptSaltSizeBytes);\n   }\n\n   private JasyptPasswordEncryptor(String algorithm, int iterations, int saltSizeBytes) {\n   public String encryptPassword(final char[] plainPassword) {\n      if (plainPassword == null) {\n         return null;\n      }\n\n      final byte[] digest = digesterPool.getStandardByteDigester(algorithm, iterations, saltSizeBytes)\n            .digest(getCleanedBytes(plainPassword));\n\n      return passwordEncoderDecoder.encode(algorithm, iterations, saltSizeBytes, digest);\n   }\n\n   @Override\n   public boolean checkPassword(final char[] plainPassword,\n                                final String storedPassword) {\n      if (plainPassword == null) {\n         return (storedPassword == null);\n      }\n      else if (storedPassword == null) {\n         return false;\n      }\n\n      final DecodedPassword decodedPassword = passwordEncoderDecoder.decode(storedPassword);\n      return digesterPool.getStandardByteDigester(decodedPassword.getAlgorithm(),\n                                                  decodedPassword.getIterations(),\n                                                  decodedPassword.getSaltSizeBytes())\n            .matches(getCleanedBytes(plainPassword), decodedPassword.getDigest());\n   }\n\n   private static byte[] getCleanedBytes(char[] password) {\n      final char[] normalizedChars = TextNormalizer.getInstance().normalizeToNfc(password);\n      final ByteBuffer byteBuffer = StandardCharsets.UTF_8.encode(CharBuffer.wrap(normalizedChars));\n      final byte[]     byteArray  = new byte[byteBuffer.remaining()];\n      byteBuffer.get(byteArray);\n      Arrays.fill(byteBuffer.array(), (byte) 0);\n      return byteArray;\n   }\n}\n', 'message': 'adds Javadoc comments to the JasyptPasswordEncryptor class\n', 'author_name': 'Adinath Raveendra Raj', 'lang': 'java'}