Create a client certificate on an Android device

I want to create an Android application that will use SSL client certificate authentication.

I found code examples that show me how two SSL client certificate authentication is in an Android app. This is clear to me.

My problem is that I want to create an SSL client certificate on the device. Simply put, I want my program to do the following:

When the program is installed on the device, the client certificate should be generated on the device (at the first start), and the print with the public key will be sent to my server. (The certificate must be generated upon first use).

How can I create a client certificate and an Android device from my application?

+7
android authentication certificate ssl client-certificates
source share
1 answer

You can run the following Android code to create a key pair and get a fingerprint. It uses the excellent AH library from jCraft .

public void generatePublicPrivateKeyPair() throws Exception { ByteArrayOutputStream privateKeyOutputStream = new ByteArrayOutputStream(); ByteArrayOutputStream publicKeyOutputStream = new ByteArrayOutputStream(); JSch jsch=new JSch(); KeyPair kpair=KeyPair.genKeyPair(jsch, KeyPair.RSA); //kpair.setPassphrase(passphrase); kpair.writePrivateKey(privateKeyOutputStream); kpair.writePublicKey(publicKeyOutputStream, "Generated by vPro Management Console"); String fingerPrint = kpair.getFingerPrint(); System.out.println("Finger print: "+ fingerPrint); kpair.dispose(); byte[] privateKey = privateKeyOutputStream.toByteArray(); byte[] publicKey = publicKeyOutputStream.toByteArray(); System.out.println("Private key " + new String(privateKey)); System.out.println("Public key " + new String(publicKey)); } 

Just put the JAR in your libs folder and you will be fine.

If you are using maven, you can refer to caller id dependency as follows:

 <dependency> <groupId>com.jcraft</groupId> <artifactId>jsch</artifactId> <version>0.1.50</version> </dependency> 
+7
source share

All Articles