java中如何得到公钥的key size
Filefile=newFile("d:\\cert\\test.cer");byte[]certBytes=newbyte[(int)file.length()];Fi...
File file = new File("d:\\cert\\test.cer");
byte[] certBytes = new byte[(int) file.length()];
FileInputStream input = new FileInputStream(file);
while (input.read(certBytes) != -1) {
}
X509Certificate cert1=(X509Certificate)pfCoder.getCertificate(certBytes);
PublicKey publickey=cert1.getPublicKey();
/**
* 得到证书
*
* @param certBytes
* @return
* @throws Exception
*/
public Certificate getCertificate(byte[] certBytes) throws Exception {
InputStream in = new ByteArrayInputStream(certBytes);
CertificateFactory cf = CertificateFactory.getInstance(X509);
return cf.generateCertificate(in);
}
怎么判断PublicKey是1024bits 还是2048bits啊,求,。。。。。。。 展开
byte[] certBytes = new byte[(int) file.length()];
FileInputStream input = new FileInputStream(file);
while (input.read(certBytes) != -1) {
}
X509Certificate cert1=(X509Certificate)pfCoder.getCertificate(certBytes);
PublicKey publickey=cert1.getPublicKey();
/**
* 得到证书
*
* @param certBytes
* @return
* @throws Exception
*/
public Certificate getCertificate(byte[] certBytes) throws Exception {
InputStream in = new ByteArrayInputStream(certBytes);
CertificateFactory cf = CertificateFactory.getInstance(X509);
return cf.generateCertificate(in);
}
怎么判断PublicKey是1024bits 还是2048bits啊,求,。。。。。。。 展开
展开全部
接你代码后面
String algorithm = publickey.getAlgorithm(); // 获取算法
KeyFactory keyFact = KeyFactory.getInstance(algorithm);
BigInteger prime = null;
if ("RSA".equals(algorithm)) { // 如果是RSA加密
RSAPublicKeySpec keySpec = (RSAPublicKeySpec)keyFact.getKeySpec(publickey, RSAPublicKeySpec.class);
prime = keySpec.getModulus();
} else if ("DSA".equals(algorithm)) { // 如果是DSA加密
DSAPublicKeySpec keySpec = (DSAPublicKeySpec)keyFact.getKeySpec(publickey, DSAPublicKeySpec.class);
prime = keySpec.getP();
}
int len = prime.toString(2).length(); // 转换为二进制,获取公钥长度
展开全部
sun.security.util.KeyUtil.getKeySize(Key key), 支持RSA、DSA等算法的PrivateKey和PublicKey
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-12-02
展开全部
X509Certificate的 toString()是这样的:
[
Version: V3
Subject: CN=XXXXXX, EMAILADDRESS=yyyyyyy@XXXXX.com, O=ZZZZZZZZZZ
Signature Algorithm: MD5withRSA, OID = 1.2.840.113549.1.1.4
Key: Sun RSA public key, 1024 bits
所以,可以知道是1024 bits
[
Version: V3
Subject: CN=XXXXXX, EMAILADDRESS=yyyyyyy@XXXXX.com, O=ZZZZZZZZZZ
Signature Algorithm: MD5withRSA, OID = 1.2.840.113549.1.1.4
Key: Sun RSA public key, 1024 bits
所以,可以知道是1024 bits
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-12-02
展开全部
PublicKey的toString()的开头是这样的
Sun RSA public key, 1024 bits
modulus: 990645334079840363710713617513
所以,也能知道是1024 bits
Sun RSA public key, 1024 bits
modulus: 990645334079840363710713617513
所以,也能知道是1024 bits
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询