문제

i have an X509Certificate that i want to add extensions to... i want to add the PrivateKeyUsage extension, but i dont know how to create a PrivateKeyUsage object or how to give it notBefore & notAfter values ... thanks

도움이 되었습니까?

해결책

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

다른 팁

You can do something like this,

    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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top