I cannot find anywhere if every Java platform implementation must come with an AES implementation too.
I want to use the following code on Android:
SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
decrypted = cipher.doFinal(encryptedData);
However, I cannot find if "AES" is guaranteed to be implemented (like the "SHA-1" algorithm is guaranteed to be implemented on every Java platform as per this quote:
"Every implementation of the Java platform is required to support the following standard MessageDigest algorithms: MD5 SHA-1 SHA-256"
(Font: http://docs.oracle.com/javase/7/docs/api/java/security/MessageDigest.html).
Does anybody know if an AES implementation is guaranteed to come with Java (or even with Android, which is where I want to use it)?
For Java, look in the Cipher section of the JCA standard names. It lists AES as one of the standard encryption algorithms. Also look in the Implementation sections of the same document. In there, it lists the minimal encryption transformations required for all Java runtimes. The list includes:
So, AES is guaranteed to be supported in either CBC or ECB mode with either PKCS5 or no padding. The only key size guaranteed to be supported is 128-bit.
Now, Android is technically not a Java runtime so is not bound to the JCA requirements. However, most likely AES is supported in one mode or another because it is included as an example in Android's API documentation. To get a full list of available encryption transformations, use the following code:
public void ListSupportedAlgorithms() {
String result = "";
// get all the providers
Provider[] providers = Security.getProviders();
for (int p = 0; p < providers.length; p++) {
// get all service types for a specific provider
Set<Object> ks = providers[p].keySet();
Set<String> servicetypes = new TreeSet<String>();
for (Iterator<Object> it = ks.iterator(); it.hasNext();) {
String k = it.next().toString();
k = k.split(" ")[0];
if (k.startsWith("Alg.Alias."))
k = k.substring(10);
servicetypes.add(k.substring(0, k.indexOf('.')));
}
// get all algorithms for a specific service type
int s = 1;
for (Iterator<String> its = servicetypes.iterator(); its.hasNext();) {
String stype = its.next();
Set<String> algorithms = new TreeSet<String>();
for (Iterator<Object> it = ks.iterator(); it.hasNext();) {
String k = it.next().toString();
k = k.split(" ")[0];
if (k.startsWith(stype + "."))
algorithms.add(k.substring(stype.length() + 1));
else if (k.startsWith("Alg.Alias." + stype +"."))
algorithms.add(k.substring(stype.length() + 11));
}
int a = 1;
for (Iterator<String> ita = algorithms.iterator(); ita.hasNext();) {
result += ("[P#" + (p + 1) + ":" + providers[p].getName() + "]" +
"[S#" + s + ":" + stype + "]" +
"[A#" + a + ":" + ita.next() + "]\n");
a++;
}
s++;
}
}
(copied from Android Encryption with the Android Cryptography API)
There should be several AES transformations in that list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With