Code example for KeyPair

Methods: getPrivate, getPublic

0
 
		X500Principal              dnName = new X500Principal("CN=" + getAccount(context));
		PKCS10CertificationRequest kpGen = new PKCS10CertificationRequest(
		                                                      "SHA1WithRSA", 
		                                                      dnName,
		                                                      keypair.getPublic(),
		                                                      null, 
		                                                      keypair.getPrivate());
		 
		Log.d("client", "Private key CSR: " + new String(keypair.getPrivate().getEncoded()));
		 
		String basecert = new String(Base64.encode(kpGen.getDEREncoded()));
		return postData(basecert);
	} 
	 
	public static boolean serializeKeypair(Context context, KeyPair keypair) 
	{	 
		try {  
			File dir = context.getFilesDir();
			File file = new File(dir, "keypair");
			 
			if(file != null)
			{ 
				boolean deleted = file.delete();
				Log.d("client", "Cert file deleted:" + deleted);
			} 
			 
	      FileOutputStream output = context.openFileOutput("keypair", Context.MODE_PRIVATE);
 
	      ObjectOutput out = new ObjectOutputStream(output); 
	      out.writeObject(keypair); 
	      out.close(); 
	  
	      // Get the bytes of the serialized object  
	  
	      return true;