乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      InvalidKeyException java.security.InvalidKeyException:沒有安裝的提供程序支持此密鑰:(空)

       印度阿三17 2019-10-29

      我有兩個類,一個是主類,另一個是AES的實現(xiàn).

      但是,在我的AES類中,我有一種解密字符串的方法,但是每當(dāng)我運(yùn)行它時,它都會產(chǎn)生異常

      我的加密方法工作正常,但我的解密方法無法正常工作.

      編碼

      private Cipher aesCipherForDecryption;
      String strDecryptedText = new String();
      
      public String decryptAES(final String ciphertext) {
      
          try {
      
              aesCipherForDecryption = Cipher.getInstance("AES/CBC/PKCS5PADDING");
              aesCipherForDecryption.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(iV));
              byte[] byteDecryptedText = aesCipherForDecryption.doFinal(byteCipherText);
              strDecryptedText = new String(byteDecryptedText);
      
          } catch (IllegalBlockSizeException e) {
              System.out.print("IllegalBlockSizeException "  e);
          } catch (BadPaddingException e) {
              System.out.print("BadPaddingException " e);
          } catch (NoSuchAlgorithmException e) {
              System.out.print("NoSuchAlgorithmException "  e);
          } catch (NoSuchPaddingException e) {
              System.out.print("NoSuchPaddingException " e);
          } catch (InvalidKeyException e) {
              System.out.print("InvalidKeyException " e);
          } catch (InvalidAlgorithmParameterException e) {
              System.out.print("InvalidAlgorithmParameterException " e);
          }
      
          System.out.println("\nDecrypted Text message is "   strDecryptedText);
          return strDecryptedText;
      }
      

      該方法輸出的錯誤是

      InvalidKeyException java.security.InvalidKeyException: No installed provider supports this key: (null)

      更新#1:

      所以我更新了以下代碼

      public String decryptAES(byte[] ciphertext) {
          String strDecryptedText = new String();
              try {
                  byte[] byteDecryptedText = aesCipherForDecryption.doFinal(ciphertext);
      
                  strDecryptedText = new String(byteDecryptedText);
      
              } catch (IllegalBlockSizeException e) {
                  System.out.print("IllegalBlockSizeException " e);
                  e.printStackTrace();
              } catch (BadPaddingException e) {
                  System.out.print("BadPaddingException " e);
                  e.printStackTrace();
              }
      
          System.out.println("\nDecrypted Text message is "   strDecryptedText);
          return strDecryptedText;
      }    
      

      在主班我有這條線

      byte [] byteciphertext = ciphertext.getBytes();
      

      只是將字符串轉(zhuǎn)換為字節(jié)

      這是正確的嗎?我還有

      IllegalBlockSizeException javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipherjavax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher
      

      有人可以幫我解決這個問題嗎?

      謝謝.

      解決方法:

      secretKey顯然為null.

      其他問題:

      >您沒有使用輸入?yún)?shù)cipherText.
      >輸入?yún)?shù)cipherText應(yīng)該是byte [],而不是字符串:密文是二進(jìn)制的,并且String不是二進(jìn)制數(shù)據(jù)的容器.
      >結(jié)果字符串strDecryptedText應(yīng)該是局部變量,而不是成員變量.

      來源:https://www./content-1-531851.html

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多