Android certificate

Put your problem here if it does not fit any of the other categories.

Android certificate

Postby skuz » Mon Dec 07, 2009 4:47 pm

Heya, i want a secure connection from my android device to my website, (using a self-signed certficiate).

I would like to create a certificate request, but android wont allow me.

I tried using www.bountycastle.org but it wont create, when i create a csr. It ends up being null.

It's this code im working on from this homepage, http://www.java2s.com/Tutorial/Java/049 ... equest.htm


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. import java.io.OutputStreamWriter;
  3.  
  4. import java.security.KeyPair;
  5.  
  6. import java.security.KeyPairGenerator;
  7.  
  8. import java.security.SecureRandom;
  9.  
  10. import java.security.Security;
  11.  
  12.  
  13.  
  14. import javax.security.auth.x500.X500Principal;
  15.  
  16.  
  17.  
  18. import org.bouncycastle.jce.PKCS10CertificationRequest;
  19.  
  20. import org.bouncycastle.openssl.PEMWriter;
  21.  
  22.  
  23.  
  24. public class MainClass {
  25.  
  26.   public static PKCS10CertificationRequest generateRequest(KeyPair pair) throws Exception {
  27.  
  28.     return new PKCS10CertificationRequest("SHA256withRSA", new X500Principal(
  29.  
  30.         "CN=Requested Test Certificate"), pair.getPublic(), null, pair.getPrivate());
  31.  
  32.   }
  33.  
  34.  
  35.  
  36.   public static void main(String[] args) throws Exception {
  37.  
  38.     Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
  39.  
  40.     KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA", "BC");
  41.  
  42.  
  43.  
  44.     kpGen.initialize(1024, new SecureRandom());
  45.  
  46.     KeyPair pair = kpGen.generateKeyPair();
  47.  
  48.     PKCS10CertificationRequest request = generateRequest(pair);
  49.  
  50.     PEMWriter pemWrt = new PEMWriter(new OutputStreamWriter(System.out));
  51.  
  52.     pemWrt.writeObject(request);
  53.  
  54.     pemWrt.close();
  55.  
  56.   }
  57.  
  58. }
  59.  
  60.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
skuz
Freshman
Freshman
 
Posts: 2
Joined: Tue Sep 08, 2009 1:24 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 22 guests