0
votes

From API level 28, Google has restricted Security provider feature(bouncy castle issue). So alternatively we have added Security provider using spongy castle Now we can able to generate a keypair. But the key pair is not matching with the previous one. We can't get Private keyThis is we used previously, Old codeapi 27:

KeyPairGenerator keyGen = KeyPairGenerator.getInstance("EC", "BC");
SecureRandom random =SecureRandom.getInstance("SHA1PRNG");
keyGen.initialize(256, random);KeyFactory kaif = KeyFactory.getInstance("EC", "BC");
KeyPair pair = keyGen.generateKeyPair();
PrivateKey privateKey = pair.getPrivate();
PublicKey publicKey = pair.getPublic();

After the API level issue, we have removed "BC" and added Bouncy Castle manually by adding the below lineSecurity.insertProviderAt(BouncyCastleProvider(), 1); by implementing Bouncy castle in dependencies, implementation "com.madgag.spongycastle:core:1.58.0.0" implementation "com.madgag.spongycastle:prov:1.58.0.0" But the key pair is not matching with the previous one. New Code:api 28

Security.insertProviderAt(new org.spongycastle.jce.provider.BouncyCastleProvider(), 1);
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("EC");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
keyGen.initialize(256, random);
KeyFactory kaif = KeyFactory.getInstance("EC");
KeyPair pair = keyGen.generateKeyPair();
PrivateKey privateKey = pair.getPrivate();
PublicKey publicKey = pair.getPublic();

But the key pair is not matching with the previous one.

Image:codeexpectation

1
your question is not clear enough, please read minimal reproducible example and edit your question accordinglyDev
ok let me add sampleuser11415509
Please see this answer for a full example: stackoverflow.com/a/66323575/215266satur9nine

1 Answers

0
votes

try insert new BouncyCastleProvider() on the first row of your security provider and remove all setprovider("BC") from your code.