gpt4 book ai didi

java - Bouncy CaSTLe 提供程序在标准 java 中工作时抛出 NoSuchAlgorithmException

转载 作者:行者123 更新时间:2023-12-02 11:20:26 24 4
gpt4 key购买 nike

我正在尝试在android中使用jwt身份验证来实现box-java-sdk。当 sdk 尝试解密这些行中的私钥时:

InputDecryptorProvider pkcs8Prov = new JceOpenSSLPKCS8DecryptorProviderBuilder().setProvider("BC")
.build(this.privateKeyPassword.toCharArray());
PrivateKeyInfo keyInfo = ((PKCS8EncryptedPrivateKeyInfo) keyPair).decryptPrivateKeyInfo(pkcs8Prov);
decryptedPrivateKey = (new JcaPEMKeyConverter()).getPrivateKey(keyInfo);

发生以下异常:

W/System.err: com.box.sdk.BoxAPIException: Error parsing PKCS private key for Box Developer Edition.
W/System.err: at com.box.sdk.BoxDeveloperEditionAPIConnection.decryptPrivateKey(BoxDeveloperEditionAPIConnection.java:516)
W/System.err: at com.box.sdk.BoxDeveloperEditionAPIConnection.constructJWTAssertion(BoxDeveloperEditionAPIConnection.java:450)
W/System.err: at com.box.sdk.BoxDeveloperEditionAPIConnection.constructJWTAssertion(BoxDeveloperEditionAPIConnection.java:431)
W/System.err: at com.box.sdk.BoxDeveloperEditionAPIConnection.authenticate(BoxDeveloperEditionAPIConnection.java:320)
W/System.err: at com.box.sdk.BoxDeveloperEditionAPIConnection.tryRestoreUsingAccessTokenCache(BoxDeveloperEditionAPIConnection.java:419)
W/System.err: at com.box.sdk.BoxDeveloperEditionAPIConnection.getAppUserConnection(BoxDeveloperEditionAPIConnection.java:271)
W/System.err: at com.box.sdk.BoxDeveloperEditionAPIConnection.getAppUserConnection(BoxDeveloperEditionAPIConnection.java:296)
W/System.err: at com.kapalya.box.BoxClient$1.inBackgroud(BoxClient.java:41)
W/System.err: at com.kapalya.box.BoxClient$4.doInBackground(BoxClient.java:111)
W/System.err: at com.kapalya.box.BoxClient$4.doInBackground(BoxClient.java:107)
W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:295)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
W/System.err: at java.lang.Thread.run(Thread.java:818)
W/System.err: Caused by: org.bouncycastle.pkcs.PKCSException: unable to read encrypted data: 1.2.840.113549.1.5.13 not available: Provider BC does not provide 1.2.840.113549.3.7
W/System.err: at org.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfo.decryptPrivateKeyInfo(Unknown Source)
W/System.err: at com.box.sdk.BoxDeveloperEditionAPIConnection.decryptPrivateKey(BoxDeveloperEditionAPIConnection.java:505)
W/System.err: ... 15 more
W/System.err: Caused by: org.bouncycastle.operator.OperatorCreationException: 1.2.840.113549.1.5.13 not available: Provider BC does not provide 1.2.840.113549.3.7
W/System.err: at org.bouncycastle.openssl.jcajce.JceOpenSSLPKCS8DecryptorProviderBuilder$1.get(Unknown Source)
W/System.err: ... 17 more
W/System.err: Caused by: java.security.NoSuchAlgorithmException: Provider BC does not provide 1.2.840.113549.3.7
W/System.err: at javax.crypto.Cipher.getCipher(Cipher.java:357)
W/System.err: at javax.crypto.Cipher.getInstance(Cipher.java:325)
W/System.err: at javax.crypto.Cipher.getInstance(Cipher.java:297)
W/System.err: at org.bouncycastle.jcajce.util.NamedJcaJceHelper.createCipher(Unknown Source)
W/System.err: ... 18 more

虽然这个 sdk 在标准 java 应用程序中运行良好。 Android 的 BountyCaSTLe 提供者的实现有什么变化吗?这个问题有解决方法吗?

最佳答案

首先删除 BountyCaSTLe 的 Android 实现来让它工作:

Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME);

因此注册 BouncyCaSTLeProvider 的静态 block 变为:

static {
Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME);
Security.addProvider(new BouncyCastleProvider());
}

关于java - Bouncy CaSTLe 提供程序在标准 java 中工作时抛出 NoSuchAlgorithmException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49959611/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com