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

Java AlgorithmIdentifier类代码示例

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

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



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

示例1: generateCSR

import org.spongycastle.asn1.x509.AlgorithmIdentifier; //导入依赖的package包/类
/**
 * Create the certificate signing request (CSR) from private and public keys
 *
 * @param keyPair the KeyPair with private and public keys
 * @return PKCS10CertificationRequest with the certificate signing request
 *         (CSR) data
 * @throws IOException
 * @throws OperatorCreationException
 */
public static PKCS10CertificationRequest generateCSR(KeyPair keyPair) throws IOException,
        OperatorCreationException {
    String principal = "CN=AWS IoT Certificate" + ", O=Amazon";
    AsymmetricKeyParameter privateKey = PrivateKeyFactory.createKey(keyPair.getPrivate()
            .getEncoded());
    AlgorithmIdentifier signatureAlgorithm = new DefaultSignatureAlgorithmIdentifierFinder()
            .find("SHA1WITHRSA");
    AlgorithmIdentifier digestAlgorithm = new DefaultDigestAlgorithmIdentifierFinder()
            .find("SHA-1");
    ContentSigner signer = new BcRSAContentSignerBuilder(signatureAlgorithm, digestAlgorithm)
            .build(privateKey);

    PKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder(
            new X500Name(principal), keyPair.getPublic());
    ExtensionsGenerator extensionsGenerator = new ExtensionsGenerator();
    extensionsGenerator.addExtension(Extension.basicConstraints, true, new BasicConstraints(
            true));
    csrBuilder.addAttribute(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest,
            extensionsGenerator.generate());
    PKCS10CertificationRequest csr = csrBuilder.build(signer);

    return csr;
}
 
开发者ID:awslabs,项目名称:aws-sdk-android-samples,代码行数:33,代码来源:CsrHelper.java


示例2: generateCertificate

import org.spongycastle.asn1.x509.AlgorithmIdentifier; //导入依赖的package包/类
/**
 * Generates a short-living certificate for the keyPair.
 */
private X509Certificate generateCertificate() throws NoSuchProviderException, NoSuchAlgorithmException, CertificateException, SignatureException, InvalidKeyException, IOException, OperatorCreationException {
    /* The certificate starts to be valid one minute in the past to be safe
     * if the clocks are a bit out of sync. */
    Calendar startDate = Calendar.getInstance();
    startDate.add(Calendar.MINUTE, -1);
    /* The certificate is not valid anymore after two minutes. This should
     * be enough to complete the protocol. */
    Calendar expiryDate = Calendar.getInstance();
    expiryDate.add(Calendar.MINUTE, +2);
    AlgorithmIdentifier sha1withRSA = new DefaultSignatureAlgorithmIdentifierFinder().find("SHA1withRSA");
    ContentSigner signer = new BcRSAContentSignerBuilder(
            new DefaultSignatureAlgorithmIdentifierFinder().find("SHA1withRSA"),
            new DefaultDigestAlgorithmIdentifierFinder().find(sha1withRSA))
            .build(keyPair.getPrivate());
    X500Name subjectName = new X500Name("CN=Wallet Protocol Server Ephemeral Certificate");
    BcX509v3CertificateBuilder certBuilder = new BcX509v3CertificateBuilder(
            subjectName,
            BigInteger.ONE,
            startDate.getTime(), expiryDate.getTime(),
            subjectName,
            keyPair.getPublic()
    );
    X509CertificateHolder certHolder = certBuilder.build(signer);
    X509Certificate cert = new JcaX509CertificateConverter().getCertificate(certHolder);
    return cert;
}
 
开发者ID:ChristopherMann,项目名称:2FactorWallet,代码行数:30,代码来源:ProtocolServer.java


示例3: getEncoded

import org.spongycastle.asn1.x509.AlgorithmIdentifier; //导入依赖的package包/类
public byte[] getEncoded()
{
    return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new org.spongycastle.asn1.pkcs.RSAPrivateKey(getModulus(), ZERO, getPrivateExponent(), ZERO, ZERO, ZERO, ZERO, ZERO));
}
 
开发者ID:B4dT0bi,项目名称:silvertunnel-ng,代码行数:5,代码来源:TempJCERSAPrivateKey.java


示例4: getEncoded

import org.spongycastle.asn1.x509.AlgorithmIdentifier; //导入依赖的package包/类
public byte[] getEncoded()
{
    return KeyUtil.getEncodedSubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new RSAPublicKeyStructure(getModulus(), getPublicExponent()));
}
 
