當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。