Results 1 to 1 of 1
- 12-22-2010, 07:21 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 1
- Rep Power
- 0
Formatting POST data with a pkcs#7 signature
Hii,
I am a newbie in java networking.
My problem is, i hv no idea how to generate the pkcs#7formatted signature string within the following code.
My digital signature is imprinted in an e-token.
I am providing the following java code which is used for the connection.
The signature (which is to be generated in pkcs#7 format for a certificate) is hard coded here and the "String ip" is an example I.P. to give u an idea of what I need.
.............
...................
..........................
public static void main(String[] args) {
SSLContext sslcontext = null;
try {
sslcontext = SSLContext.getInstance("SSL");
sslcontext.init(new KeyManager[0],
new TrustManager[] { new DummyTrustManager() },
new SecureRandom());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace(System.err);
} catch (KeyManagementException e) {
e.printStackTrace(System.err);
}
SSLSocketFactory factory = sslcontext.getSocketFactory();
String data="V00501^adsdsfff";
String signature="MIIHvQYJKoZIhvcNAQcCoIIHrjCCB6oCAQExCzA JBgUrDgMCGgUAMAsGCSqGSIb3DQEHAaCCBaUwggWhMIIEiaADA gECAgI1qDANBgkqhkiG9w0BAQUFADCB0zEk=";
String urlParameters="data=";
try{
urlParameters =urlParameters + URLEncoder.encode(data, "UTF-8") +"&signature=" + URLEncoder.encode(signature, "UTF-8");
}catch(Exception e){
e.printStackTrace();
}
try{
URL url;
HttpsURLConnection connection;
InputStream is = null;
//------------------------
String ip="45.168.64.6";
url = new URL("https://" + ip + "/MIN/BackEnd");
System.out.println("URL "+ip);
connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length)) ;
connection.setRequestProperty("Content-Language", "en-US");
connection.setUseCaches (false);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setSSLSocketFactory(factory);
connection.setHostnameVerifier(new DummyHostnameVerifier());
OutputStream os = connection.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os);
osw.write(urlParameters);
osw.flush();
osw.close();
is =connection.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(is));
String line = in.readLine();
System.out.println("Output "+line);
is.close();
in.close();
} catch(Exception e){
e.printStackTrace();
}
}
...........
..................
Any kind of sugggestions and helps in this regard are most welcome.
Thanking you all.........looking forward to a solution very soon.
Similar Threads
-
how to post data to a website using java
By mr_anderson in forum Advanced JavaReplies: 6Last Post: 11-12-2010, 11:46 AM -
Formatting String data from database
By computerbum in forum JDBCReplies: 1Last Post: 04-28-2010, 01:27 PM -
how to POST data to server using HttpURLConnection ??
By dhana in forum NetworkingReplies: 4Last Post: 10-15-2008, 01:59 PM -
padding informaiton for PKCS#5
By nanaji in forum Advanced JavaReplies: 3Last Post: 07-31-2008, 05:36 AM -
Data formatting for the <display:table>
By yuchuang in forum Web FrameworksReplies: 3Last Post: 12-14-2007, 10:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks