Example usage for org.bouncycastle.asn1 ASN1EncodableVector add

List of usage examples for org.bouncycastle.asn1 ASN1EncodableVector add

Introduction

In this page you can find the example usage for org.bouncycastle.asn1 ASN1EncodableVector add.

Prototype

public void add(ASN1Encodable element) 

Source Link

Usage

From source file:com.novosec.pkix.asn1.crmf.PKMACValue.java

License:Open Source License

public DERObject getDERObject() {
    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(algId);
    v.add(value);//from   w w w  .jav  a  2s . c  om

    return new DERSequence(v);
}

From source file:com.novosec.pkix.asn1.crmf.POPOSigningKey.java

License:Open Source License

public DERObject getDERObject() {
    ASN1EncodableVector v = new ASN1EncodableVector();

    if (poposkInput != null) {
        v.add(new DERTaggedObject(false, 0, poposkInput));
    }//ww  w.  j ava2s . c o  m
    v.add(algorithmIdentifier);
    v.add(signature);

    return new DERSequence(v);
}

From source file:com.novosec.pkix.asn1.crmf.POPOSigningKeyInput.java

License:Open Source License

public DERObject getDERObject() {
    ASN1EncodableVector v = new ASN1EncodableVector();

    if (sender != null) {
        v.add(new DERTaggedObject(false, 0, sender));
    } else {//from w  ww  . j a v a  2 s  .c  o m
        v.add(publicKeyMAC);
    }

    v.add(publicKey);

    return new DERSequence(v);
}

From source file:com.novosec.pkix.asn1.crmf.SinglePubInfo.java

License:Open Source License

public DERObject getDERObject() {
    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(pubMethod);

    if (pubLocation != null) {
        v.add(pubLocation);/*from  w  w w .j  a v  a  2 s . c om*/
    }

    return new DERSequence(v);
}

From source file:com.otterca.common.crypto.SimplePolicyGeneratorImpl.java

License:Apache License

/**
 * Get user notification policy information.
 * /*from   w w  w  .j  a  va 2 s .co m*/
 * @return
 */
public PolicyInformation getUserNoticePolicyInformation() {
    PolicyInformation unotice = null;
    if ((organization != null) && (userNotice != null)) {
        ASN1EncodableVector noticeNumbers = new ASN1EncodableVector();
        if (noticeNumber != null) {
            noticeNumbers.add(new DERInteger(noticeNumber.intValue()));
        }
        NoticeReference noticeReference = new NoticeReference(organization, noticeNumbers);
        unotice = new PolicyInformation(id_qt_unotice,
                new DERSequence(new UserNotice(noticeReference, new DisplayText(userNotice))));
    }
    return unotice;
}

From source file:com.peterphi.std.crypto.keygen.CaHelper.java

License:Open Source License

public static PKCS10CertificationRequest generateCertificateRequest(X509Certificate cert, PrivateKey signingKey)
        throws Exception {
    ASN1EncodableVector attributes = new ASN1EncodableVector();

    Set<String> nonCriticalExtensionOIDs = cert.getNonCriticalExtensionOIDs();
    for (String nceoid : nonCriticalExtensionOIDs) {
        byte[] derBytes = cert.getExtensionValue(nceoid);
        ByteArrayInputStream bis = new ByteArrayInputStream(derBytes);
        ASN1InputStream dis = new ASN1InputStream(bis);
        try {/*from  w ww  .jav a  2  s .  c  o  m*/
            DERObject derObject = dis.readObject();
            DERSet value = new DERSet(derObject);
            Attribute attr = new Attribute(new DERObjectIdentifier(nceoid), value);
            attributes.add(attr);
        } finally {
            IOUtils.closeQuietly(dis);
        }
    }
    PKCS10CertificationRequest certificationRequest = new PKCS10CertificationRequest(getSignatureAlgorithm(),
            cert.getSubjectX500Principal(), cert.getPublicKey(), new DERSet(attributes), signingKey);
    return certificationRequest;
}

