Reputation: 639
I have a query about the default AES key length and symmetric/asymmetric mode in javax.crypto.Cipher library.
I created a cipher as follows (I am in Java8 & Scala 2.12.x):
val mycipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
mycipher.init(Cipher.ENCRYPT_MODE, givemeKey(), givemeIV())
private def givemeKey(keyPass: Option[String] = None) = {
new SecretKeySpec(new BASE64Decoder().decodeBuffer('XxXxXxYyYyYXxZzZz-5z3y**\n'), "AES")
}
private def givemeIV() = {
val myuuid = UUID.randomUUID().toString.split("-").mkString("").getBytes()
val mybyteIV = new Array[Byte](16)
System.arraycopy(myuuid, 0, mybyteIV, 0, 16)
val returnIV = new IvParameterSpec(mybyteIV)
returnIV
}
I did look into documentations of Cipher package. Still I have two questions which I can not able to figure out, hence reaching out to you:
Upvotes: 1
Views: 1133
Reputation: 719346
According to the javadocs for javax.crypto.Cipher
, that string ("AES/CBC/PKCS5Padding"
) gives you an AES cipher algorithm.
There isn't a default key length. (But there is a guarantee that every standard Java SE platform supports AES keys of 128 bits. Some Java SE platforms support other AES key lengths (192 & 256) as well.)
The actual key length is not part of the algorithm name / Cipher
object. It will depend on whatever key that givemeKey
is returning. However in your example the base64 encoded key string is 24 characters long so that means it could not possibly be a 265 bit key.
(Do the math. 6 bits per character x 24 characters == 144 bits max. So assuming that some of those bits are "envelope" or "padding", that looks like it would be an 128 bit key.)
AES is a symmetric-key algorithm; see Wikipedia.
Upvotes: 2