Bouncycastle encryption algorithms not provided

I am trying to use BouncyCastle with Android to implement ECDH and EL Gamal. I added the bouncycastle jar file (bcprov-jdk16-144.jar) and wrote some code that works with my jvm computers, however, when I try to port it to my Android application, it throws:

java.security.NoSuchAlgorithmException: KeyPairGenerator ECDH implementation not found

Sample code:

Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());

java.security.KeyPairGenerator keyGen = org.bouncycastle.jce.provider.asymmetric.ec.KeyPairGenerator.getInstance("ECDH", "BC");
                ECGenParameterSpec ecSpec = new ECGenParameterSpec("prime192v1");

                keyGen.initialize(ecSpec, SecureRandom.getInstance("SHA1PRNG"));



                KeyPair pair = keyGen.generateKeyPair();
                PublicKey pubk = pair.getPublic();
                PrivateKey prik = pair.getPrivate();

Then I wrote a simple program to see which encryption algorithms are available, and ran it on my Android emulator, and on my computers jvm was:

Set<Provider.Service> rar = new org.bouncycastle.jce.provider.BouncyCastleProvider().getServices();
    Iterator<Provider.Service> ir = rar.iterator();
    while(ir.hasNext())
        System.out.println(ir.next().getAlgorithm());

In android, I do not get any of the EC algorithms while it is working normally on my computer.

I also get the following two compilation errors for many cool castle classes:

01-07 17: 17: 42.548: INFO/dalvikvm (1054): DexOpt: 'Lorg/bouncycastle/asn1/ASN1Encodable;'

01-07 17: 17: 42.548: DEBUG/dalvikvm (1054): DexOpt: "Lorg/bouncycastle/asn1/ess/OtherSigningCertificate;":

?

+3
3

, , Spongy Castle - , Bouncy Castle Android. :

http://code.google.com/p/android/issues/detail?id=3280

... Android, , Bouncy Castle, - - - BC, .

Spongy Castle Bouncy Castle, Android. , Android:

  • org.bouncycastle. * org.spongycastle. * -
  • API Java SC, BC
+9

, , BouncyCastle Android SDK. , , BouncyCastle .

, javax.crypto.Cipher.

+1

If you are viewing the Android code, you will see that not all BouncyCastle features are enabled. see libcore / security / src / main / java / org / bouncycastle / jce / provider / BouncyCastleProvider.java

In particular, the output of ECDH is commented out, which means that during compilation it will be completely excluded from the jar android file.

+1
source

Source: https://habr.com/ru/post/1727655/


All Articles