如何使用Java中的bouncyCastle向证书添加PrivateKeyUsage扩展?
我有一个X509证书,我要向其添加扩展...我想添加PrivateKeyUsage扩展,但我不知道如何创建PrivateKeyUsage对象,也不知道如何为其赋值Not BeeBead;Not After值(&;Not After值)...谢谢
解决方案
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);
相关文章