Is Java security module KeyGenerator thread safe? If not then how to fix it?
问题 I have a concurrent encryption/decryption program in which multiple AES128 keys are randomly generated concurrently by invoking the following code (written in scala, the Java version should be fairly similar): private def AESKeyGen: KeyGenerator = { val keyGen = KeyGenerator.getInstance("AES") keyGen.init(128) keyGen } def generateKey: SecretKey = this.synchronized { AESKeyGen.generateKey() } each key is use to encrypt a fixed byte array, then decrypt it by using AESEncrypt and AESDecrypt