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


Java X500Name.asX500Name方法代码示例

本文整理汇总了Java中sun.security.x509.X500Name.asX500Name方法的典型用法代码示例。如果您正苦于以下问题:Java X500Name.asX500Name方法的具体用法?Java X500Name.asX500Name怎么用?Java X500Name.asX500Name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sun.security.x509.X500Name的用法示例。


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

示例1: generateSignedData

import sun.security.x509.X500Name; //导入方法依赖的package包/类
/**
 * Assembles a PKCS #7 signed data message that optionally includes a
 * signature timestamp.
 *
 * @param signature the signature bytes
 * @param signerChain the signer's X.509 certificate chain
 * @param content the content that is signed; specify null to not include
 *        it in the PKCS7 data
 * @param signatureAlgorithm the name of the signature algorithm
 * @param tsaURI the URI of the Timestamping Authority; or null if no
 *         timestamp is requested
 * @param tSAPolicyID the TSAPolicyID of the Timestamping Authority as a
 *         numerical object identifier; or null if we leave the TSA server
 *         to choose one. This argument is only used when tsaURI is provided
 * @return the bytes of the encoded PKCS #7 signed data message
 * @throws NoSuchAlgorithmException The exception is thrown if the signature
 *         algorithm is unrecognised.
 * @throws CertificateException The exception is thrown if an error occurs
 *         while processing the signer's certificate or the TSA's
 *         certificate.
 * @throws IOException The exception is thrown if an error occurs while
 *         generating the signature timestamp or while generating the signed
 *         data message.
 */
