- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用导入的 keystore key 对一段数据进行签名:
我的 key 首先在 AndroidKeyStore 之外生成(这是故意的)
然后导入到AndroidKeyStore
使用以下方式:
val keyGen = KeyPairGenerator.getInstance("RSA")
keyGen.initialize(2048)
val keyPair = keyGen.generateKeyPair()
val keyProtectionSign = KeyProtection.Builder(KeyProperties.PURPOSE_SIGN or //
KeyProperties.PURPOSE_VERIFY).setDigests(KeyProperties.DIGEST_SHA256) //
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1) //
.setSignaturePaddings(KeyProperties.SIGNATURE_PADDING_RSA_PKCS1)
.build()
keyStore.setEntry(signatureAlias,
KeyStore.PrivateKeyEntry(keyPair.private, arrayOf(certificate)),
keyProtectionSign)
val keyStore = KeyStore.getInstance("AndroidKeyStore")
keyStore.load(null)
val privateKey = keyStore.getKey(signatureAlias,null)
val signature = Signature.getInstance("SHA256withRSA")
signature.initSign(privateKey)
signature.update(data)
val sign = signature.sign()
signature.initSign(privateKey)
抛出异常:
java.security.InvalidKeyException: Supplied key (android.security.keystore.AndroidKeyStoreRSAPrivateKey) is not a RSAPrivateKey instance
最佳答案
尝试查看此线程中讨论的问题:
https://markmail.org/message/4omngfbqzdq3wk3b#query:+page:1+mid:ne47xbhggf6samib+state:results
Unfortunately, Bouncy Castle JCA Provider has a bug (http://www.bouncycastle.org/jira/browse/BJA-543 https://www.google.com/url?q=http://www.bouncycastle.org/jira/browse/BJA-543&sa=D&usg=AFQjCNEErNOODYZHHZomGgR1y7NLq2yegw) where is advertises to JCA that it can handle any keys, even those that it actually can't handle
...
If you must install the Bouncy Castle JCA Provider, install it below Android Keystore JCA provider. The best way to achieve that is to find the index at which the platform-bundled Bouncy Castle provider is installed, and then invoke Security.insertProviderAt with that same index and your Bouncy Castle Provider.
关于android - 无法使用导入到 AndroidKeyStore RSA 私钥进行签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59131150/
我是一名优秀的程序员,十分优秀!