Example usage for org.bouncycastle.asn1 ASN1EncodableVector ASN1EncodableVector

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

Introduction

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

Prototype

public ASN1EncodableVector() 

Source Link

Usage

From source file:de.tsenger.animamea.asn1.FileID.java

License:Open Source License

/**
 * The definition of FileID is/*  w  w  w  . j a  v a2s . co m*/
  * <pre>
  * FileID ::= SEQUENCE {
  *      fid      OCTET STRING (SIZE(2)),
  *      sfid   OCTET STRING (SIZE(1)) OPTIONAL
  * }
  * </pre>
 */
@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(fid);
    if (sfid != null)
        v.add(sfid);

    return ASN1Sequence.getInstance(v);
}

From source file:de.tsenger.animamea.asn1.PaceDomainParameterInfo.java

License:Open Source License

/**
 * The definition of PaceDomainParameterInfo is
  * <pre>/*w  w  w  .  ja  va  2  s . co m*/
  * PaceDomainParameterInfo ::= SEQUENCE {
  *      protocol      OBJECT IDENTIFIER(,
  *                  id-PACE-DH-GM |
  *                  id-PACE-ECDH-GM |
  *                  id-PACE-DH-IM |
  *                  id-PACE-ECDH-IM),
  *      domainParameter   AlgorithmIdentifier,
  *      parameterId      INTEGER OPTIONAL
  * }
  * </pre>
 */
@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(protocol);
    v.add(domainParameter);
    if (parameterId != null)
        v.add(parameterId);

    return ASN1Sequence.getInstance(v);
}

From source file:de.tsenger.animamea.asn1.PaceInfo.java

License:Open Source License

/**
 * The definition of PaceInfo is/*from w  w  w. j  a v a 2  s.c o  m*/
  * <pre>
  * PaceInfo ::= SEQUENCE {
  *      protocol   OBJECT IDENTIFIER(
 *               id-PACE-DH-GM-3DES-CBC-CBC |
 *               id-PACE-DH-GM-AES-CBC-CMAC-128 |
 *               id-PACE-DH-GM-AES-CBC-CMAC-192 |
 *               id-PACE-DH-GM-AES-CBC-CMAC-256 |
 *               id-PACE-ECDH-GM-3DES-CBC-CBC |
 *               id-PACE-ECDH-GM-AES-CBC-CMAC-128 |
 *               id-PACE-ECDH-GM-AES-CBC-CMAC-192 |
 *               id-PACE-ECDH-GM-AES-CBC-CMAC-256,
 *               id-PACE-DH-IM-3DES-CBC-CBC |
 *               id-PACE-DH-IM-AES-CBC-CMAC-128 |
 *               id-PACE-DH-IM-AES-CBC-CMAC-192 |
 *               id-PACE-DH-IM-AES-CBC-CMAC-256 |
 *               id-PACE-ECDH-IM-3DES-CBC-CBC |
 *               id-PACE-ECDH-IM-AES-CBC-CMAC-128 |
 *               id-PACE-ECDH-IM-AES-CBC-CMAC-192 |
 *               id-PACE-ECDH-IM-AES-CBC-CMAC-256),
  *      version      INTEGER, -- SHOULD be 2
  *      parameterId   INTEGER OPTIONAL
  * }
  * </pre>
 */
@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(protocol);
    v.add(version);
    if (parameterId != null)
        v.add(parameterId);

    return ASN1Sequence.getInstance(v);
}

From source file:de.tsenger.animamea.asn1.PrivilegedTerminalInfo.java

License:Open Source License

/**
 * The definition of PrivilegedTerminalInfo is
  * <pre>//  w w  w  .  j a va 2 s  .co  m
  * PrivilegedTerminalInfo ::= SEQUENCE {
  *      protocol            OBJECT IDENTIFIER(id-PT),
  *      privilegedTerminalInfos   SecurityInfos
  * }
  * </pre>
 */
@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(protocol);
    v.add(secinfos);

    return ASN1Sequence.getInstance(v);
}

From source file:de.tsenger.animamea.asn1.SecurityInfos.java

