What does "SecretKeyFactory unavailable" mean?

What happened to this?

for (Object obj : java.security.Security.getAlgorithms("Cipher")) {
  System.out.println(obj);
}
javax.crypto.SecretKeyFactory.getInstance("AES");

This is the output (JDK 1.6 on Mac OS 10.6):

BLOWFISH
ARCFOUR
PBEWITHMD5ANDDES
RC2
RSA
PBEWITHMD5ANDTRIPLEDES
PBEWITHSHA1ANDDESEDE
DESEDE
AESWRAP
AES
DES
DESEDEWRAP
PBEWITHSHA1ANDRC2_40

java.security.NoSuchAlgorithmException: AES SecretKeyFactory not available
 at javax.crypto.SecretKeyFactory.<init>(DashoA13*..)
 at javax.crypto.SecretKeyFactory.getInstance(DashoA13*..)
 ...
+5
source share
3 answers

This is a validated Java bug. See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7022467

EDIT: Different versions of Java support different algorithms, you can also extend them with custom providers and so on. Oracle has a list for java 6 here http://docs.oracle.com/javase/6/docs/technotes/guides/security/SunProviders.html . For KeyFactory, this is a DSA.

+5
source

You do not need to use SecretKeyFactory. You can create an AES key with the following:

byte[] keyData = ........ 
SecretKeySpec key = new SecretKeySpec(keyData, "AES");

(PBE), , , . , 256- AES, ;

private Key buildKey(String password) throws NoSuchAlgorithmException, UnsupportedEncodingException {
  MessageDigest digester = MessageDigest.getInstance("SHA-256");
  digester.update(password.getBytes("UTF-8"));
  byte[] key = digester.digest();
  SecretKeySpec spec = new SecretKeySpec(key, "AES");
  return spec;
}

Edit:
MD5 DES, , .

+4

Java SecretKeyFactory "AES" .

, (128, 192 256) SecureRandom SecretKeySpec.

If you use password-based encryption, create SecretKeyFactoryPBKDF2WithHmacSHA1 for the algorithm and use it to initialize the instance SecretKeySpecas shown here.

+2
source

All Articles