public static byte[] generateSignedData(byte[] signature,
                                        X509Certificate[] signerChain,
                                        byte[] content,
                                        String signatureAlgorithm,
                                        URI tsaURI,
                                        String tSAPolicyID)
    throws CertificateException, IOException, NoSuchAlgorithmException
{

    // Generate the timestamp token
    PKCS9Attributes unauthAttrs = null;
    if (tsaURI != null) {
        // Timestamp the signature
        HttpTimestamper tsa = new HttpTimestamper(tsaURI);
        byte[] tsToken = generateTimestampToken(tsa, tSAPolicyID, signature);

        // Insert the timestamp token into the PKCS #7 signer info element
        // (as an unsigned attribute)
        unauthAttrs =
            new PKCS9Attributes(new PKCS9Attribute[]{
                new PKCS9Attribute(
                    PKCS9Attribute.SIGNATURE_TIMESTAMP_TOKEN_STR,
                    tsToken)});
    }

    // Create the SignerInfo
    X500Name issuerName =
        X500Name.asX500Name(signerChain[0].getIssuerX500Principal());
    BigInteger serialNumber = signerChain[0].getSerialNumber();
    String encAlg = AlgorithmId.getEncAlgFromSigAlg(signatureAlgorithm);
    String digAlg = AlgorithmId.getDigAlgFromSigAlg(signatureAlgorithm);
    SignerInfo signerInfo = new SignerInfo(issuerName, serialNumber,
                                           AlgorithmId.get(digAlg), null,
                                           AlgorithmId.get(encAlg),
                                           signature, unauthAttrs);

    // Create the PKCS #7 signed data message
    SignerInfo[] signerInfos = {signerInfo};
    AlgorithmId[] algorithms = {signerInfo.getDigestAlgorithmId()};
    // Include or exclude content
    ContentInfo contentInfo = (content == null)
        ? new ContentInfo(ContentInfo.DATA_OID, null)
        : new ContentInfo(content);
    PKCS7 pkcs7 = new PKCS7(algorithms, contentInfo,
                            signerChain, signerInfos);
    ByteArrayOutputStream p7out = new ByteArrayOutputStream();
    pkcs7.encodeSignedData(p7out);

    return p7out.toByteArray();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:75,代码来源:PKCS7.java

示例2: compare

import sun.security.x509.X500Name; //导入方法依赖的package包/类
@Override
public int compare(X509Certificate cert1, X509Certificate cert2) {

    /*
     * if either cert certifies the target, always
     * put at head of list.
     */
    X500Principal targetSubject = buildParams.targetSubject();
    if (cert1.getSubjectX500Principal().equals(targetSubject)) {
        return -1;
    }
    if (cert2.getSubjectX500Principal().equals(targetSubject)) {
        return 1;
    }

    int targetDist1;
    int targetDist2;
    try {
        X500Name targetSubjectName = X500Name.asX500Name(targetSubject);
        targetDist1 = Builder.targetDistance(
            null, cert1, targetSubjectName);
        targetDist2 = Builder.targetDistance(
            null, cert2, targetSubjectName);
    } catch (IOException e) {
        if (debug != null) {
            debug.println("IOException in call to Builder.targetDistance");
            e.printStackTrace();
        }
        throw new ClassCastException
            ("Invalid target subject distinguished name");
    }

    if (targetDist1 == targetDist2)
        return 0;

    if (targetDist1 == -1)
        return 1;

    if (targetDist1 < targetDist2)
        return -1;

    return 1;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:44,代码来源:ReverseBuilder.java

示例3: generateSignedData

import sun.security.x509.X500Name; //导入方法依赖的package包/类
/**
 * Assembles a PKCS #7 signed data message that optionally includes a
 * signature timestamp.
 *
 * @param signature the signature bytes
 * @param signerChain the signer's X.509 certificate chain
 * @param content the content that is signed; specify null to not include
 *        it in the PKCS7 data
 * @param signatureAlgorithm the name of the signature algorithm
 * @param tsaURI the URI of the Timestamping Authority; or null if no
 *         timestamp is requested
 * @param tSAPolicyID the TSAPolicyID of the Timestamping Authority as a
 *         numerical object identifier; or null if we leave the TSA server
 *         to choose one. This argument is only used when tsaURI is provided
 * @return the bytes of the encoded PKCS #7 signed data message
 * @throws NoSuchAlgorithmException The exception is thrown if the signature
 *         algorithm is unrecognised.
 * @throws CertificateException The exception is thrown if an error occurs
 *         while processing the signer's certificate or the TSA's
 *         certificate.
 * @throws IOException The exception is thrown if an error occurs while
 *         generating the signature timestamp or while generating the signed
 *         data message.
 */
public static byte[] generateSignedData(byte[] signature,
                                        X509Certificate[] signerChain,
                                        byte[] content,
                                        String signatureAlgorithm,
                                        URI tsaURI,
                                        String tSAPolicyID,
                                        String tSADigestAlg)
    throws CertificateException, IOException, NoSuchAlgorithmException
{

    // Generate the timestamp token
    PKCS9Attributes unauthAttrs = null;
    if (tsaURI != null) {
        // Timestamp the signature
        HttpTimestamper tsa = new HttpTimestamper(tsaURI);
        byte[] tsToken = generateTimestampToken(
                tsa, tSAPolicyID, tSADigestAlg, signature);

        // Insert the timestamp token into the PKCS #7 signer info element
        // (as an unsigned attribute)
        unauthAttrs =
            new PKCS9Attributes(new PKCS9Attribute[]{
                new PKCS9Attribute(
                    PKCS9Attribute.SIGNATURE_TIMESTAMP_TOKEN_STR,
                    tsToken)});
    }

    // Create the SignerInfo
    X500Name issuerName =
        X500Name.asX500Name(signerChain[0].getIssuerX500Principal());
    BigInteger serialNumber = signerChain[0].getSerialNumber();
    String encAlg = AlgorithmId.getEncAlgFromSigAlg(signatureAlgorithm);
    String digAlg = AlgorithmId.getDigAlgFromSigAlg(signatureAlgorithm);
    SignerInfo signerInfo = new SignerInfo(issuerName, serialNumber,
                                           AlgorithmId.get(digAlg), null,
                                           AlgorithmId.get(encAlg),
                                           signature, unauthAttrs);

    // Create the PKCS #7 signed data message
    SignerInfo[] signerInfos = {signerInfo};
    AlgorithmId[] algorithms = {signerInfo.getDigestAlgorithmId()};
    // Include or exclude content
    ContentInfo contentInfo = (content == null)
        ? new ContentInfo(ContentInfo.DATA_OID, null)
        : new ContentInfo(content);
    PKCS7 pkcs7 = new PKCS7(algorithms, contentInfo,
                            signerChain, signerInfos);
    ByteArrayOutputStream p7out = new ByteArrayOutputStream();
    pkcs7.encodeSignedData(p7out);

    return p7out.toByteArray();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:77,代码来源:PKCS7.java


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