• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java CMSAttributes类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getSignatureTime

import org.bouncycastle.asn1.cms.CMSAttributes; //导入依赖的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: getSigningTime

import org.bouncycastle.asn1.cms.CMSAttributes; //导入依赖的package包/类
private Time getSigningTime() throws CMSException
{
    ASN1Primitive validSigningTime = getSingleValuedSignedAttribute(
        CMSAttributes.signingTime, "signing-time");

    if (validSigningTime == null)
    {
        return null;
    }

    try
    {
        return Time.getInstance(validSigningTime);
    }
    catch (IllegalArgumentException e)
    {
        throw new CMSException("signing-time attribute value not a valid 'Time' structure");
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:20,代码来源:SignerInformation.java


示例3: buildSignedAttributes

import org.bouncycastle.asn1.cms.CMSAttributes; //导入依赖的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: getDataAssinatura

import org.bouncycastle.asn1.cms.CMSAttributes; //导入依赖的package包/类
/**
 * Retorna a data da criacao da assinatura
 * NAO EH CARIMBO DE TEMPO 
 * @return Date
 * @see Date
 */
public Date getDataAssinatura(){
	
	try {
		getCertificadoAssinante();
	} catch (Exception e) {
		return null;
	}
       AttributeTable attr = signerInfo.getSignedAttributes();

       if (attr != null)
       {
           Attribute t = attr.get(CMSAttributes.signingTime);
           if (t != null)
           {
               Time   time = Time.getInstance(
                                   t.getAttrValues().getObjectAt(0).getDERObject());
               return time.getDate();
           }
       }
       return null;
}
 
开发者ID:esaito,项目名称:ExemplosDemoiselle,代码行数:28,代码来源:TabeliaoAssinaturaPKCS7.java


示例5: getContentDigest

import org.bouncycastle.asn1.cms.CMSAttributes; //导入依赖的package包/类
public byte[] getContentDigest()
{
    if (authAttrs != null)
    {
        return ASN1OctetString.getInstance(getAuthAttrs().get(CMSAttributes.messageDigest).getAttrValues().getObjectAt(0)).getOctets();
    }

    return null;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:10,代码来源:CMSAuthenticatedData.java


示例6: getContentDigest

import org.bouncycastle.asn1.cms.CMSAttributes; //导入依赖的package包/类
/**
 * This will only be valid after the content has been read.
 *
 * @return the contents of the messageDigest attribute, if available. Null if not present.
 */
public byte[] getContentDigest()
{
    if (authAttrs != null)
    {
        return ASN1OctetString.getInstance(authAttrs.get(CMSAttributes.messageDigest).getAttrValues().getObjectAt(0)).getOctets();
    }

    return null;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:15,代码来源:CMSAuthenticatedDataParser.java


示例7: addCounterSigners

import org.bouncycastle.asn1.cms.CMSAttributes; //导入依赖的package包/类
/**
 * Return a signer information object with passed in SignerInformationStore representing counter
 * signatures attached as an unsigned attribute.
 *
 * @param signerInformation the signerInfo to be used as the basis.
 * @param counterSigners signer info objects carrying counter signature.
 * @return a copy of the original SignerInformationObject with the changed attributes.
 */
public static SignerInformation addCounterSigners(
    SignerInformation        signerInformation,
    SignerInformationStore   counterSigners)
{
    // TODO Perform checks from RFC 3852 11.4

    SignerInfo          sInfo = signerInformation.info;
    AttributeTable      unsignedAttr = signerInformation.getUnsignedAttributes();
    ASN1EncodableVector v;

    if (unsignedAttr != null)
    {
        v = unsignedAttr.toASN1EncodableVector();
    }
    else
    {
        v = new ASN1EncodableVector();
    }

    ASN1EncodableVector sigs = new ASN1EncodableVector();

    for (Iterator it = counterSigners.getSigners().iterator(); it.hasNext();)
    {
        sigs.add(((SignerInformation)it.next()).toASN1Structure());
    }

    v.add(new Attribute(CMSAttributes.counterSignature, new DERSet(sigs)));

    return new SignerInformation(
            new SignerInfo(sInfo.getSID(), sInfo.getDigestAlgorithm(),
                sInfo.getAuthenticatedAttributes(), sInfo.getDigestEncryptionAlgorithm(), sInfo.getEncryptedDigest(), new DERSet(v)),
                signerInformation.contentType, signerInformation.content, null);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:42,代码来源:SignerInformation.java


示例8: signWithSeparatedHashing

import org.bouncycastle.asn1.cms.CMSAttributes; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/41767351/create-pkcs7-signature-from-file-digest">
 * Create pkcs7 signature from file digest
 * </a>
 * <p>
 * The OP's <code>sign</code> method after fixing some errors. The
 * OP's original method is {@link #signBySnox(InputStream)}. The
 * errors were
 * </p>
 * <ul>
 * <li>multiple attempts at reading the {@link InputStream} parameter;
 * <li>convoluted creation of final CMS container.
 * </ul>
 * <p>
 * Additionally this method uses SHA256 instead of SHA-1.
 * </p>
 */
public byte[] signWithSeparatedHashing(InputStream content) throws IOException
{
    try
    {
        // Digest generation step
        MessageDigest md = MessageDigest.getInstance("SHA256", "BC");
        byte[] digest = md.digest(IOUtils.toByteArray(content));

        // Separate signature container creation step
        List<Certificate> certList = Arrays.asList(chain);
        JcaCertStore certs = new JcaCertStore(certList);

        CMSSignedDataGenerator gen = new CMSSignedDataGenerator();

        Attribute attr = new Attribute(CMSAttributes.messageDigest,
                new DERSet(new DEROctetString(digest)));

        ASN1EncodableVector v = new ASN1EncodableVector();

        v.add(attr);

        SignerInfoGeneratorBuilder builder = new SignerInfoGeneratorBuilder(new BcDigestCalculatorProvider())
                .setSignedAttributeGenerator(new DefaultSignedAttributeTableGenerator(new AttributeTable(v)));

        AlgorithmIdentifier sha256withRSA = new DefaultSignatureAlgorithmIdentifierFinder().find("SHA256withRSA");

        CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
        InputStream in = new ByteArrayInputStream(chain[0].getEncoded());
        X509Certificate cert = (X509Certificate) certFactory.generateCertificate(in);

        gen.addSignerInfoGenerator(builder.build(
                new BcRSAContentSignerBuilder(sha256withRSA,
                        new DefaultDigestAlgorithmIdentifierFinder().find(sha256withRSA))
                                .build(PrivateKeyFactory.createKey(pk.getEncoded())),
                new JcaX509CertificateHolder(cert)));

        gen.addCertificates(certs);

        CMSSignedData s = gen.generate(new CMSAbsentContent(), false);
        return s.getEncoded();
    }
    catch (Exception e)
    {
        e.printStackTrace();
        throw new IOException(e);
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox2,代码行数:65,代码来源:CreateSignature.java


示例9: createAttrs

import org.bouncycastle.asn1.cms.CMSAttributes; //导入依赖的package包/类
private AttributeTable createAttrs(byte[] digestBytes, Date signingDate) {
	ASN1EncodableVector signedAttributes = new ASN1EncodableVector();
	signedAttributes.add(
			new Attribute(CMSAttributes.contentType, new DERSet(new ASN1ObjectIdentifier("1.2.840.113549.1.7.1"))));
	signedAttributes.add(new Attribute(CMSAttributes.messageDigest, new DERSet(new DEROctetString(digestBytes))));
	signedAttributes.add(new Attribute(CMSAttributes.signingTime, new DERSet(new DERUTCTime(signingDate))));

	AttributeTable signedAttributesTable = new AttributeTable(signedAttributes);
	return signedAttributesTable;
}
 
开发者ID:beat2,项目名称:pdfbox-signer,代码行数:11,代码来源:Signing.java


示例10: addCounterSigners

import org.bouncycastle.asn1.cms.CMSAttributes; //导入依赖的package包/类
/**
 * Return a signer information object with passed in SignerInformationStore representing counter
 * signatures attached as an unsigned attribute.
 *
 * @param signerInformation the signerInfo to be used as the basis.
 * @param counterSigners signer info objects carrying counter signature.
 * @return a copy of the original SignerInformationObject with the changed attributes.
 */
public static SignerInformation addCounterSigners(
    SignerInformation        signerInformation,
    SignerInformationStore   counterSigners)
{
    // TODO Perform checks from RFC 3852 11.4

    SignerInfo          sInfo = signerInformation.info;
    AttributeTable      unsignedAttr = signerInformation.getUnsignedAttributes();
    ASN1EncodableVector v;

    if (unsignedAttr != null)
    {
        v = unsignedAttr.toASN1EncodableVector();
    }
    else
    {
        v = new ASN1EncodableVector();
    }

    ASN1EncodableVector sigs = new ASN1EncodableVector();

    for (Iterator it = counterSigners.getSigners().iterator(); it.hasNext();)
    {
        sigs.add(((SignerInformation)it.next()).toSignerInfo());
    }

    v.add(new Attribute(CMSAttributes.counterSignature, new DERSet(sigs)));

    return new SignerInformation(
            new SignerInfo(sInfo.getSID(), sInfo.getDigestAlgorithm(),
                sInfo.getAuthenticatedAttributes(), sInfo.getDigestEncryptionAlgorithm(), sInfo.getEncryptedDigest(), new DERSet(v)),
                signerInformation.contentType, signerInformation.content, null);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:42,代码来源:SignerInformation.java


示例11: generateMultiPartRsa

import org.bouncycastle.asn1.cms.CMSAttributes; //导入依赖的package包/类
private MimeMultipart generateMultiPartRsa(
    String       algorithm,
    MimeBodyPart msg,
    Date         signingTime,
    Map          micalgs)
    throws Exception
{
    List certList = new ArrayList();

    certList.add(_signCert);
    certList.add(_origCert);

    Store certs = new JcaCertStore(certList);

    ASN1EncodableVector signedAttrs = generateSignedAttributes();
    
    if (signingTime != null)
    {
        signedAttrs.add(new Attribute(CMSAttributes.signingTime, new DERSet(new Time(signingTime))));
    }

    SMIMESignedGenerator gen = new SMIMESignedGenerator(micalgs);

    gen.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider(BC).setSignedAttributeGenerator(new DefaultSignedAttributeTableGenerator(new AttributeTable(signedAttrs))).build(algorithm, _signKP.getPrivate(), _signCert));
    gen.addCertificates(certs);

    return gen.generate(msg);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:29,代码来源:NewSMIMESignedTest.java


示例12: generateMultiPartRsaPSS

import org.bouncycastle.asn1.cms.CMSAttributes; //导入依赖的package包/类
private MimeMultipart generateMultiPartRsaPSS(
    String digest,
    MimeBodyPart msg,
    Date         signingTime)
    throws Exception
{
    List certList = new ArrayList();

    certList.add(_signCert);
    certList.add(_origCert);

    Store certs = new JcaCertStore(certList);

    ASN1EncodableVector signedAttrs = generateSignedAttributes();

    if (signingTime != null)
    {
        signedAttrs.add(new Attribute(CMSAttributes.signingTime, new DERSet(new Time(signingTime))));
    }

    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider(BC).setSignedAttributeGenerator(new AttributeTable(signedAttrs)).build(digest + "withRSAandMGF1", _signKP.getPrivate(), _signCert));
    gen.addCertificates(certs);

    return gen.generate(msg);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:28,代码来源:NewSMIMESignedTest.java


示例13: generateMultiPartRsa

import org.bouncycastle.asn1.cms.CMSAttributes; //导入依赖的package包/类
private MimeMultipart generateMultiPartRsa(
    String digestOid, 
    MimeBodyPart msg,
    Date         signingTime,
    Map          micalgs)
    throws Exception
{
    List certList = new ArrayList();

    certList.add(_signCert);
    certList.add(_origCert);

    CertStore certs = CertStore.getInstance("Collection",
                    new CollectionCertStoreParameters(certList), "BC");

    ASN1EncodableVector signedAttrs = generateSignedAttributes();
    
    if (signingTime != null)
    {
        signedAttrs.add(new Attribute(CMSAttributes.signingTime, new DERSet(new Time(signingTime))));
    }

    SMIMESignedGenerator gen = new SMIMESignedGenerator(micalgs);

    gen.addSigner(_signKP.getPrivate(), _signCert, digestOid, new AttributeTable(signedAttrs), null);
    gen.addCertificatesAndCRLs(certs);

    return gen.generate(msg, "BC");
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:30,代码来源:SMIMESignedTest.java


示例14: generateMultiPartRsaPSS

import org.bouncycastle.asn1.cms.CMSAttributes; //导入依赖的package包/类
private MimeMultipart generateMultiPartRsaPSS(
    String digestOid,
    MimeBodyPart msg,
    Date         signingTime)
    throws Exception
{
    List certList = new ArrayList();

    certList.add(_signCert);
    certList.add(_origCert);

    CertStore certs = CertStore.getInstance("Collection",
                    new CollectionCertStoreParameters(certList), "BC");

    ASN1EncodableVector signedAttrs = generateSignedAttributes();

    if (signingTime != null)
    {
        signedAttrs.add(new Attribute(CMSAttributes.signingTime, new DERSet(new Time(signingTime))));
    }

    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSigner(_signKP.getPrivate(), _signCert, SMIMESignedGenerator.ENCRYPTION_RSA_PSS, digestOid, new AttributeTable(signedAttrs), null);
    gen.addCertificatesAndCRLs(certs);

    return gen.generate(msg, "BC");
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:29,代码来源:SMIMESignedTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FhirContext类代码示例发布时间:2022-05-21
下一篇:
Java Constants类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap