当前位置: 首页>>代码示例>>Java>>正文


Java Attribute类代码示例

本文整理汇总了Java中org.bouncycastle.asn1.cms.Attribute的典型用法代码示例。如果您正苦于以下问题:Java Attribute类的具体用法?Java Attribute怎么用?Java Attribute使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Attribute类属于org.bouncycastle.asn1.cms包,在下文中一共展示了Attribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSignatureTime

import org.bouncycastle.asn1.cms.Attribute; //导入依赖的package包/类
public static Date getSignatureTime(SignerInformation signer)
{
    AttributeTable atab = signer.getSignedAttributes();
    Date result = null;
    if (atab != null)
    {
        Attribute attr = atab.get(CMSAttributes.signingTime);
        if (attr != null)
        {
            Time t = Time.getInstance(attr.getAttrValues().getObjectAt(0)
                    .toASN1Primitive());
            result = t.getDate();
        }
    }
    return result;
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:17,代码来源:SignedMailValidator.java

示例2: getInstance

import org.bouncycastle.asn1.cms.Attribute; //导入依赖的package包/类
/**
 * return an Attribute object from the given object.
 *
 * @param o the object we want converted.
 * @exception IllegalArgumentException if the object cannot be converted.
 */
public static SMIMECapabilities getInstance(
    Object o)
{
    if (o == null || o instanceof SMIMECapabilities)
    {
        return (SMIMECapabilities)o;
    }
    
    if (o instanceof ASN1Sequence)
    {
        return new SMIMECapabilities((ASN1Sequence)o);
    }

    if (o instanceof Attribute)
    {
        return new SMIMECapabilities(
            (ASN1Sequence)(((Attribute)o).getAttrValues().getObjectAt(0)));
    }

    throw new IllegalArgumentException("unknown object in factory: " + o.getClass().getName());
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:28,代码来源:SMIMECapabilities.java

示例3: buildSignedAttributes

import org.bouncycastle.asn1.cms.Attribute; //导入依赖的package包/类
private static ASN1Set buildSignedAttributes(byte[] hash, Date dateTime, X509Certificate cert) throws Exception {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(new Attribute(CMSAttributes.contentType, new DERSet(PKCSObjectIdentifiers.data)));
    if (dateTime != null)
        v.add(new Attribute(CMSAttributes.signingTime, new DERSet(new Time(dateTime))));
    v.add(new Attribute(CMSAttributes.messageDigest, new DERSet(new DEROctetString(hash))));

    // CADES support section
    ASN1EncodableVector aaV2 = new ASN1EncodableVector();
    AlgorithmIdentifier algoId = new AlgorithmIdentifier(new ASN1ObjectIdentifier(CMSSignedDataGenerator.DIGEST_SHA256), null);
    aaV2.add(algoId);
    byte[] dig = SignUtils.calculateHASH(CMSSignedDataGenerator.DIGEST_SHA256, cert.getEncoded());
    aaV2.add(new DEROctetString(dig));
    Attribute cades = new Attribute(PKCSObjectIdentifiers.id_aa_signingCertificateV2, new DERSet(new DERSequence(new DERSequence(new DERSequence(aaV2)))));
    v.add(cades);

    ASN1Set signedAttributes = new DERSet(v);
    return signedAttributes;
}
 
开发者ID:damianofalcioni,项目名称:Websocket-Smart-Card-Signer,代码行数:20,代码来源:CMSSignedDataWrapper.java

示例4: getValue

import org.bouncycastle.asn1.cms.Attribute; //导入依赖的package包/类
@Override
public Attribute getValue() throws SignerException {
	try {
        logger.info(cadesMessagesBundle.getString("info.tsa.connecting"));

        if (timeStampGenerator != null) {
              //Inicializa os valores para o timestmap
        	timeStampGenerator.initialize(content, privateKey, certificates, hash);

            //Obtem o carimbo de tempo atraves do servidor TSA
            byte[] response = timeStampGenerator.generateTimeStamp();

            //Valida o carimbo de tempo gerado
            timeStampGenerator.validateTimeStamp(content, response, hash);

            return new Attribute(new ASN1ObjectIdentifier(identifier), new DERSet(ASN1Primitive.fromByteArray(response)));
        } else {
            throw new SignerException(cadesMessagesBundle.getString("error.tsa.not.found"));
        }
    } catch (SecurityException | IOException ex) {
    }
    throw new UnsupportedOperationException(cadesMessagesBundle.getString("error.not.supported",getClass().getName()));
}
 
开发者ID:demoiselle,项目名称:signer,代码行数:24,代码来源:EscTimeStamp.java

示例5: getValue

import org.bouncycastle.asn1.cms.Attribute; //导入依赖的package包/类
@Override
public Attribute getValue() {
    try {
        X509Certificate cert = (X509Certificate) certificates[0];
        Digest digest = DigestFactory.getInstance().factoryDefault();
        digest.setAlgorithm(DigestAlgorithmEnum.SHA_1);
        byte[] hash = digest.digest(cert.getEncoded());
        X500Name dirName = new X500Name(cert.getSubjectDN().getName());
        GeneralName name = new GeneralName(dirName);
        GeneralNames issuer = new GeneralNames(name);
        ASN1Integer serial = new ASN1Integer(cert.getSerialNumber());
        IssuerSerial issuerSerial = new IssuerSerial(issuer, serial);
        ESSCertID essCertId = new ESSCertID(hash, issuerSerial);
        return new Attribute(new ASN1ObjectIdentifier(identifier), new DERSet(new DERSequence(new ASN1Encodable[]{new DERSequence(essCertId), new DERSequence(DERNull.INSTANCE)})));

    } catch (CertificateEncodingException ex) {
        throw new SignerException(ex.getMessage());
    }
}
 
开发者ID:demoiselle,项目名称:signer,代码行数:20,代码来源:SigningCertificate.java

示例6: getValue

import org.bouncycastle.asn1.cms.Attribute; //导入依赖的package包/类
@Override
public Attribute getValue() throws SignerException {
    try {
        logger.info(cadesMessagesBundle.getString("info.tsa.connecting"));

        if (timeStampGenerator != null) {
              //Inicializa os valores para o timestmap
        	timeStampGenerator.initialize(content, privateKey, certificates, hash);

            //Obtem o carimbo de tempo atraves do servidor TSA
            byte[] response = timeStampGenerator.generateTimeStamp();

            //Valida o carimbo de tempo gerado
            timeStampGenerator.validateTimeStamp(content, response, hash);

            return new Attribute(new ASN1ObjectIdentifier(identifier), new DERSet(ASN1Primitive.fromByteArray(response)));
        } else {
            throw new SignerException(cadesMessagesBundle.getString("error.tsa.not.found"));
        }
    } catch (SecurityException | IOException ex) {
        throw new SignerException(ex.getMessage());
    }
}
 
开发者ID:demoiselle,项目名称:signer,代码行数:24,代码来源:TimeStampToken.java

示例7: getValue

import org.bouncycastle.asn1.cms.Attribute; //导入依赖的package包/类
@Override
	public Attribute getValue() throws SignerException {
		try {
			X509Certificate cert = (X509Certificate) certificates[0];
			X509Certificate issuerCert = (X509Certificate) certificates[1];
			Digest digest = DigestFactory.getInstance().factoryDefault();
			digest.setAlgorithm(DigestAlgorithmEnum.SHA_256);
			byte[] certHash = digest.digest(cert.getEncoded());
			X500Name dirName = new X500Name(issuerCert.getSubjectX500Principal().getName());
			GeneralName name = new GeneralName(dirName);
			GeneralNames issuer = new GeneralNames(name);
			ASN1Integer serialNumber = new ASN1Integer(cert.getSerialNumber());
			IssuerSerial issuerSerial = new IssuerSerial(issuer, serialNumber);
			AlgorithmIdentifier algId = new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256);// SHA-256
			ESSCertIDv2 essCertIDv2 = new ESSCertIDv2(algId, certHash, issuerSerial);
//			return new Attribute(new ASN1ObjectIdentifier(identifier), new DERSet(new DERSequence(essCertIDv2)));
			return new Attribute(new ASN1ObjectIdentifier(identifier), new DERSet(new DERSequence(
					new ASN1Encodable[] { new DERSequence(essCertIDv2) })));
		} catch (CertificateEncodingException ex) {
			throw new SignerException(ex.getMessage());
		}
	}
 
开发者ID:demoiselle,项目名称:signer,代码行数:23,代码来源:SigningCertificateV2.java

示例8: addTimestamp

import org.bouncycastle.asn1.cms.Attribute; //导入依赖的package包/类
private static CMSSignedData addTimestamp(String tsaUrl, CMSSignedData signedData) throws IOException {

		Collection<SignerInformation> signerInfos = signedData.getSignerInfos().getSigners();

		// get signature of first signer (should be the only one)
		SignerInformation si = signerInfos.iterator().next();
		byte[] signature = si.getSignature();

		// send request to TSA
		byte[] token = TimeStampingClient.getTimeStampToken(tsaUrl, signature, DigestType.SHA1);

		// create new SignerInformation with TS attribute
		Attribute tokenAttr = new Attribute(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken,
				new DERSet(ASN1Primitive.fromByteArray(token)));
		ASN1EncodableVector timestampVector = new ASN1EncodableVector();
		timestampVector.add(tokenAttr);
		AttributeTable at = new AttributeTable(timestampVector);
		si = SignerInformation.replaceUnsignedAttributes(si, at);
		signerInfos.clear();
		signerInfos.add(si);
		SignerInformationStore newSignerStore = new SignerInformationStore(signerInfos);

		// create new signed data
		CMSSignedData newSignedData = CMSSignedData.replaceSigners(signedData, newSignerStore);
		return newSignedData;
	}
 
开发者ID:kaikramer,项目名称:keystore-explorer,代码行数:27,代码来源:JarSigner.java

示例9: signTimeStamp

import org.bouncycastle.asn1.cms.Attribute; //导入依赖的package包/类
/**
 * We are extending CMS Signature
 *
 * @param signer
 *            information about signer
 * @return information about SignerInformation
 */
private SignerInformation signTimeStamp(SignerInformation signer) throws IOException, TSPException {
	AttributeTable unsignedAttributes = signer.getUnsignedAttributes();

	ASN1EncodableVector vector = new ASN1EncodableVector();
	if (unsignedAttributes != null) {
		vector = unsignedAttributes.toASN1EncodableVector();
	}

	byte[] token = tsaClient.getTimeStampToken(signer.getSignature());
	ASN1ObjectIdentifier oid = PKCSObjectIdentifiers.id_aa_signatureTimeStampToken;
	ASN1Encodable signatureTimeStamp = new Attribute(oid, new DERSet(ASN1Primitive.fromByteArray(token)));

	vector.add(signatureTimeStamp);
	Attributes signedAttributes = new Attributes(vector);

	SignerInformation newSigner = SignerInformation.replaceUnsignedAttributes(signer,
			new AttributeTable(signedAttributes));

	return newSigner;
}
 
开发者ID:beat2,项目名称:pdfbox-signer,代码行数:28,代码来源:Signing.java

示例10: verifySignedReferencesToSigningCertificate

import org.bouncycastle.asn1.cms.Attribute; //导入依赖的package包/类
private boolean verifySignedReferencesToSigningCertificate() {

		final IssuerSerial signingTokenIssuerSerial = DSSASN1Utils.getIssuerSerial(signingCertificateValidity.getCertificateToken());
		final BigInteger signingTokenSerialNumber = signingTokenIssuerSerial.getSerial().getValue();
		final GeneralNames signingTokenIssuerName = signingTokenIssuerSerial.getIssuer();

		final AttributeTable signedAttributes = CMSUtils.getSignedAttributes(signerInformation);
		final Attribute signingCertificateAttributeV1 = signedAttributes.get(id_aa_signingCertificate);
		if (signingCertificateAttributeV1 != null) {

			signingCertificateValidity.setAttributePresent(true);
			verifySigningCertificateV1(signingTokenSerialNumber, signingTokenIssuerName, signingCertificateAttributeV1);
			return true;
		}
		final Attribute signingCertificateAttributeV2 = signedAttributes.get(id_aa_signingCertificateV2);
		if (signingCertificateAttributeV2 != null) {

			signingCertificateValidity.setAttributePresent(true);
			verifySigningCertificateV2(signingTokenSerialNumber, signingTokenIssuerName, signingCertificateAttributeV2);
			return true;
		}
		return false;
	}
 
开发者ID:esig,项目名称:dss,代码行数:24,代码来源:CAdESSignature.java

示例11: getContentHints

import org.bouncycastle.asn1.cms.Attribute; //导入依赖的package包/类
@Override
public String getContentHints() {
	final Attribute contentHintAttribute = getSignedAttribute(PKCSObjectIdentifiers.id_aa_contentHint);
	if (contentHintAttribute == null) {
		return null;
	}
	final ASN1Encodable asn1Encodable = contentHintAttribute.getAttrValues().getObjectAt(0);
	final ContentHints contentHints = ContentHints.getInstance(asn1Encodable);
	String contentHint = null;
	if (contentHints != null) {
		// content-type is mandatory
		contentHint = contentHints.getContentType().toString();
		// content-description is optional
		if (contentHints.getContentDescription() != null) {
			contentHint += " [" + contentHints.getContentDescription().toString() + "]";
		}
	}
	return contentHint;
}
 
开发者ID:esig,项目名称:dss,代码行数:20,代码来源:CAdESSignature.java

示例12: getTimestampX1Data

import org.bouncycastle.asn1.cms.Attribute; //导入依赖的package包/类
@Override
public byte[] getTimestampX1Data(final TimestampToken timestampToken, String canonicalizationMethod) {
	try (ByteArrayOutputStream data = new ByteArrayOutputStream()) {
		data.write(signerInformation.getSignature());
		// We don't include the outer SEQUENCE, only the attrType and
		// attrValues as stated by the TS §6.3.5, NOTE 2

		final Attribute attribute = getUnsignedAttribute(id_aa_signatureTimeStampToken);
		if (attribute != null) {
			data.write(DSSASN1Utils.getDEREncoded(attribute.getAttrType()));
			data.write(DSSASN1Utils.getDEREncoded(attribute.getAttrValues()));
		}
		// Those are common to Type 1 and Type 2
		data.write(getTimestampX2Data(timestampToken, null));
		return data.toByteArray();
	} catch (IOException e) {
		throw new DSSException(e);
	}
}
 
开发者ID:esig,项目名称:dss,代码行数:20,代码来源:CAdESSignature.java

示例13: getTimestampX2Data

import org.bouncycastle.asn1.cms.Attribute; //导入依赖的package包/类
@Override
public byte[] getTimestampX2Data(final TimestampToken timestampToken, String canonicalizationMethod) {
	try (ByteArrayOutputStream data = new ByteArrayOutputStream()) {
		// Those are common to Type 1 and Type 2
		final Attribute certAttribute = getUnsignedAttribute(id_aa_ets_certificateRefs);
		final Attribute revAttribute = getUnsignedAttribute(PKCSObjectIdentifiers.id_aa_ets_revocationRefs);
		if (certAttribute != null) {
			data.write(DSSASN1Utils.getDEREncoded(certAttribute.getAttrType()));
			data.write(DSSASN1Utils.getDEREncoded(certAttribute.getAttrValues()));
		}
		if (revAttribute != null) {
			data.write(DSSASN1Utils.getDEREncoded(revAttribute.getAttrType()));
			data.write(DSSASN1Utils.getDEREncoded(revAttribute.getAttrValues()));
		}

		return data.toByteArray();
	} catch (IOException e) {
		throw new DSSException(e);
	}
}
 
开发者ID:esig,项目名称:dss,代码行数:21,代码来源:CAdESSignature.java

示例14: filterUnauthenticatedAttributes

import org.bouncycastle.asn1.cms.Attribute; //导入依赖的package包/类
/**
 * Remove any archive-timestamp-v2/3 attribute added after the
 * timestampToken
 */
private ASN1Sequence filterUnauthenticatedAttributes(ASN1Set unauthenticatedAttributes, TimestampToken timestampToken) {
	ASN1EncodableVector result = new ASN1EncodableVector();
	for (int ii = 0; ii < unauthenticatedAttributes.size(); ii++) {

		final Attribute attribute = Attribute.getInstance(unauthenticatedAttributes.getObjectAt(ii));
		final ASN1ObjectIdentifier attrType = attribute.getAttrType();
		if (id_aa_ets_archiveTimestampV2.equals(attrType) || id_aa_ets_archiveTimestampV3.equals(attrType)) {
			try {

				TimeStampToken token = new TimeStampToken(
						new CMSSignedData(DSSASN1Utils.getDEREncoded(attribute.getAttrValues().getObjectAt(0).toASN1Primitive())));
				if (!token.getTimeStampInfo().getGenTime().before(timestampToken.getGenerationTime())) {
					continue;
				}
			} catch (Exception e) {
				throw new DSSException(e);
			}
		}
		result.add(unauthenticatedAttributes.getObjectAt(ii));
	}
	return new DERSequence(result);
}
 
开发者ID:esig,项目名称:dss,代码行数:27,代码来源:CAdESSignature.java

示例15: getArchiveTimestampDataV3

import org.bouncycastle.asn1.cms.Attribute; //导入依赖的package包/类
public byte[] getArchiveTimestampDataV3(SignerInformation signerInformation, Attribute atsHashIndexAttribute, byte[] originalDocumentDigest)
		throws DSSException {

	final CMSSignedData cmsSignedData = cadesSignature.getCmsSignedData();
	final byte[] encodedContentType = getEncodedContentType(cmsSignedData); // OID
	final byte[] signedDataDigest = originalDocumentDigest;
	final byte[] encodedFields = getSignedFields(signerInformation);
	final byte[] encodedAtsHashIndex = DSSASN1Utils.getDEREncoded(atsHashIndexAttribute.getAttrValues().getObjectAt(0));
	/**
	 * The input for the archive-time-stamp-v3’s message imprint computation shall be the concatenation (in the
	 * order shown by the list below) of the signed data hash (see bullet 2 below) and certain fields in their
	 * binary encoded
	 * form without any modification and including the tag, length and value octets:
	 */
	final byte[] dataToTimestamp = DSSUtils.concatenate(encodedContentType, signedDataDigest, encodedFields, encodedAtsHashIndex);
	if (LOG.isDebugEnabled()) {
		LOG.debug("eContentType={}", Utils.toHex(encodedContentType));
		LOG.debug("signedDataDigest={}", Utils.toHex(signedDataDigest));
		LOG.debug("encodedFields=see above");
		LOG.debug("encodedAtsHashIndex={}", Utils.toHex(encodedAtsHashIndex));
		// LOG.debug("Archive Timestamp Data v3 is: {}", Hex.encodeHexString(dataToTimestamp));
	}
	return dataToTimestamp;
}
 
开发者ID:esig,项目名称:dss,代码行数:25,代码来源:CadesLevelBaselineLTATimestampExtractor.java


注:本文中的org.bouncycastle.asn1.cms.Attribute类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。