diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-01-06 10:25:47 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-01-06 10:25:47 +0100 |
commit | e6740c707c8cc05051f8c0ac716d809809df43ce (patch) | |
tree | 5bbd6e6926e679d950f870263aca445b59d3ad7e /server/sonar-process/src | |
parent | 68284714b92b16a230be3f901f8e615d773129ac (diff) | |
download | sonarqube-e6740c707c8cc05051f8c0ac716d809809df43ce.tar.gz sonarqube-e6740c707c8cc05051f8c0ac716d809809df43ce.zip |
Fix some quality flaws
Diffstat (limited to 'server/sonar-process/src')
-rw-r--r-- | server/sonar-process/src/main/java/org/sonar/process/AesCipher.java | 8 | ||||
-rw-r--r-- | server/sonar-process/src/main/java/org/sonar/process/Base64Cipher.java | 5 |
2 files changed, 8 insertions, 5 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/AesCipher.java b/server/sonar-process/src/main/java/org/sonar/process/AesCipher.java index 204ae1a6b6b..f98f1fe65dd 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/AesCipher.java +++ b/server/sonar-process/src/main/java/org/sonar/process/AesCipher.java @@ -20,6 +20,7 @@ package org.sonar.process; +import org.apache.commons.io.Charsets; import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; @@ -28,6 +29,7 @@ import javax.annotation.Nullable; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; + import java.io.File; import java.io.IOException; import java.security.Key; @@ -58,7 +60,7 @@ final class AesCipher implements Cipher { try { javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(CRYPTO_KEY); cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, loadSecretFile()); - return new String(Base64.encodeBase64(cipher.doFinal(clearText.getBytes("UTF-8")))); + return Base64.encodeBase64String(cipher.doFinal(clearText.getBytes("UTF-8"))); } catch (RuntimeException e) { throw e; } catch (Exception e) { @@ -72,7 +74,7 @@ final class AesCipher implements Cipher { javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(CRYPTO_KEY); cipher.init(javax.crypto.Cipher.DECRYPT_MODE, loadSecretFile()); byte[] cipherData = cipher.doFinal(Base64.decodeBase64(StringUtils.trim(encryptedText))); - return new String(cipherData); + return new String(cipherData, Charsets.UTF_8); } catch (RuntimeException e) { throw e; } catch (Exception e) { @@ -117,7 +119,7 @@ final class AesCipher implements Cipher { KeyGenerator keyGen = KeyGenerator.getInstance(CRYPTO_KEY); keyGen.init(KEY_SIZE_IN_BITS, new SecureRandom()); SecretKey secretKey = keyGen.generateKey(); - return new String(Base64.encodeBase64(secretKey.getEncoded())); + return Base64.encodeBase64String(secretKey.getEncoded()); } catch (Exception e) { throw new IllegalStateException("Fail to generate secret key", e); diff --git a/server/sonar-process/src/main/java/org/sonar/process/Base64Cipher.java b/server/sonar-process/src/main/java/org/sonar/process/Base64Cipher.java index 5eb3eecd541..fb950396352 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/Base64Cipher.java +++ b/server/sonar-process/src/main/java/org/sonar/process/Base64Cipher.java @@ -21,15 +21,16 @@ package org.sonar.process; import org.apache.commons.codec.binary.Base64; +import org.apache.commons.io.Charsets; final class Base64Cipher implements Cipher { @Override public String encrypt(String clearText) { - return new String(Base64.encodeBase64(clearText.getBytes())); + return Base64.encodeBase64String(clearText.getBytes()); } @Override public String decrypt(String encryptedText) { - return new String(Base64.decodeBase64(encryptedText)); + return new String(Base64.decodeBase64(encryptedText), Charsets.UTF_8); } } |