導航:首頁 > 編程語言 > 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格式的證書訪問網站相關的資料

熱點內容
java網頁能做心跳機制 瀏覽:817
逆戰文件應用在哪裡 瀏覽:102
紅頭文件訂書紅線在哪裡 瀏覽:851
excel怎麼做文件頭 瀏覽:703
為什麼word找不到文件菜單 瀏覽:671
ios15安裝後找不到描述文件 瀏覽:440
學編程怎麼學最有效 瀏覽:873
通過wifi傳文件到ipad 瀏覽:197
js隨機顏色 瀏覽:611
文件快速復制到u盤的軟體 瀏覽:443
如何檢查無線網路驅動是否正常 瀏覽:468
百度網盤來自分享的文件在哪裡 瀏覽:127
如何發視頻到騰訊視頻文件夾里 瀏覽:510
微信打開cad外部文件找不到 瀏覽:882
平板可以打開各種文件後綴的軟體 瀏覽:531
蘋果微信文件怎麼全選 瀏覽:749
手機里之前打開過的文件在哪裡找 瀏覽:685
cad能看word文件嗎 瀏覽:719
12306火車票系統後台資料庫 瀏覽:570
js翻譯德語 瀏覽:33

友情鏈接