related to issue 36909: minor code review improvements
authorCarlos Aristu <carlos.aristu@openbravo.com>
Wed, 27 Sep 2017 09:54:45 +0200
changeset 32824 9d9df9af05c4
parent 32823 916f5b898b33
child 32825 813c115641f1
child 32827 a2ee31f89feb
related to issue 36909: minor code review improvements

- Created new private TRANSFORMATION constant
- Moved the array designator from the variable to the type
src-core/src/org/openbravo/utils/CryptoUtility.java
--- a/src-core/src/org/openbravo/utils/CryptoUtility.java	Tue Sep 26 21:52:28 2017 +0000
+++ b/src-core/src/org/openbravo/utils/CryptoUtility.java	Wed Sep 27 09:54:45 2017 +0200
@@ -24,6 +24,7 @@
 public class CryptoUtility {
   private static final SecretKey KEY = new SecretKeySpec(new byte[] { 100, 25, 28, -122, -26, 94,
       -3, -72 }, "DES");
+  private static final String TRANSFORMATION = "DES/ECB/PKCS5Padding";
 
   /**
    * Encrypts a String
@@ -36,9 +37,9 @@
     String clearText = value == null ? "" : value;
 
     try {
-      Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
+      Cipher cipher = Cipher.getInstance(TRANSFORMATION);
       cipher.init(Cipher.ENCRYPT_MODE, KEY);
-      byte encString[] = cipher.doFinal(clearText.getBytes());
+      byte[] encString = cipher.doFinal(clearText.getBytes());
       return new String(encodeBase64(encString), "UTF-8");
     } catch (Exception ex) {
       throw new ServletException("CryptoUtility.encrypt() - Can't init cipher", ex);
@@ -58,8 +59,8 @@
     }
 
     try {
-      byte decode[] = decodeBase64(value.getBytes("UTF-8"));
-      Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
+      byte[] decode = decodeBase64(value.getBytes("UTF-8"));
+      Cipher cipher = Cipher.getInstance(TRANSFORMATION);
       cipher.init(Cipher.DECRYPT_MODE, KEY, cipher.getParameters());
       return new String(cipher.doFinal(decode));
     } catch (Exception ex) {