forked from Archives/Athou_commafeed
fix findbugs warnings
This commit is contained in:
@@ -57,32 +57,32 @@ public class PasswordEncryptionService {
|
|||||||
KeySpec spec = new PBEKeySpec(password.toCharArray(), salt, iterations,
|
KeySpec spec = new PBEKeySpec(password.toCharArray(), salt, iterations,
|
||||||
derivedKeyLength);
|
derivedKeyLength);
|
||||||
|
|
||||||
SecretKey key = null;
|
byte[] bytes = null;
|
||||||
try {
|
try {
|
||||||
SecretKeyFactory f = SecretKeyFactory.getInstance(algorithm);
|
SecretKeyFactory f = SecretKeyFactory.getInstance(algorithm);
|
||||||
key = f.generateSecret(spec);
|
SecretKey key = f.generateSecret(spec);
|
||||||
|
bytes = key.getEncoded();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// should never happen
|
// should never happen
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
return bytes;
|
||||||
return key.getEncoded();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] generateSalt() {
|
public byte[] generateSalt() {
|
||||||
// VERY important to use SecureRandom instead of just Random
|
// VERY important to use SecureRandom instead of just Random
|
||||||
SecureRandom random = null;
|
|
||||||
|
byte[] salt = null;
|
||||||
try {
|
try {
|
||||||
random = SecureRandom.getInstance("SHA1PRNG");
|
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
|
||||||
|
|
||||||
|
// Generate a 8 byte (64 bit) salt as recommended by RSA PKCS5
|
||||||
|
salt = new byte[8];
|
||||||
|
random.nextBytes(salt);
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
// should never happen
|
// should never happen
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate a 8 byte (64 bit) salt as recommended by RSA PKCS5
|
|
||||||
byte[] salt = new byte[8];
|
|
||||||
random.nextBytes(salt);
|
|
||||||
|
|
||||||
return salt;
|
return salt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user