1
我有我想要擴展添加到...我要添加PrivateKeyUsage擴展的X509Certificate,但我不知道如何創建一個PrivateKeyUsage對象或如何給它notBefore & notAfter值...感謝如何使用java中的bouncycastle將PrivateKeyUsage擴展添加到證書中?
我有我想要擴展添加到...我要添加PrivateKeyUsage擴展的X509Certificate,但我不知道如何創建一個PrivateKeyUsage對象或如何給它notBefore & notAfter值...感謝如何使用java中的bouncycastle將PrivateKeyUsage擴展添加到證書中?
Date from = new Date();
Date to = new Date(System.currentTimeMillis()+ 30*1000*60*60l);
ASN1EncodableVector v = new ASN1EncodableVector();
DERGeneralizedTime fromTime = new DERGeneralizedTime(from);
v.add(new DERTaggedObject(false, 0, fromTime));
DERGeneralizedTime toTime = new DERGeneralizedTime(to);
v.add(new DERTaggedObject(false, 1, toTime));
DERObject o = new DERSequence(v);
PrivateKeyUsagePeriod pkup = PrivateKeyUsagePeriod.getInstance(o);
v3CertGen.addExtension(x509Extensions.PrivateKeyUsagePeriod, false, pkup);
你可以做這樣的事情,
Date notBeforeDate = new Date();
Date notAfterDate = new Date(System.currentMillis() + 24L*3600*365*1000);
PrivateKeyUsagePeriod pkup = new PrivateKeyUsagePeriod(notBeforeDate,
notAfterDate);
V3Extension[] v3 = {pkup};
cert = CertificateFactory.createCertificate(subject, kp.getPublic(), issuer,
kp.getPrivate(), algorithm, 1, v3);
它說,這種構造是不確定的... 但我發現另一種方式來做到這一點...感謝.. – 2010-06-21 16:57:53