Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use .key and .pem file to create a socket SSL in Android?

My .key file like: -----BEGIN RSA PRIVATE KEY----- MIIEpAIBAAKCAQEA1j6eGXbHpqigZ1K//wnuyr5v/L2jFm7dzTtHJx8ZoMQ4CbsG

My .pem file like: -----BEGIN CERTIFICATE----- MIIE4zCCA8ugAwIBAgIDBOziMA0GCSqGSIb3DQEBBQUAMDwxCzAJBgNVBAYTAlVT

I don't know how many steps of authenticate at here. I only want to create a ssl socket to an IP and port, and send/receive data in that socket. I tried to use keystock, but perhaps I don't understand deep about it, I always get wrong.

Please give me a guide, or sample code.

Thanks so much.

like image 946
Brave Avatar asked Jul 09 '12 07:07

Brave


People also ask

What is .PEM file in Android?

pem file represents your client certificate you have to use for performing an HTTPS client authentication. Unfortunately Java/Android prefers a different format, therefore I recommend you to import both file into a BKS file. Creating a BKS file and importing existing .

What is PEM format for SSL?

PEM or Privacy Enhanced Mail is a Base64 encoded DER certificate. PEM certificates are frequently used for web servers as they can easily be translated into readable data using a simple text editor. Generally when a PEM encoded file is opened in a text editor, it contains very distinct headers and footers.


1 Answers

I assume that the .key and .pem file represents your client certificate you have to use for performing an HTTPS client authentication. Unfortunately Java/Android prefers a different format, therefore I recommend you to import both file into a BKS file.

Creating a BKS file and importing existing .key+.pem file is very simple using KeyStore Explorer. After starting KeyStore Explorer select File -> New Keystore -> BKSv1. Afterwards you can execute Tools -> Import Key Pair and select the .pem file. Afterwards KeyStore Explorer will ask you for selecting the .key file.

Finally save the key store protected with a password of your choice.

The created BKSv1 file can now be used in your Android app. See for example the code posted in this question: Using client/server certificates for two way authentication SSL socket on Android

like image 118
Robert Avatar answered Sep 23 '22 13:09

Robert