From source file:com.raphfrk.craftproxyclient.net.protocol.p16x.P16xProtocol.java

License:Open Source License

public byte[] encodeRSAPublicKey(RSAKeyParameters key) {
    if (((RSAKeyParameters) key).isPrivate()) {
        return null;
    }/*from  w w w .  j  a va 2  s.c o  m*/

    RSAKeyParameters rsaKey = (RSAKeyParameters) key;

    ASN1EncodableVector encodable = new ASN1EncodableVector();
    encodable.add(new ASN1Integer(rsaKey.getModulus()));
    encodable.add(new ASN1Integer(rsaKey.getExponent()));

    return KeyUtil.getEncodedSubjectPublicKeyInfo(
            new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE),
            new DERSequence(encodable));
}

From source file:com.rcn.service.CertificateService.java

License:Open Source License

private void addCaExtension(JcaX509v3CertificateBuilder v3CertGen) {
    v3CertGen.addExtension(X509Extension.basicConstraints, false, new BasicConstraints(true));

    v3CertGen.addExtension(X509Extension.keyUsage, false,
            new KeyUsage(KeyUsage.keyCertSign | KeyUsage.cRLSign));

    ASN1EncodableVector intPolicies = new ASN1EncodableVector();

    intPolicies.add(new PolicyInformation(new DERObjectIdentifier(ANY_POLICY)));

    v3CertGen.addExtension(X509Extension.certificatePolicies, false, new DERSequence(intPolicies));
}

From source file:com.vmware.identity.rest.core.test.util.CertificateGenerator.java

License:Open Source License

/**
 * Generate a self-signed X.509 certificate
 *
 * @param pair the key pair to use when signing the certificate
 * @param algorithm the signing algorithm to use
 * @param dn the X.509 distinguished name for the certificate
 * @return a self-signed X.509 certificate
 * @throws NoSuchAlgorithmException//w  w  w  .  j ava 2  s  . co m
 * @throws NoSuchProviderException
 * @throws InvalidKeyException
 * @throws SignatureException
 * @throws IOException
 * @throws CertificateException
 */
public static X509Certificate generateSelfSignedCertificate(KeyPair pair, AlgorithmName algorithm, String dn)
        throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException, SignatureException,
        IOException, CertificateException {
    if (Security.getProvider("BC") == null) {
        Security.addProvider(new BouncyCastleProvider());
    }

    AtomicLong serialNumber = new AtomicLong(System.currentTimeMillis());
    X500Name owner = new X500Name(dn);

    V1TBSCertificateGenerator generator = new V1TBSCertificateGenerator();
    long time = System.currentTimeMillis();

    generator.setSerialNumber(new ASN1Integer(serialNumber.getAndIncrement()));
    generator.setIssuer(owner);
    generator.setSubject(owner);
    generator.setStartDate(new Time(new Date(time - 5000)));
    generator.setEndDate(new Time(new Date(time + 30 * 60 * 1000)));
    generator.setSignature(ALGORITHM_IDS.get(algorithm));
    generator.setSubjectPublicKeyInfo(SubjectPublicKeyInfo.getInstance(pair.getPublic().getEncoded()));

    Signature sig = Signature.getInstance(algorithm.toString(), "BC");

    sig.initSign(pair.getPrivate());

    sig.update(generator.generateTBSCertificate().getEncoded(ASN1Encoding.DER));

    TBSCertificate tbsCert = generator.generateTBSCertificate();

    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(tbsCert);
    v.add(ALGORITHM_IDS.get(algorithm));
    v.add(new DERBitString(sig.sign()));

    return (X509Certificate) CertificateFactory.getInstance("X.509", "BC")
            .generateCertificate(new ByteArrayInputStream(new DERSequence(v).getEncoded(ASN1Encoding.DER)));
}

From source file:com.vvote.thirdparty.ximix.util.PartialPublicKeyInfo.java

License:Apache License

@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(new ASN1Integer(sequenceNo));
    v.add(partialKeyInfo);//from  w  ww. j a va  2 s .c om

    return new DERSequence(v);
}