Search in sources :

Example 96 with ASN1Set

use of com.github.zhenwei.core.asn1.ASN1Set in project LinLong-Java by zhenwei1108.

the class PKCS10CertificationRequest method getAttributes.

/**
 * Return an  array of attributes matching the passed in type OID.
 *
 * @param type the type of the attribute being looked for.
 * @return an array of Attribute of the requested type, zero length if none present.
 */
public Attribute[] getAttributes(ASN1ObjectIdentifier type) {
    ASN1Set attrSet = certificationRequest.getCertificationRequestInfo().getAttributes();
    if (attrSet == null) {
        return EMPTY_ARRAY;
    }
    List list = new ArrayList();
    for (int i = 0; i != attrSet.size(); i++) {
        Attribute attr = Attribute.getInstance(attrSet.getObjectAt(i));
        if (attr.getAttrType().equals(type)) {
            list.add(attr);
        }
    }
    if (list.size() == 0) {
        return EMPTY_ARRAY;
    }
    return (Attribute[]) list.toArray(new Attribute[list.size()]);
}
Also used : ASN1Set(com.github.zhenwei.core.asn1.ASN1Set) Attribute(com.github.zhenwei.core.asn1.pkcs.Attribute) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 97 with ASN1Set

use of com.github.zhenwei.core.asn1.ASN1Set in project LinLong-Java by zhenwei1108.

the class PKCS10CertificationRequest method getAttributes.

/**
 * Return the attributes, if any associated with this request.
 *
 * @return an array of Attribute, zero length if none present.
 */
public Attribute[] getAttributes() {
    ASN1Set attrSet = certificationRequest.getCertificationRequestInfo().getAttributes();
    if (attrSet == null) {
        return EMPTY_ARRAY;
    }
    Attribute[] attrs = new Attribute[attrSet.size()];
    for (int i = 0; i != attrSet.size(); i++) {
        attrs[i] = Attribute.getInstance(attrSet.getObjectAt(i));
    }
    return attrs;
}
Also used : ASN1Set(com.github.zhenwei.core.asn1.ASN1Set) Attribute(com.github.zhenwei.core.asn1.pkcs.Attribute)

Example 98 with ASN1Set

use of com.github.zhenwei.core.asn1.ASN1Set in project LinLong-Java by zhenwei1108.

the class BCEdDSAPrivateKey method getEncoded.

public byte[] getEncoded() {
    try {
        ASN1Set attrSet = ASN1Set.getInstance(attributes);
        PrivateKeyInfo privInfo = PrivateKeyInfoFactory.createPrivateKeyInfo(eddsaPrivateKey, attrSet);
        if (hasPublicKey && !Properties.isOverrideSet("com.github.zhenwei.pkix.pkcs8.v1_info_only")) {
            return privInfo.getEncoded();
        } else {
            return new PrivateKeyInfo(privInfo.getPrivateKeyAlgorithm(), privInfo.parsePrivateKey(), attrSet).getEncoded();
        }
    } catch (IOException e) {
        return null;
    }
}
Also used : ASN1Set(com.github.zhenwei.core.asn1.ASN1Set) IOException(java.io.IOException) PrivateKeyInfo(com.github.zhenwei.core.asn1.pkcs.PrivateKeyInfo)

Example 99 with ASN1Set

use of com.github.zhenwei.core.asn1.ASN1Set in project LinLong-Java by zhenwei1108.

the class BCXDHPrivateKey method getEncoded.

public byte[] getEncoded() {
    try {
        ASN1Set attrSet = ASN1Set.getInstance(attributes);
        PrivateKeyInfo privInfo = PrivateKeyInfoFactory.createPrivateKeyInfo(xdhPrivateKey, attrSet);
        if (hasPublicKey && !Properties.isOverrideSet("com.github.zhenwei.pkix.pkcs8.v1_info_only")) {
            return privInfo.getEncoded();
        } else {
            return new PrivateKeyInfo(privInfo.getPrivateKeyAlgorithm(), privInfo.parsePrivateKey(), attrSet).getEncoded();
        }
    } catch (IOException e) {
        return null;
    }
}
Also used : ASN1Set(com.github.zhenwei.core.asn1.ASN1Set) IOException(java.io.IOException) PrivateKeyInfo(com.github.zhenwei.core.asn1.pkcs.PrivateKeyInfo)

Example 100 with ASN1Set

use of com.github.zhenwei.core.asn1.ASN1Set in project LinLong-Java by zhenwei1108.

the class P7bBuilder method buildP7b.

public static ArrayList<X509Certificate> buildP7b(byte[] data) throws WeGooCryptoException {
    ContentInfo contentInfo = ContentInfo.getInstance(data);
    // P7B 的 contentType应该是这个
    // ASN1ObjectIdentifier signedData = PKCSObjectIdentifiers.signedData;
    SignedData signedData = SignedData.getInstance(contentInfo.getContent());
    if (signedData == null)
        throw new WeGooCryptoException(CryptoExceptionMassageEnum.build_err);
    ASN1Set certs = signedData.getCertificates();
    ArrayList<X509Certificate> list = new ArrayList<>();
    for (ASN1Encodable cert : certs) {
        list.add(CertBuilder.getInstance(cert).getCert());
    }
    return list;
}
Also used : WeGooCryptoException(com.github.zhenwei.core.exception.WeGooCryptoException) SignedData(com.github.zhenwei.core.asn1.pkcs.SignedData) ASN1Set(com.github.zhenwei.core.asn1.ASN1Set) ContentInfo(com.github.zhenwei.core.asn1.pkcs.ContentInfo) ArrayList(java.util.ArrayList) ASN1Encodable(com.github.zhenwei.core.asn1.ASN1Encodable) X509Certificate(java.security.cert.X509Certificate)

Aggregations

ASN1Set (org.bouncycastle.asn1.ASN1Set)67 ArrayList (java.util.ArrayList)51 IOException (java.io.IOException)34 ASN1Set (com.unboundid.asn1.ASN1Set)33 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)30 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)30 ASN1Set (com.github.zhenwei.core.asn1.ASN1Set)26 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)22 ASN1Element (com.unboundid.asn1.ASN1Element)21 NotNull (com.unboundid.util.NotNull)21 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)19 List (java.util.List)17 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)17 DEROctetString (org.bouncycastle.asn1.DEROctetString)16 Enumeration (java.util.Enumeration)15 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)14 OutputStream (java.io.OutputStream)12 Test (org.testng.annotations.Test)12 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)11 ASN1Enumerated (com.unboundid.asn1.ASN1Enumerated)11