我正在尝试在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提供程序的实现有什么变化吗?这个问题有解决方法吗?
答案 0 :(得分:1)
通过首先删除BountyCastle的Android实现来实现它:
Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME);
因此注册BouncyCastleProvider的静态块变为:
static {
Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME);
Security.addProvider(new BouncyCastleProvider());
}