Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Posts: 174
Registered: ‎01-25-2011
My Device: Not Specified

Help required in adding ssl certificate



I have been trying to add a ssl certificate in my application but i m not been successful, I m getting a certificate verification exception while running the application. i have used the foll code in the mainscreen to install the certificate

		X509Certificate ox509Certificate;

		try {
		    // Get an input stream for the certificate in a resource file
		    InputStream rs = getClass().getResourceAsStream("/inblrm14.pem");
		    // PEM format is Base64 encoded
		    Base64InputStream b64is = new Base64InputStream(rs);

		    // Create the X509 certificate
		    ox509Certificate = new X509Certificate(b64is);

		    // Clean up.

		    // Add the certificate to the DeviceKeyStore
		    KeyStore ks = DeviceKeyStore.getInstance();
		  //check if certificate is not already in the DeviceKeyStore
		    ks.set(null, ox509Certificate.getSubjectFriendlyName(), ox509Certificate, ox509Certificate.getStatus(),
		} catch (CertificateException ce) {
		} catch (CryptoException crypt) {
		} catch (IOException ioe) {

 I m getting that error when i m using verify method. 


Moreover i tried adding the certificate in android(to check the certificate correctness) n i got positive response. 

So, I wonder whether i m following the right procedure or not... can any one guide me through the process of adding the ssl certificate to the bb device

Posts: 40
Registered: ‎10-10-2011
My Device: BB Curve&Bold
My Carrier: Airtel

Re: Help required in adding ssl certificate

[ Edited ]
 private Certificate ReadFile(String path) {
		try {
			InputStream is = getClass().getResourceAsStream(path);
			byte[] data = new byte[is.available()];
			is.read(data, 0, is.available());
			Certificate c = CertificateUtilities.readCertificateFile(null, data);		
			return c;
		} catch (Exception ioe) {
		return null;

	public void addCertToDeviceKeyStore(Certificate certificate) {
		KeyStore keyStore = DeviceKeyStore.getInstance();
		// check if certificate is not already in the DeviceKeyStore
		if (!keyStore.isMember(certificate)) {
			try {
				String SFN = certificate.getSubjectFriendlyName();
				CertificateStatus CS = certificate.getStatus();
				keyStore.set(null, SFN, certificate, CS, keyStore.getTicket());
			} catch (Exception e) {
		} else {
			System.out.println("Added certificate to Device Keystore");

 Try this code. 

Posts: 174
Registered: ‎01-25-2011
My Device: Not Specified

Re: Help required in adding ssl certificate

Thanks a ton.. I had some progress using ur code snippet. but now the prob is that after the apps hits that part of code, I m asked to enter the key store password but i m not able to enter the password, my device got hanged. I m not able to move any further... Could u plz help me out in this issue... Thanks in advance!!