keytool
這個命令用來產生一個密匙庫
keytool
這個命令用來產生簽名時所要用的證書
//從密鑰庫中讀取CA證書
String storepass =
//前面設置的密碼
FileInputStream in = new FileInputStream(
//獲取證書 java
//BASE
//將chinajavaworld
Signature signature;
try {
InputStream streamCert = new java
CertificateFactory factory = CertificateFactory
Certificate cert = factory
System
signature = Signature
signature
//要簽名的指紋內容
String sss =
//獲取CA證書私鑰
PrivateKey priKey=(PrivateKey)ks
System
//用私鑰簽名
sig = Signature
sig
ByteArrayOutputStream streamRaw
DataOutputStream streamSig
streamSig
String signatureS = StringUtils
System
//用公鑰做驗證測試
System
ByteArrayOutputStream streamRaw = new ByteArrayOutputStream();
DataOutputStream streamSig = new DataOutputStream(streamRaw);
streamSig
System
} catch(Exception e)
{
System
}
接下來
附
public static String encodeBase
boolean lineSep = false;
int sLen = data == null ?
(sLen ==
int eLen = (sLen /
int cCnt = (sLen
int dLen = cCnt + (lineSep ? (cCnt
char dArr[] = new char[dLen];
int s =
int d =
int cc =
do {
if(s >= eLen)
break;
int i = (data[s++] &
dArr[d++] = CA[i >>>
dArr[d++] = CA[i >>>
dArr[d++] = CA[i >>>
dArr[d++] = CA[i &
if(lineSep && ++cc ==
{ dArr[d++] =
dArr[d++] =
cc =
}
} while(true);
int left = sLen
if(left >
{ int i = (data[eLen] &
dArr[dLen
dArr[dLen
} return new String(dArr);
}
public static final String encodeHex(byte bytes[])
{ StringBuffer buf = new StringBuffer(bytes
for(int i =
if((bytes[i] &
buf
} return buf
}
public static final byte[] decodeHex(String hex) {
char chars[] = hex
byte bytes[] = new byte[chars
int byteCount =
for(int i =
int newByte =
newByte |= hexCharToByte(chars[i]);
newByte <<=
newByte |= hexCharToByte(chars[i +
bytes[byteCount] = (byte)newByte; byteCount++; } return bytes; }
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26624.html