java.security.invalidkeyexception:没有安装的提供程序支持此密钥:javax.crypto.spec.secretkeyspec

hfyxw5xn  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(618)

我在第一次运行vm时遇到了这个错误。但是当我重新启动java进程时,它就变得正常了(不再出错)。太奇怪了,我还是不明白。请帮帮我。
我的代码:

private def key16(): String =
    "%16s".format(cipherKey)

  def encrypt(key: Array[Byte], input: Array[Byte]): Try[Array[Byte]] =
    Try{
      val secretBytes = new SecretKeySpec(key, "AES")
      cipher.init(Cipher.ENCRYPT_MODE, secretBytes, new SecureRandom())
      cipher.getIV ++ cipher.doFinal(input)
    } recoverWith {
      case e: Throwable =>
        e.printStackTrace()
        Failure(new CipherFailedException("Encryption failed", e))
    }
Caused by: java.security.InvalidKeyException: No installed provider supports this key: javax.crypto.spec.SecretKeySpec
    at javax.crypto.Cipher.chooseProvider(Cipher.java:892) ~[na:1.8.0_191]
    at javax.crypto.Cipher.init(Cipher.java:1248) ~[na:1.8.0_191]

java版本为:

java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题