Has Anyone run into this problem?
I am trying to use BouncyCastle to Create Certificate in Android but as soon as I have added BouncyCastle Provider Jar, I get Java Heap Space problem, Eclipse crashes with OutOfMemory error.
All I am doing is following, which is similar to Example code in bouncy castle,
public static X509Certificate createMasterCert(
PublicKey pubKey,
PrivateKey privKey)
throws Exception
{
//
// signers name
//
String issuer = "C=AU, O=The Legion of the Bouncy Castle, OU=Bouncy Primary Certificate";
//
// subjects name - the same as we are self signed.
//
String subject = "C=AU, O=The Legion of the Bouncy Castle, OU=Bouncy Primary Certificate";
//
// create the certificate - version 1
//
X509v1CertificateBuilder v1CertBuilder = new JcaX509v1CertificateBuilder(
new X500Name(issuer),
BigInteger.valueOf(1),
new Date(System.currentTimeMillis() - 1000L * 60 * 60 * 24 * 30),
new Date(System.currentTimeMillis() + (1000L * 60 * 60 * 24 * 30)),
new X500Name(subject),
pubKey);
X509CertificateHolder cert = v1CertBuilder.build(new JcaContentSignerBuilder("SHA1withRSA").setProvider(BC).build(privKey));
return new JcaX509CertificateConverter().setProvider(BC).getCertificate(cert);
}
If this code is being executed in Android, increasing Eclipse’s heap size will do nothing for you, because it simply has nothing to do with it. The heap size of Android applications is fixed and you cannot increase it (not before Honeycomb anyway). What version of Android are you using? Additionally, the BouncyCastle libraries are part of Android, so even if you add them to your project, it will use the system ones, which are slightly different and this can lead to subtle (and not so subtle) errors. IF you want to use BC on pre-Honeycomb (3.0) platforms you need to change the package name or include Spongy Castle which already does this for you.