Cleanup BCryptService class

This commit is contained in:
DNx5 2016-02-09 05:04:29 +07:00
parent 600c70ad9f
commit 9959c0f7d5

View File

@ -388,7 +388,7 @@ public class BCryptService {
private static String encode_base64(byte d[], int len) private static String encode_base64(byte d[], int len)
throws IllegalArgumentException { throws IllegalArgumentException {
int off = 0; int off = 0;
StringBuffer rs = new StringBuffer(); StringBuilder rs = new StringBuilder();
int c1, c2; int c1, c2;
if (len <= 0 || len > d.length) if (len <= 0 || len > d.length)
@ -441,7 +441,7 @@ public class BCryptService {
*/ */
private static byte[] decode_base64(String s, int maxolen) private static byte[] decode_base64(String s, int maxolen)
throws IllegalArgumentException { throws IllegalArgumentException {
StringBuffer rs = new StringBuffer(); StringBuilder rs = new StringBuilder();
int off = 0, slen = s.length(), olen = 0; int off = 0, slen = s.length(), olen = 0;
byte ret[]; byte ret[];
byte c1, c2, c3, c4, o; byte c1, c2, c3, c4, o;
@ -486,7 +486,7 @@ public class BCryptService {
* @param lr an array containing the two 32-bit half blocks * @param lr an array containing the two 32-bit half blocks
* @param off the position in the array of the blocks * @param off the position in the array of the blocks
*/ */
private final void encipher(int lr[], int off) { private void encipher(int lr[], int off) {
int i, n, l = lr[off], r = lr[off + 1]; int i, n, l = lr[off], r = lr[off + 1];
l ^= P[0]; l ^= P[0];
@ -534,8 +534,8 @@ public class BCryptService {
* Initialise the Blowfish key schedule * Initialise the Blowfish key schedule
*/ */
private void init_key() { private void init_key() {
P = (int[])P_orig.clone(); P = P_orig.clone();
S = (int[])S_orig.clone(); S = S_orig.clone();
} }
/** /**
@ -653,8 +653,8 @@ public class BCryptService {
String real_salt; String real_salt;
byte passwordb[], saltb[], hashed[]; byte passwordb[], saltb[], hashed[];
char minor = (char)0; char minor = (char)0;
int rounds, off = 0; int rounds, off;
StringBuffer rs = new StringBuffer(); StringBuilder rs = new StringBuilder();
if (salt.charAt(0) != '$' || salt.charAt(1) != '2') if (salt.charAt(0) != '$' || salt.charAt(1) != '2')
throw new IllegalArgumentException ("Invalid salt version"); throw new IllegalArgumentException ("Invalid salt version");
@ -684,8 +684,7 @@ public class BCryptService {
saltb = decode_base64(real_salt, BCRYPT_SALT_LEN); saltb = decode_base64(real_salt, BCRYPT_SALT_LEN);
B = new BCryptService(); B = new BCryptService();
hashed = B.crypt_raw(passwordb, saltb, rounds, hashed = B.crypt_raw(passwordb, saltb, rounds, bf_crypt_ciphertext.clone());
(int[])bf_crypt_ciphertext.clone());
rs.append("$2"); rs.append("$2");
if (minor >= 'a') if (minor >= 'a')
@ -714,7 +713,7 @@ public class BCryptService {
* @return an encoded salt value * @return an encoded salt value
*/ */
public static String gensalt(int log_rounds, SecureRandom random) { public static String gensalt(int log_rounds, SecureRandom random) {
StringBuffer rs = new StringBuffer(); StringBuilder rs = new StringBuilder();
byte rnd[] = new byte[BCRYPT_SALT_LEN]; byte rnd[] = new byte[BCRYPT_SALT_LEN];
random.nextBytes(rnd); random.nextBytes(rnd);