问题
My app is minSDK 15 - so I thought I can use BouncyCastle directly. Unfortunately I get a NoSuchAlgorithmException. Do I have to use SpongyCastle then? The lib works great in a JVM app - but fails on android.
Caused by: java.security.NoSuchAlgorithmException: no such algorithm: ECDSA for provider BC
at sun.security.jca.GetInstance.getService(GetInstance.java:87)
at sun.security.jca.GetInstance.getInstance(GetInstance.java:206)
at java.security.KeyPairGenerator.getInstance(KeyPairGenerator.java:307)
at org.kethereum.crypto.Keys.createSecp256k1KeyPair$crypto(Keys.kt:43)
at org.kethereum.crypto.Keys.createEcKeyPair(Keys.kt:51)
at org.walleth.data.keystore.KethereumWallethKeyStore.newAddress(KethereumWallethKeyStore.kt:43)
at org.walleth.activities.CreateAccountActivity$onCreate$4.onClick(CreateAccountActivity.kt:95)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24701)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
回答1:
Android support for ECDSA was introduced since version 4.0 using Bouncycastle (v1.46) as the default cryptographic provider. See the blog https://nelenkov.blogspot.com.es/2011/12/using-ecdh-on-android.html?m=1
But Android included a shortened version of Bouncycastle, and there is no full support for ECDSA. You can see in the link that algorithm KeyPairGenerator/ECDSA is not supported, which is the required one to generate ethereum keys.
You can not include directly the bouncycastle library because there is a conflict with the package name org.bouncycastle. I suggest to include spongycastle in your project, which it is a repackaged version of bouncycastle for Android org.spongycastle.
The package name conflict has been resolved in new android versions, but if your target are old versions then you need to ensure which cryptographic provider is being used.
来源:https://stackoverflow.com/questions/47565574/no-such-algorithm-ecdsa-for-provider-bc