-1

First, i ran this:

public static void main(String[] args)
  {
    for (Provider provider: Security.getProviders()) {
      System.out.println(provider.getName());
      for (String key: provider.stringPropertyNames())
        System.out.println("\t" + key + "\t" + provider.getProperty(key));
    }
  }

Got:

Cipher.AES SupportedModes   ECB|CBC|PCBC|CTR|CTS|CFB|OFB|CFB8|CFB16|CFB24|CFB32|CFB40|CFB48|CFB56|CFB64|OFB8|OFB16|OFB24|OFB32|OFB40|OFB48|OFB56|OFB64|CFB72|CFB80|CFB88|CFB96|CFB104|CFB112|CFB120|CFB128|OFB72|OFB80|OFB88|OFB96|OFB104|OFB112|OFB120|OFB128
    Cipher.AES_128/OFB/NoPadding    com.sun.crypto.provider.AESCipher$AES128_OFB_NoPadding
    Cipher.AESWrap SupportedModes   ECB
    Cipher.AES SupportedKeyFormats  RAW
    Cipher.AES  com.sun.crypto.provider.AESCipher$General
    Provider.id info    SunJCE Provider (implements RSA, DES, Triple DES, AES, Blowfish, ARCFOUR, RC2, PBE, Diffie-Hellman, HMAC)
    Cipher.AES SupportedPaddings    NOPADDING|PKCS5PADDING|ISO10126PADDING

But when I try to getInstance() of Cipher "AES/ECB/PKCS5PADDING", it jump to exception:

test.java:43: error: unreported exception NoSuchAlgorithmException; must be caught or declared to be thrown
        Cipher cip = Cipher.getInstance("AES/ECB/PKCS5PADDING");
  • 1
    Possible duplicate of [Why do I get "Exception; must be caught or declared to be thrown" when I try to compile my Java code?](http://stackoverflow.com/questions/908672/why-do-i-get-exception-must-be-caught-or-declared-to-be-thrown-when-i-try-to) – Savior Apr 08 '16 at 16:47
  • No. You're saying the difference thing. I mean that javax.crypto support to AES algorith/ECB mode/PKCS5PADDING, but why exception occurred? – Tạ Quang Khánh Apr 08 '16 at 16:53
  • 1
    The compiler is raising an error, an exception is not being thrown. – Darth Android Apr 08 '16 at 16:54
  • @DarthAndroid Okay i known it bro, but it isn't my question – Tạ Quang Khánh Apr 08 '16 at 16:57
  • 1
    Then change your question. Because right now you're asking about a compilation error. – Savior Apr 08 '16 at 16:59
  • Engligh isn't my primary language, so I don't know how to explain clearly in the question title, can you give me? @Pillar – Tạ Quang Khánh Apr 08 '16 at 17:01
  • 1
    You seem to be asking about the error `unreported exception NoSuchAlgorithmException; must be caught or declared to be thrown`. That is a compilation error. That is already answered in the linked duplicate. You're not handling the exception in the source code. – Savior Apr 08 '16 at 17:02
  • Have you read my question at all? – Tạ Quang Khánh Apr 08 '16 at 17:04
  • 1
    I literally copy-pasted the error you have in your question body. – Savior Apr 08 '16 at 17:06
  • Im not expecting any answer that such like `you didn't thrown exception` or `you didn't handled exception`. I want to know why exception occurred... – Tạ Quang Khánh Apr 08 '16 at 17:08
  • 1
    You haven't shown any exception occurring...You've shown a compilation error that indicates you didn't handle an exception either with a `try-catch` or with a `throws` declaration. I don't know what else to tell you. – Savior Apr 08 '16 at 17:09
  • Okay, won't the compilation error tell that exception occur? If i use `try-catch`, then surely jump to exception :) – Tạ Quang Khánh Apr 08 '16 at 17:21
  • 1
    No. You're confusing compile time and runtime. A compilation error tells you that your source code is invalid Java code. A thrown exception during program execution tells you that something misbehaved at runtime. – Savior Apr 08 '16 at 17:23
  • Ah, sorry. I know, but, again, quite difficult for me to explain. I mean the first code snipet show my java system does support AES algorithm/ECB mode and PKCS5PADDING, so why this compilation error occurred... – Tạ Quang Khánh Apr 08 '16 at 18:04
  • :( Because you haven't handled the possible exception with a `throws` or a `try-catch`.............. – Savior Apr 08 '16 at 18:05
  • Oh, gotcha... So now i know that when handled possible exception will avoid this compilation error. Thank you very much. BTW, Sorry for anything make you uncomfortable from starting of conversion :) – Tạ Quang Khánh Apr 08 '16 at 18:24

1 Answers1

-1

Take a look at Cipher Algorithm Names in the documentation. You're getting a list of providers, not Ciphers.

stdunbar
  • 16,263
  • 11
  • 31
  • 53