0

I'm working on a simple program that does nothing except generate and output a pair of keys:

public class keyWriter {

    public static KeyPairGenerator k;
    static {
        try {
            k = KeyPairGenerator.getInstance("AES");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }

    public static void writeKey() throws FileNotFoundException, IOException{
        //implement output
    }

    public static void main(String[] args){
        try{
            writeKey();
        } catch (Exception e){}
    }       
}

When I try and run this code, I get the following exception:

java.security.NoSuchAlgorithmException: AES KeyPairGenerator not available at 
java.base/java.security.KeyPairGenerator.getInstance(KeyPairGenerator.java:236)
    at keyWriter.<clinit><keyWriter.java:24> 
//line 24 is the line "k = KeyPairGenerator.getInstance("AES");"

I don't know how to interpret this; I'm running Java 9.0.1 on Windows 8.1 and have imported the security package, so I'm quite sure everything should be on my machine. What would lead to this exception, and how can I solve it?

MMMMMCK
  • 307
  • 3
  • 14
  • "AES" doesn't appear to be a valid algorithm name for that function: [doc link](https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator) – luckydog32 Nov 10 '17 at 01:23
  • Ah, you're right! I switched it to DSA and was successful , thanks. If you make this an answer I'll accept it in a bit – MMMMMCK Nov 10 '17 at 01:30
  • I appreciate the thought, but I wouldn't feel comfortable giving an answer to this question, since it's not something that I know much about. I'm glad it helped though. – luckydog32 Nov 10 '17 at 01:33
  • If you need a key pair and you're going for one of the algorithms that are supported out of the box, you're probably better off using a 2048 bit RSA key instead of a DSA key. – Robby Cornelissen Nov 10 '17 at 01:38

0 Answers0