License:Open Source License

/**
 * The definition of SecurityInfos is//from www . ja va  2  s.  com
  * <pre>
  * SecurityInfos ::= SET OF SecurityInfo
  * 
  * SecurityInfo ::= SEQUENCE {
  *       protocol      OBJECT IDENTIFIER,
  *       requiredData   ANY DEFINED BY protocol,
  *       optionalData   ANY DEFINED BY protocol OPTIONAL
  * }
  * </pre>
 */
@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();

    for (TerminalAuthenticationInfo item : terminalAuthenticationInfoList) {
        v.add(item);
    }
    for (ChipAuthenticationInfo item : chipAuthenticationInfoList) {
        v.add(item);
    }
    for (ChipAuthenticationDomainParameterInfo item : chipAuthenticationDomainParameterInfoList) {
        v.add(item);
    }
    for (ChipAuthenticationPublicKeyInfo item : chipAuthenticationPublicKeyInfoList) {
        v.add(item);
    }
    for (PaceInfo item : paceInfoList) {
        v.add(item);
    }
    for (PaceDomainParameterInfo item : paceDomainParameterInfoList) {
        v.add(item);
    }
    for (CardInfoLocator item : cardInfoLocatorList) {
        v.add(item);
    }
    for (PrivilegedTerminalInfo item : privilegedTerminalInfoList) {
        v.add(item);
    }

    return ASN1Set.getInstance(v);
}

From source file:de.tsenger.animamea.asn1.SubjectPublicKeyInfo.java

License:Open Source License

/** 
 * The SubjectPublicKeyInfo object./*from w ww.j  a va 2s  .  c o m*/
 * <pre>
 * SubjectPublicKeyInfo ::= SEQUENCE {
 *   algorithm         AlgorithmIdentifier,
 *   subjectPublicKey   BIT STRING
 * }
 * </pre>
 * 
 */
@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector vec = new ASN1EncodableVector();
    vec.add(algorithm);
    vec.add(subjectPublicKey);
    return ASN1Sequence.getInstance(vec);
}

From source file:de.tsenger.animamea.asn1.TerminalAuthenticationInfo.java

License:Open Source License

/**
 * The definition of TerminalAuthenticationInfo is
  * <pre>/*from  w w w .j  a  v  a 2  s. c o m*/
  * TerminalAuthenticationInfo ::= SEQUENCE {
  *      protocol   OBJECT IDENTIFIER(id-TA),
  *      version      INTEGER, -- MUST be 1 or 2
  *      efCVCA      FileID OPTIONAL -- MUST NOT be used for version 2
  * }
  * </pre>
 */
@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(protocol);
    v.add(version);
    if (fileID != null)
        v.add(fileID);

    return ASN1Sequence.getInstance(v);
}

From source file:dorkbox.util.crypto.CryptoX509.java

License:Apache License

/**
 * Creates a NEW signature block that contains the pkcs7 (minus content, which is the .SF file)
 * signature of the .SF file.//w ww.j a v  a 2s  .com
 *
 * It contains the hash of the data, and the verification signature.
 */
