我克隆了一个已经创建的项目,但未能在 release.keystore 中构建应用程序。 所以我再次生成密钥库仍然遇到同样的问题 ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
我正在尝试将RSA加密与KeyStore结合使用,并且需要为KeyPairGenerator
指定参数,而我在这里迷路了。 KeyPairGeneratorPair
有点简单,但是我不理解API> = 23的KeyGenParameterSpec
这就是我所做的,我想我得到了一切else
部分,但现在我感到困惑KeyGenParameterSpec
RSAKeyGenParameterSpec
确切的公共指数是什么?
我应该在.setDigests
指定哪些摘要?
还有.setBlockMode()
方法要调用,并且由于我使用的是RSA和RSA/None/OAEPWithSHA1AndMGF1Padding
,因此要设置哪个阻止模式? 欧洲央行,加拿大广播公司?
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
generator.initialize(new KeyGenParameterSpec.Builder("PrivateKey", KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
.setAlgorithmParameterSpec(new RSAKeyGenParameterSpec(2048, RSAKeyGenParameterSpec.F4))
.setDigests(KeyProperties.DIGEST_SHA1,
KeyProperties.DIGEST_SHA256)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_OAEP)
.setCertificateSerialNumber(BigInteger.ONE)
.setCertificateSubject(new X500Principal("CN=" + "PrivateKey"))
.setCertificateNotBefore(calendar.getTime())
.setCertificateNotAfter(endCalendar.getTime())
.setKeySize(2048).build());
} else {
generator.initialize(new KeyPairGeneratorSpec.Builder(MainActivity.this)
.setAlias("PrivateKey")
.setSerialNumber(BigInteger.ONE)
.setSubject(new X500Principal("CN=" + "PrivateKey"))
.setStartDate(calendar.getTime())
.setEndDate(endCalendar.getTime())
.setKeySize(2048).build()
);
}
Cipher cipher = Cipher.getInstance("RSA/None/OAEPWithSHA1AndMGF1Padding");
方法setDigests()
设置填充模式的摘要方法,而setBlockMode()
设置加密模式,具体取决于您的工作。
我认为您设置了很多不必要的字段。 例如,我使用此方法创建自己的RSA
密钥:
public boolean createKey() {
try {
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(
KeyProperties.KEY_ALGORITHM_RSA,
"AndroidKeyStore"
);
mKeyStore.load(null);
KeyGenParameterSpec.Builder builder =
new KeyGenParameterSpec.Builder(
MY_KEY,
KeyProperties.PURPOSE_DECRYPT).
setKeySize(MY_KEYLEN).
setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_OAEP).
setDigests(KeyProperties.DIGEST_SHA256);
keyPairGenerator.initialize(builder.build());
keyPairGenerator.generateKeyPair();
} catch (NoSuchAlgorithmException | CertificateException | IOException |
InvalidAlgorithmParameterException | NoSuchProviderException e) {
return false;
}
return true;
}
我创建了此密钥以用于RSA/ECB/OAEPWithSHA-256AndMGF1Padding
算法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.