Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECDSA implementation not found in 4.1.0-android #828

Closed
WarSame opened this issue Dec 27, 2018 · 24 comments
Closed

ECDSA implementation not found in 4.1.0-android #828

WarSame opened this issue Dec 27, 2018 · 24 comments

Comments

@WarSame
Copy link

WarSame commented Dec 27, 2018

I am getting an exception on Android when trying to generate a new light wallet using 4.1.0-android. This is code that previously used to work:

this.fileName = WalletUtils.generateLightNewWalletFile(longPassword, getWalletDir(context));

longPassword is a String, getWalletDir returns a directory to store all of the wallet files in.

W/System.err: java.security.NoSuchAlgorithmException: KeyPairGenerator ECDSA implementation not found
        at org.apache.harmony.security.fortress.Engine.notFound(Engine.java:190)
W/System.err:     at org.apache.harmony.security.fortress.Engine.getInstance(Engine.java:183)
W/System.err:     at java.security.KeyPairGenerator.getInstance(KeyPairGenerator.java:149)
W/System.err:     at java.security.KeyPairGenerator.getInstance(KeyPairGenerator.java:122)
        at org.web3j.crypto.Keys.createSecp256k1KeyPair(Keys.java:58)
        at org.web3j.crypto.Keys.createEcKeyPair(Keys.java:75)
        at org.web3j.crypto.Keys.createEcKeyPair(Keys.java:70)
        at org.web3j.crypto.WalletUtils.generateNewWalletFile(WalletUtils.java:61)
W/System.err:     at org.web3j.crypto.WalletUtils.generateLightNewWalletFile(WalletUtils.java:47)
        at com.example.graeme.beamitup.wallet.Wallet.<init>(Wallet.java:43)
W/System.err:     at com.example.graeme.beamitup.wallet.Wallet.<init>(Wallet.java:22)
        at com.example.graeme.beamitup.wallet.Wallet$WalletBuilder.build(Wallet.java:161)
        at com.example.graeme.beamitup.wallet.GenerateWalletTask.handleWalletCreation(GenerateWalletTask.java:74)
        at com.example.graeme.beamitup.wallet.GenerateWalletTask.doInBackground(GenerateWalletTask.java:51)
        at com.example.graeme.beamitup.wallet.GenerateWalletTask.doInBackground(GenerateWalletTask.java:18)
W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:295)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
        at java.lang.Thread.run(Thread.java:818)

Googling seems to suggest that it may be due to Bouncy Castle implementing stunted versions of some algorithms for Android, but again, this previously worked on Android 3.4 and I believe web3j uses Spongy Castle to get around BC's problems.

I noticed @sanignucio mentioned this problem in the sample project which I cannot build the project to reproduce.

@kagile
Copy link

kagile commented Jan 4, 2019

I am getting the same error, too. Is there any solution other than downgrading?

@narimanam
Copy link

I have the same problem. any plan to fix it?

@narimanam
Copy link

as i know the problem is that Spongy Castle changed to Bouncy Castle in version 4.1.0-android and android have problem with bouncy Castle.

@snazha-blkio
Copy link
Contributor

Please take a look at #769, this contains some information regarding the crypto changes.

@WarSame
Copy link
Author

WarSame commented Jan 6, 2019

@snazha-blkio Thanks for the information.
What follow up do we have? Did @serso test generating a wallet?

@snazha-blkio
Copy link
Contributor

@WarSame there is a test for this functionality, please refer to: https://github.com/web3j/web3j/blob/release/4.1-android/core/src/test/java/org/web3j/crypto/WalletUtilsTest.java#L70

Are you able to run similar code to this in your app?

@serso
Copy link
Contributor

serso commented Jan 7, 2019

Hey guys, the library was tested in this sample app: https://github.com/serso/web3a.
I think the only one thing you need to do is to replace the Android version of Bouncy Castle with the shipped one, see https://github.com/serso/web3a/blob/4dda74db948f8cbd9a79ba4b9ab456316ea52c4d/app/src/main/java/org/solovyev/android/web3a/App.java#L47.
Spongy Castle is not needed anymore as Bouncy Castle shipped with Android has its package name rewritten starting from Android API 14. See rtyley/spongycastle#34 for more details.

@serso
Copy link
Contributor

serso commented Jan 7, 2019

@snazha-blkio
Copy link
Contributor

Thanks @serso . @WarSame , can you please try the suggested change by @serso and report back?

@serso
Copy link
Contributor

serso commented Jan 9, 2019

@WarSame, @kagile, @nariman-amani have you tried the proposed solution? Did it fix the problem?

@narimanam
Copy link

@serso yes, by adding bouncy castle provider in application, problem solved.
thanks.

@WarSame
Copy link
Author

WarSame commented Jan 9, 2019

@serso @snazha-blkio Sorry for the delay. Thank you guys, that works! Adding the BC provider in the application onCreate resolved the issue.

@serso
Copy link
Contributor

serso commented Jan 9, 2019

Great! I assume this issue can be closed then.

@WarSame WarSame closed this as completed Jan 14, 2019
@Ayesha742
Copy link

I had the same problem and when I added the bouncy castle, the app crashed. Is there any way to fix this?

@serso
Copy link
Contributor

serso commented Apr 24, 2019

@Ayesha742 providing a stack trace would be beneficial

@Ayesha742
Copy link

image

@serso
Copy link
Contributor

serso commented Apr 24, 2019

The stack trace is clearly different. It doesn't even seem to be related to Bouncy Castle or web3j.

@Ayesha742
Copy link

Here it is:
image

@Ayesha742
Copy link

Hi, is there anything to fix this?

@serso
Copy link
Contributor

serso commented Apr 26, 2019

@Ayesha742 what's the memory heap size you have on your phone/emulator? OOM exception might be caused by some other component in your app that eats too much RAM.

@kagile
Copy link

kagile commented Apr 26, 2019

@serso There is no problem with RAM. It is occurring on my device as well with 6gb RAM and no other apps running. The problem is in the code.

@serso
Copy link
Contributor

serso commented Apr 26, 2019

@kagile @Ayesha742 have you tried running https://github.com/serso/web3a?

@Ayesha742
Copy link

I created a new android project and used bouncy castle, now it is working

@huangShan-gitHub
Copy link

要怎么解决啊.........................

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants