Example usage for org.bouncycastle.asn1 DERTaggedObject DERTaggedObject

List of usage examples for org.bouncycastle.asn1 DERTaggedObject DERTaggedObject

Introduction

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

Prototype

public DERTaggedObject(int tagNo, ASN1Encodable encodable) 

Source Link

Usage

From source file:bluecrystal.bcdeps.helper.DerEncoder.java

License:Open Source License

public byte[] buildCmsBody(String signedHashId, X509Certificate certContent, byte[] content, String hashId,
        int version) throws CertificateEncodingException, IOException {
    final ASN1EncodableVector whole = new ASN1EncodableVector();
    whole.add(new DERObjectIdentifier(CMS_SIGNED_ID));

    final ASN1EncodableVector body = new ASN1EncodableVector();
    // ----- versao -------
    // final int version = 1;
    body.add(new DERInteger(version));
    buildDigestAlg(body, hashId);/*from w w  w  . j  a  v  a  2  s .com*/
    // buildContentInfo(body, content);
    buildCerts(body, certContent);

    buildSignerInfo(body, signedHashId, certContent, hashId);

    whole.add(new DERTaggedObject(0, new DERSequence(body)));

    return genOutput(new DERSequence(whole));

}

From source file:bluecrystal.bcdeps.helper.DerEncoder.java

License:Open Source License

public byte[] buildCmsBody(byte[] signedHashId, X509Certificate certContent, List<X509Certificate> chain,
        int hashId, int version, int attachSize) throws Exception {
    final ASN1EncodableVector whole = new ASN1EncodableVector(); // 0 SEQ
    whole.add(new DERObjectIdentifier(CMS_SIGNED_ID)); // 1 SEQ

    final ASN1EncodableVector body = new ASN1EncodableVector();
    // ----- versao -------
    // final int version = 1;
    body.add(new DERInteger(version)); // 3 INT
    buildDigestAlg(body, getHashAlg(hashId)); // 3 SET
    buildContentInfo(body, attachSize); // 3 SEQ
    buildCerts(body, chain); // 3 CS

    buildSignerInfo(body, signedHashId, certContent, hashId); // 3 SET

    whole.add(new DERTaggedObject(0, new DERSequence( // 2 SEQ
            body))); // 1 CS

    return genOutput(new DERSequence(whole));

}

From source file:bluecrystal.bcdeps.helper.DerEncoder.java

License:Open Source License

public byte[] buildADRBBody(List<AppSignedInfoEx> listAsiEx, SignPolicy signPol, List<X509Certificate> chain,
        int version, boolean signingCertFallback, int attachSize) throws Exception {
    // AppSignedInfoEx asiEx = listAsiEx.get(0);
    final ASN1EncodableVector whole = new ASN1EncodableVector(); // 0 SEQ
    whole.add(new DERObjectIdentifier(CMS_SIGNED_ID)); // 1 SEQ

    final ASN1EncodableVector body = new ASN1EncodableVector();
    // ----- versao -------
    // final int version = 1;
    body.add(new DERInteger(version)); // 3 INT

    List<String> listHashId = createHashList(listAsiEx);
    buildDigestAlg(body, listHashId); // 3 SET

    buildContentInfo(body, attachSize); // 3 SEQ
    if (chain != null) {
        buildCerts(body, chain); // 3 CS
    } else {/*from   w ww.  j  a v  a 2 s.  c  o  m*/
        buildCertsASIE(body, listAsiEx); // 3 CS
    }

    // buildADRBSignerInfo(body, asiEx.getSignedHash(), asiEx.getX509(),
    // asiEx.getOrigHash(), signPol.getPolicyHash(),
    // asiEx.getCertHash(), asiEx.getSigningTime(),
    // asiEx.getIdSha(), signPol.getPolicyUri(),
    // signPol.getPolicyId(),
    // signingCertFallback); // 3 SET

    buildADRBSignerInfo(body, listAsiEx, signPol, signingCertFallback); // 3
    // SET

    whole.add(new DERTaggedObject(0, new DERSequence( // 2 SEQ
            body))); // 1 CS

    return genOutput(new DERSequence(whole));

}

From source file:bluecrystal.bcdeps.helper.DerEncoder.java

License:Open Source License

private void buildContentInfo(final ASN1EncodableVector body, int size) {

    // ------ Content Info
    ASN1EncodableVector contentInfoVector = new ASN1EncodableVector();
    contentInfoVector.add(new DERObjectIdentifier(ID_PKCS7_DATA)); // 4 OID
    if (size != DETACHED) {
        byte[] content = new byte[size];
        for (int i = 0; i < size; i++) {
            content[i] = (byte) 0xba;
        }/*from w  w w.j  a v a2s.  c o m*/
        contentInfoVector.add(new DERTaggedObject(0, new DEROctetString(content)));
    }
    // CONTENT INFO

    final DERSequence contentinfo = new DERSequence(contentInfoVector); // 3
    // SEQ
    body.add(contentinfo);

}

From source file:com.github.horrorho.inflatabledonkey.data.der.EncryptedKeys.java

License:Open Source License

@Override
public ASN1Primitive toASN1Primitive() {
    DERTaggedObject cont0Encodable = cont0().map(DEROctetString::new).map(e -> new DERTaggedObject(CONT0, e))
            .orElseGet(null);/*  w  ww. j av  a2  s .  com*/

    ASN1EncodableVector vector = DER.vector(new ASN1Integer(x), DER.toSet(encryptedKeySet), cont0Encodable);

    return new DERSequence(vector);
}

From source file:com.github.horrorho.inflatabledonkey.data.der.ObjectSignature.java

License:Open Source License

@Override
public ASN1Primitive toASN1Primitive() {

    DERTaggedObject signatureInfoEncodable = signatureInfo.map(e -> new DERTaggedObject(SIGNATURE_INFO, e))
            .orElseGet(null);//from www .  ja va2  s  .  c  o m

    DERTaggedObject signatureEncodable = signature.map(e -> new DERTaggedObject(SIGNATURE, e)).orElseGet(null);

    ASN1EncodableVector vector = DER.vector(signatureInfoEncodable, signatureEncodable);

    return new DERSequence(vector);
}

From source file:com.github.horrorho.inflatabledonkey.data.der.ProtectionInfo.java

License:Open Source License

@Override
public ASN1Primitive toASN1Primitive() {

    DERTaggedObject dataEncodable = data.map(DEROctetString::new).map(e -> new DERTaggedObject(DATA, e))
            .orElseGet(null);/*from  www  .j  a  v a 2 s  . c o m*/

    DERTaggedObject signatureEncodable = signature.map(e -> new DERTaggedObject(SIGNATURE, e)).orElseGet(null);

    DERTaggedObject tagEncodable = tag.map(DEROctetString::new).map(e -> new DERTaggedObject(TAG, e))
            .orElseGet(null);

    DERTaggedObject cont3Encodable = cont3.map(DEROctetString::new).map(e -> new DERTaggedObject(CONT3, e))
            .orElseGet(null);

    DERTaggedObject cont4Encodable = cont4.map(DEROctetString::new).map(e -> new DERTaggedObject(CONT4, e))
            .orElseGet(null);

    ASN1EncodableVector vector = DER.vector(encryptedKeys, dataEncodable, signatureEncodable,
            new DEROctetString(hmac()), tagEncodable, cont3Encodable, cont4Encodable);

    DERSequence sequence = new DERSequence(vector);
    return DER.toApplicationSpecific(APPLICATION_TAG, sequence);
}

From source file:com.github.horrorho.inflatabledonkey.data.der.PublicKeyInfo.java

License:Open Source License

@Override
public ASN1Primitive toASN1Primitive() {

    DERTaggedObject signatureInfoEncodable = signatureInfo.map(e -> new DERTaggedObject(SIGNATURE_INFO, e))
            .orElse(null);/*from w  w  w.j a  v  a 2s. c  om*/

    DERTaggedObject signatureEncodable = signature.map(e -> new DERTaggedObject(SIGNATURE, e)).orElse(null);

    DERTaggedObject extendedSignatureEncodable = extendedSignature
            .map(e -> new DERTaggedObject(EXTENDED_SIGNATURE, e)).orElse(null);

    ASN1EncodableVector vector = DER.vector(new ASN1Integer(service), new ASN1Integer(type),
            new DEROctetString(key()), signatureInfoEncodable, signatureEncodable, extendedSignatureEncodable);

    DERSequence sequence = new DERSequence(vector);
    return DER.toApplicationSpecific(APPLICATION_TAG, sequence);
}

From source file:com.github.horrorho.inflatabledonkey.data.der.SECPrivateKey.java

License:Open Source License

@Override
public ASN1Primitive toASN1Primitive() {
    DERTaggedObject parametersEncodable = parameters().map(DEROctetString::new)
            .map(e -> new DERTaggedObject(PARAMETERS, e)).orElseGet(null);

    DERTaggedObject publicKeyEncodable = publicKey().map(DERBitString::new)
            .map(e -> new DERTaggedObject(PUBLIC_KEY, e)).orElseGet(null);

    ASN1EncodableVector vector = DER.vector(new ASN1Integer(version), new DEROctetString(privateKey),
            parametersEncodable, publicKeyEncodable);

    return new DERSequence(vector);
}

From source file:com.google.bitcoin.core.ECKey.java

License:Apache License

/**
 * Output this ECKey as an ASN.1 encoded private key, as understood by OpenSSL or used by the BitCoin reference
 * implementation in its wallet storage format.
 *//*from  www. j  a  v  a  2 s . c  om*/
public byte[] toASN1() {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream(400);

        // ASN1_SEQUENCE(EC_PRIVATEKEY) = {
        //   ASN1_SIMPLE(EC_PRIVATEKEY, version, LONG),
        //   ASN1_SIMPLE(EC_PRIVATEKEY, privateKey, ASN1_OCTET_STRING),
        //   ASN1_EXP_OPT(EC_PRIVATEKEY, parameters, ECPKPARAMETERS, 0),
        //   ASN1_EXP_OPT(EC_PRIVATEKEY, publicKey, ASN1_BIT_STRING, 1)
        // } ASN1_SEQUENCE_END(EC_PRIVATEKEY)
        DERSequenceGenerator seq = new DERSequenceGenerator(baos);
        seq.addObject(new ASN1Integer(1)); // version
        seq.addObject(new DEROctetString(priv.toByteArray()));
        seq.addObject(new DERTaggedObject(0, SECNamedCurves.getByName("secp256k1").toASN1Primitive()));
        seq.addObject(new DERTaggedObject(1, new DERBitString(getPubKey())));
        seq.close();
        return baos.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException(e); // Cannot happen, writing to memory stream.
    }
}