導航:首頁 > 源碼編譯 > 如何編譯pfx文件

如何編譯pfx文件

發布時間:2024-04-25 11:14:56

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;
}
}

閱讀全文

與如何編譯pfx文件相關的資料

熱點內容
程序員那麼可愛誰是獅子座 瀏覽:453
土體壓縮系數 瀏覽:403
程序員愛看片嗎 瀏覽:335
電腦c盤有灰色文件夾 瀏覽:126
斐波那契數列php 瀏覽:668
如何獲取嗶哩嗶哩app郵箱注冊 瀏覽:530
怎麼啟動arduino編譯環境 瀏覽:842
昕動app怎麼突然進不去 瀏覽:471
如何登錄內部伺服器 瀏覽:878
python讀取在線表格 瀏覽:1001
喝什麼茶能緩解壓抑 瀏覽:867
u命令無法打開 瀏覽:962
vue編譯後的js能爬嗎 瀏覽:455
解壓骰子推薦3代 瀏覽:749
安卓手機劃線密碼忘了怎麼解鎖 瀏覽:309
精美角度主圖指標源碼 瀏覽:279
程序員編程函數需要特別好嗎 瀏覽:183
fue加密毛發怎麼樣 瀏覽:931
網上考學歷app如何屏蔽 瀏覽:355
python矩陣庫 瀏覽:164