0

I am trying to write an ECDH code for my android app. As a starting point, I managed to instal lSpongyCastle Jar's on my AndroidStudion, but now I am having an issue when I run:

KeyPairGenerator aliceKeyGen = KeyPairGenerator.getInstance("ECDH", "SC");

It keeps saying that there is no such provider, however I have added

  Security.insertProviderAt(new org.spongycastle.jce.provider.BouncyCastleProvider(), 1);

to my code, and I have added the

implementation 'com.madgag.spongycastle:prov:1.58.0.0'

to my gradle.

I have tried different provider names (such as "BC") but all gave me the same error 'NoSuchProviderException'

I have tried reading everywhere without success, please let me know what I am doing wrong and what else I should do.

Thank you!

PS Needless to say, other functions of SpongyCastle are working properly, so I believe I have installed the library successfully.

1 Answers1

-1

Which API Version are you using? Google changed the behavior of inserting and using security providers. I do not have an actual answer for your question, but that looks like it.

Google states state since Android P the prefer AndroidOpenSSL as security provider internally and they deprecate some BC provider functionality. Using getInstance() with a given provider (e.g. "BC" or "SC") will throw NoSuchAlgorithmException for apps targeting Android P or later.

They propose to just not use an explicit provider in getInstance().

see https://android-developers.googleblog.com/2018/03/cryptography-changes-in-android-p.html and https://developer.android.com/guide/topics/security/cryptography#deprecated-functionality

Also I do see in my experiments on Android that spongycastle may not need to be added at position 1 as AndroidOpenSSL provides now a lot of security algorithms (just do Security.addProvider(new BouncyCastleProvider()); if you really need some stuff from it).

chrislro
  • 41
  • 3