導航:首頁 > 編程語言 > javapfx格式的證書訪問網站

javapfx格式的證書訪問網站

發布時間:2023-08-04 19:52:09

1. java客戶端怎麼訪問帶有pfx格式證書的https網站(伺服器)呢,

使用HttpURLConnection訪問https地址。

以下是導入JKS證書的方式,可以參考。

Stringkeystorefile="file";
Stringkeystorepw="password";
Stringkeypw="password";

KeyStorekeystore=KeyStore.getInstance("JKS");
keystore.load(newFileInputStream(keystorefile),keystorepw.toCharArray());
=KeyManagerFactory.getInstance("SunX509");
keymanagerfactory.init(keystore,keypw.toCharArray());
KeyManagerakeymanager[]=keymanagerfactory.getKeyManagers();
=TrustManagerFactory.getInstance("SunX509");
trustmanagerfactory.init(keystore);
TrustManageratrustmanager[]=trustmanagerfactory.getTrustManagers();
sslcontext=SSLContext.getInstance("TLS");
sslcontext.init(akeymanager,atrustmanager,null);
sslSocketFactory=sslcontext.getSocketFactory();

Stringurl="asdfdf";
URLtestURL=newURL(url);
=(HttpURLConnection)testURL.openConnection();
if(){
HttpsURLConnectionconn=(HttpsURLConnection)urlConnection;
conn.setSSLSocketFactory(sslSocketFactory);
}

2. Java如何讀取PFX密鑰文件

package com.Jinhill;
import java.io.*;
import java.util.*;
import java.security.*;
import java.security.cert.Certificate;

public class ReadPFX {
public ReadPFX (){
}
//轉換成十六進制字元串
public static String Byte2String(byte[] b) {
String hs="";
String stmp="";

for (int n=0;n<b.length;n++) {
stmp=(java.lang.Integer.toHexString(b[n] & 0XFF));
if (stmp.length()==1) hs=hs+"0"+stmp;
else hs=hs+stmp;
//if (n<b.length-1) hs=hs+":";
}
return hs.toUpperCase();
}

public static byte[] StringToByte(int number) {
int temp = number;
byte[] b=new byte[4];
for (int i=b.length-1;i>-1;i--){
b[i] = new Integer(temp&0xff).byteValue();//將最高位保存在最低位
temp = temp >> 8; //向右移8位
}
return b;
}
private PrivateKey GetPvkformPfx(String strPfx, String strPassword){
try {
KeyStore ks = KeyStore.getInstance("PKCS12");
FileInputStream fis = new FileInputStream(strPfx);
// If the keystore password is empty(""), then we have to set
// to null, otherwise it won't work!!!
char[] nPassword = null;
if ((strPassword == null) || strPassword.trim().equals("")){
nPassword = null;
}
else
{
nPassword = strPassword.toCharArray();
}
ks.load(fis, nPassword);
fis.close();
System.out.println("keystore type=" + ks.getType());
// Now we loop all the aliases, we need the alias to get keys.
// It seems that this value is the "Friendly name" field in the
// detals tab <-- Certificate window <-- view <-- Certificate
// Button <-- Content tab <-- Internet Options <-- Tools menu
// In MS IE 6.
Enumeration enumas = ks.aliases();
String keyAlias = null;
if (enumas.hasMoreElements())// we are readin just one certificate.
{
keyAlias = (String)enumas.nextElement();
System.out.println("alias=[" + keyAlias + "]");
}
// Now once we know the alias, we could get the keys.
System.out.println("is key entry=" + ks.isKeyEntry(keyAlias));
PrivateKey prikey = (PrivateKey) ks.getKey(keyAlias, nPassword);
Certificate cert = ks.getCertificate(keyAlias);
PublicKey pubkey = cert.getPublicKey();
System.out.println("cert class = " + cert.getClass().getName());
System.out.println("cert = " + cert);
System.out.println("public key = " + pubkey);
System.out.println("private key = " + prikey);
return prikey;
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
}

3. pfx證書文件能直接使用嗎

不能直接使用pfx證書的,
需要去java網站上下一個keytools工具,導入pfx證書後才能使用。cer和pfx是成對的,你做了個cer的話必然會同時生成一個pfx,不曉得你的cer是怎麼做的。一般來說是這樣的,你先用一些工具,比如剛才說的java的keytools,或者IIS生成一個密鑰請求crs,然後把這個crs發送給密鑰發放的CA,你可以自己搭一個CA或者去買一個,CA會再發給你一個確認後的證書,你再使用這個確認後的cer來結束證書申請過程,最終得到一個私鑰和一個密鑰

4. pfx格式文件如何打開如題 謝謝了

pfx可能是證書的備份文件,這時可雙擊相關文件即可導入證書,如果要求輸入密碼,則輸入當初設定的密碼即可。

5. 數字證書文件格式cer和pfx的區別 / 藍訊

Windows IIS下的數字證書格式一般為。pfx
Java tomcat 下的數字證書格式一般為.jks或.store
Apache和nginx一般是.pem
證書請求文件一般是.csr
證書公鑰文件一般是.cer或.crt
證書私鑰文件一般是.key
可以到易維信【evtrust】申請數字簽名證書或者代碼簽名證書

閱讀全文

與javapfx格式的證書訪問網站相關的資料

熱點內容
汽車保養數據怎麼清 瀏覽:629
pdf文件圖像打不開 瀏覽:176
msp430時鍾程序 瀏覽:660
查看sd卡文件系統格式 瀏覽:696
c盤中顯示隱藏文件 瀏覽:951
蘋果升級系統白屏 瀏覽:136
三菱gxplc編程軟體如何使用 瀏覽:710
海康威視手機app怎麼看不了 瀏覽:482
wordpress下載中心插件 瀏覽:402
微信限制字數是多少 瀏覽:20
策劃輸出主要從哪些文件來 瀏覽:174
網路營銷找什麼工作 瀏覽:372
tcl匹配文件名的正則表達式 瀏覽:461
音頻文件數據量為何8 瀏覽:534
有哪些分享學習的網站 瀏覽:174
小程序文件發到微信電腦如何打開 瀏覽:265
四星五星做號工具 瀏覽:920
qq郵箱怎麼發送視頻文件 瀏覽:453
能免費開店的網站有哪些 瀏覽:548
中國網路營銷發展史 瀏覽:828

友情鏈接