public static byte[] createSignature(byte[] signatureSourceData, X509CertificateHolder x509CertificateHolder,
        AsymmetricKeyParameter privateKey) {

    try {
        CMSTypedData content = new CMSProcessableByteArray(signatureSourceData);

        ASN1ObjectIdentifier contentTypeOID = new ASN1ObjectIdentifier(content.getContentType().getId());
        ASN1EncodableVector digestAlgs = new ASN1EncodableVector();
        ASN1EncodableVector signerInfos = new ASN1EncodableVector();

        AlgorithmIdentifier sigAlgId = x509CertificateHolder.getSignatureAlgorithm();
        AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);

        // use the bouncy-castle lightweight API to generate a hash of the signature source data (usually the signature file bytes)
        BcContentSignerBuilder contentSignerBuilder;
        AlgorithmIdentifier digEncryptionAlgorithm;

        if (privateKey instanceof ECPrivateKeyParameters) {
            contentSignerBuilder = new BcECDSAContentSignerBuilder(sigAlgId, digAlgId);
            digEncryptionAlgorithm = new AlgorithmIdentifier(DSAUtil.dsaOids[0], null); // 1.2.840.10040.4.1  // DSA hashID
        } else if (privateKey instanceof DSAPrivateKeyParameters) {
            contentSignerBuilder = new BcDSAContentSignerBuilder(sigAlgId, digAlgId);
            digEncryptionAlgorithm = new AlgorithmIdentifier(DSAUtil.dsaOids[0], null); // 1.2.840.10040.4.1  // DSA hashID
        } else if (privateKey instanceof RSAPrivateCrtKeyParameters) {
            contentSignerBuilder = new BcRSAContentSignerBuilder(sigAlgId, digAlgId);
            digEncryptionAlgorithm = new AlgorithmIdentifier(RSAUtil.rsaOids[0], null); // 1.2.840.113549.1.1.1 // RSA hashID
        } else {
            throw new RuntimeException("Invalid signature type. Only ECDSA, DSA, RSA supported.");
        }

        ContentSigner hashSigner = contentSignerBuilder.build(privateKey);
        OutputStream outputStream = hashSigner.getOutputStream();
        outputStream.write(signatureSourceData, 0, signatureSourceData.length);
        outputStream.flush();
        byte[] sigBytes = hashSigner.getSignature();

        SignerIdentifier sigId = new SignerIdentifier(
                new IssuerAndSerialNumber(x509CertificateHolder.toASN1Structure()));

        SignerInfo inf = new SignerInfo(sigId, digAlgId, null, digEncryptionAlgorithm,
                new DEROctetString(sigBytes), (ASN1Set) null);

        digestAlgs.add(inf.getDigestAlgorithm());
        signerInfos.add(inf);

        ASN1EncodableVector certs = new ASN1EncodableVector();
        certs.add(x509CertificateHolder.toASN1Structure());

        ContentInfo encInfo = new ContentInfo(contentTypeOID, null);
        SignedData sd = new SignedData(new DERSet(digestAlgs), encInfo, new BERSet(certs), null,
                new DERSet(signerInfos));

        ContentInfo contentInfo = new ContentInfo(CMSObjectIdentifiers.signedData, sd);
        CMSSignedData cmsSignedData2 = new CMSSignedData(content, contentInfo);

        return cmsSignedData2.getEncoded();
    } catch (Throwable t) {
        logger.error("Error signing data.", t);
        throw new RuntimeException("Error trying to sign data. " + t.getMessage());
    }
}

From source file:edu.tamu.tcat.crypto.bouncycastle.ASN1SeqKeyImpl.java

License:Apache License

private static ASN1Sequence getParameters(ECParameterSpec ecParameterSpec) throws EncodingException {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(new ASN1Integer(1));
    EllipticCurve curve = ecParameterSpec.getCurve();

    ASN1Sequence fieldId = getField(curve.getField());
    v.add(fieldId);//ww  w  .j a va2  s.c  o m
    v.add(getCurve(curve));

    org.bouncycastle.math.ec.ECPoint g = EC5Util.convertPoint(ecParameterSpec, ecParameterSpec.getGenerator(),
            false);
    byte[] encoded = g.getEncoded();
    v.add(new DEROctetString(encoded));

    v.add(new ASN1Integer(ecParameterSpec.getOrder()));
    v.add(new ASN1Integer(ecParameterSpec.getCofactor()));

    return new DERSequence(v);
}

From source file:edu.tamu.tcat.crypto.bouncycastle.ASN1SeqKeyImpl.java

License:Apache License

private static ASN1Sequence getField(ECField field) throws EncodingException {
    ASN1EncodableVector v = new ASN1EncodableVector();
    if (field instanceof ECFieldFp) {
        ECFieldFp fpField = (ECFieldFp) field;
        v.add(new ASN1ObjectIdentifier("1.2.840.10045.1.1"));
        v.add(new ASN1Integer(fpField.getP()));
    } else//from  w  w w. jav a 2  s  .  c o m
        throw new EncodingException("Only know how to encode prime fields");

    return new DERSequence(v);
}