我想加密/解密密码以使用 AES(Java API)将其存储在数据库中,如下所示:
try {
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
byte[] salt = new byte[10];
secureRandom.nextBytes(salt);
byte[] encryptedPassword = //some method to mix salt with plain password
Cipher cipher = Cipher.getInstance("AES");
SecretKeySpec skeySpec = new SecretKeySpec(secretKey.getEncoded(), "AES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
return cipher.doFinal(encryptedPassword);
} catch (NoSuchAlgorithmException |
UnsupportedEncodingException |
NoSuchPaddingException |
InvalidKeyException |
IllegalBlockSizeException |
BadPaddingException ex) {
//Logger...
}
我的问题是——我可以在商业应用中免费使用 AES 吗?如何改进上面的代码?