Devesh Garg
Devesh Garg

Reputation: 83

BouncyCastle Error

I am developing an android application. In this application I create my own private key by passing pass phrase, user id and keys. When creating the private key, it says "Error: org.bouncycastle.openpgp.PGPException: cannot create cipher: CAST5/CFB/NoPadding"

I have checked the logcat as well as the warning section in the Eclipse but there is error there. SO why I am getting this error and how to solve it. Any help is greatly appreciated!

I am using bcpg-jdk15on-150.jar and bcprov-jdk15on-150.jar,

which I have downloaded from http://www.bouncycastle.org/latest_releases.html

EDIT

the solution of renaming one or both the jar files does not work. When I run the application it says Unable to execute dex: Multiple dex files define Lorg/bouncycastle/apache/bzip2/BZip2Constants; and Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lorg/bouncycastle/apache/bzip2/BZip2Constants; I think there is a problem with the duplication of some files within the two jar files. Can anyone suggest me a solution regarding this?

Thanks

Upvotes: 0

Views: 2753

Answers (1)

Tomasz Hadam
Tomasz Hadam

Reputation: 91

Use latest BouncyCastle and setup security in your code in the following way:

    Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME);
    Security.insertProviderAt(new BouncyCastleProvider(), 1);

It sets Bouncy Castle library as preferred security provider; Android's default provider config has BC at position 3 so this code will remove it and insert BC again at position 1. It solved the problem for me.

Upvotes: 1

Related Questions