开发者ID:B4dT0bi,项目名称:silvertunnel-ng,代码行数:5,代码来源:TempJCERSAPublicKey.java


示例5: signPkcs1

import org.spongycastle.asn1.x509.AlgorithmIdentifier; //导入依赖的package包/类
public synchronized byte[] signPkcs1(byte[] hash, DigestAlg alg, Key key) throws IOException, UserCancelException {
    //Prepare the card for signing
    byte[] rsp;
    switch (key) {
        case NON_REPUDIATION:
            rsp = cardReader.transmitApdu(INIT_SIGN_NONREP_RAWPKCS1);
            break;
        case AUTHENTICATION:
            rsp = cardReader.transmitApdu(INIT_SIGN_AUTH_RAWPKCS1);
            break;
        default:
            throw new IllegalArgumentException("Unknown key type");
    }
    if (validateResponse(rsp) != ApduSwCode.OK) {
        throw new APDUException(String.format("The card returned an error: SW=%X %X", rsp[0], rsp[1]), rsp[0], rsp[1]);
    }

    //Unlock the card with the pin if needed
    if (key == Key.NON_REPUDIATION) verifyPin();

    //Calculate the signature
    byte [] digestInfo;
    switch (alg) {
        case RAW:
            digestInfo = hash;
            break;
        case SHA1:
            digestInfo = new DigestInfo(new AlgorithmIdentifier(X509ObjectIdentifiers.id_SHA1,
                    DERNull.INSTANCE), hash).getEncoded(ASN1Encoding.DER);
            break;
        case SHA256:
            digestInfo = new DigestInfo(new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256,
                    DERNull.INSTANCE), hash).getEncoded(ASN1Encoding.DER);
            break;
        default:
            throw new IllegalArgumentException("Unknown digest algorithm");
    }
    byte [] cmd = new byte[DO_SIGN.length + digestInfo.length];
    System.arraycopy(DO_SIGN, 0, cmd, 0, DO_SIGN.length);
    cmd[4] = (byte) digestInfo.length;
    System.arraycopy(digestInfo, 0, cmd, DO_SIGN.length, digestInfo.length);

    byte[] data;
    rsp = cardReader.transmitApdu(cmd);
    switch (validateResponse(rsp)) {
        case OK:
            data = new byte[rsp.length-2];
            System.arraycopy(rsp, 0, data, 0, data.length);
            break;
        case OkGetRsp:
            data = getResponse(rsp[1]);
            break;
        case SecConNotSatisfied:
            verifyPin();
            rsp = cardReader.transmitApdu(cmd);
            switch (validateResponse(rsp)) {
                case OK:
                    data = new byte[rsp.length-2];
                    System.arraycopy(rsp, 0, data, 0, data.length);
                    break;
                case OkGetRsp:
                    data = getResponse(rsp[1]);
                    break;
                default:
                    throw new APDUException(String.format("The card returned an error: SW=%X %X", rsp[0], rsp[1]), rsp[0], rsp[1]);
            }
            break;
        default:
            throw new APDUException(String.format("The card returned an error: SW=%X %X", rsp[0], rsp[1]), rsp[0], rsp[1]);
    }

    return data;
}
 
开发者ID:egelke,项目名称:eIDSuite,代码行数:74,代码来源:EidCardReader.java


示例6: getAlgorithmIdentifier

import org.spongycastle.asn1.x509.AlgorithmIdentifier; //导入依赖的package包/类
@Override
public AlgorithmIdentifier getAlgorithmIdentifier() {
    return AlgorithmIdentifier
            .getInstance(PKCSObjectIdentifiers.sha512WithRSAEncryption);
}
 
开发者ID:nelenkov,项目名称:nfc-smime,代码行数:6,代码来源:MuscleCardContentSigner.java


示例7: getEncoded

import org.spongycastle.asn1.x509.AlgorithmIdentifier; //导入依赖的package包/类
/**
 * Return a PKCS8 representation of the key. The sequence returned
 * represents a full PrivateKeyInfo object.
 *
 * @return a PKCS8 representation of the key.
 */
public byte[] getEncoded()
{
    return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new RSAPrivateKey(getModulus(), getPublicExponent(), getPrivateExponent(), getPrimeP(), getPrimeQ(), getPrimeExponentP(), getPrimeExponentQ(), getCrtCoefficient()));
}
 
开发者ID:B4dT0bi,项目名称:silvertunnel-ng,代码行数:11,代码来源:TempJCERSAPrivateCrtKey.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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