Nak*_*oto 2 java algorithm rsa cordova ionic-framework
所以这就是我尝试过的
keytool -genkey -v -keystore my-release-key.jks -keyalg RSA -keysize 2048 -validity 10000
Run Code Online (Sandbox Code Playgroud)
但我得到了这个..
keytool error: java.security.NoSuchAlgorithmException: RSA KeyGenerator not available
java.security.NoSuchAlgorithmException: RSA KeyGenerator not available
Run Code Online (Sandbox Code Playgroud)
我该怎么办 ?
ps 使用:jdk1.8.0_121
keytool -genkey -v -keystore my-release-key.jks -keyalg RSA -keysize 2048 -validity 10000执行命令时没有错误,这是输出的示例。
Generating 2,048 bit RSA key pair and self-signed certificate (SHA256withRSA) with a validity of 10,000 days for: CN=a, OU=a, O=a, L=a, ST=a, C=a
Enter key password for <mykey>
(RETURN if same as keystore password):
[Storing my-release-key.jks]
Run Code Online (Sandbox Code Playgroud)
但是是什么导致的java.security.NoSuchAlgorithmException: RSA KeyGenerator not available?
此错误意味着 keytool 尝试通过 RSA 无效算法实例化 KeyGenerator 对象。为什么 RSA 是 KeyGenerator 的无效算法?这是因为 RSA 是一种用于非对称密钥的算法,而 KeyGenerator 是一个创建对称密钥的类。
现在让我们做一些测试来阐明想法并使用 RSA 创建一个 KeyGenerator 对象:
public class KeyGeneratorTest {
public static void main(String[] args) {
try {
KeyGenerator keyGeneratorTest=KeyGenerator.getInstance("RSA");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
前面的代码生成与问题中报告的相同的异常:
java.security.NoSuchAlgorithmException: RSA KeyGenerator not available
at javax.crypto.KeyGenerator.<init>(KeyGenerator.java:169)
at javax.crypto.KeyGenerator.getInstance(KeyGenerator.java:223)
Run Code Online (Sandbox Code Playgroud)
现在我将尝试使用 keytool 和 RSA 算法参数创建一个对称密钥。
keytool -genseckey -alias mytest2 -keyalg RSA -keysize 192 -storetype JCEKS
Run Code Online (Sandbox Code Playgroud)
输出与问题报告的完全相同。
keytool error: java.security.NoSuchAlgorithmException: RSA KeyGenerator not available
Run Code Online (Sandbox Code Playgroud)
抛出错误是因为内部keytool -genseckey命令尝试使用 RSA 算法参数 ( -keyalg RSA)创建 KeyGenerator 对象,并且正如我所提到的,RSA 不是用于创建对称密钥的有效算法。
请访问以下文档以了解有关 keytool 的更多信息。 Java 标准算法名称列表、NoSuchAlgorithmException 文档、Keytool 源代码和Keytool 参考文档