为什么在提供者可用时获得NoSuchAlgorithmException

时间:2016-04-08 16:45:53

标签: java algorithm exception encryption cryptography

首先,我跑了这个:

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

但是当我尝试getInstance() Cipher“AES / ECB / PKCS5PADDING”时,它会跳转到异常:

test.java:43: error: unreported exception NoSuchAlgorithmException; must be caught or declared to be thrown
        Cipher cip = Cipher.getInstance("AES/ECB/PKCS5PADDING");

1 个答案:

答案 0 :(得分:-1)

请查看文档中的Cipher Algorithm Names。你得到的是提供者列表,而不是密码。