sun.security.x509.X500Name.<init>()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(213)

本文整理了Java中sun.security.x509.X500Name.<init>()方法的一些代码示例,展示了X500Name.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。X500Name.<init>()方法的具体详情如下:
包路径:sun.security.x509.X500Name
类名称:X500Name
方法名:<init>

X500Name.<init>介绍

暂无

代码示例

代码示例来源:origin: pxb1988/dex2jar

/** Write a .RSA file with a digital signature. */
  @SuppressWarnings("all")
  protected void writeSignatureBlock(byte[] signature, OutputStream out) throws IOException {
    try {
      SignerInfo signerInfo = new SignerInfo(new X500Name(cert.getIssuerX500Principal().getName()),
          cert.getSerialNumber(), AlgorithmId.get(digestAlg), AlgorithmId.get("RSA"), signature);

      PKCS7 pkcs7 = new PKCS7(new AlgorithmId[] { AlgorithmId.get(digestAlg) }, new ContentInfo(
          ContentInfo.DATA_OID, null), new X509Certificate[] { cert }, new SignerInfo[] { signerInfo });

      pkcs7.encodeSignedData(out);
    } catch (NoSuchAlgorithmException e) {
      throw new RuntimeException(e);
    }
  }
}

代码示例来源:origin: stackoverflow.com

X500Name x500Name = new X500Name(commonName, organizationalUnit, organization, city, state, country);

代码示例来源:origin: rapidoid/rapidoid

private static X500Name x500Name(SelfSignedCertInfo info) throws IOException {
  return new X500Name(info.name(), info.unit(), info.organization(), info.locality(), info.state(), info.country());
}

代码示例来源:origin: stackoverflow.com

CertificateValidity interval = new CertificateValidity(from, to);
BigInteger sn = new BigInteger(64, new SecureRandom());
X500Name owner = new X500Name(dn);

代码示例来源:origin: redisson/redisson

X500Name owner = new X500Name("CN=" + fqdn);
info.set(X509CertInfo.VERSION, new CertificateVersion(CertificateVersion.V3));
info.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber(new BigInteger(64, random)));

代码示例来源:origin: wildfly/wildfly

X500Name owner = new X500Name("CN=" + fqdn);
info.set(X509CertInfo.VERSION, new CertificateVersion(CertificateVersion.V3));
info.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber(new BigInteger(64, random)));

代码示例来源:origin: io.netty/netty

X500Name owner = new X500Name("CN=" + fqdn);
info.set(X509CertInfo.VERSION, new CertificateVersion(CertificateVersion.V3));
info.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber(new BigInteger(64, random)));

代码示例来源:origin: io.netty/netty-handler

X500Name owner = new X500Name("CN=" + fqdn);
info.set(X509CertInfo.VERSION, new CertificateVersion(CertificateVersion.V3));
info.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber(new BigInteger(64, random)));

代码示例来源:origin: at.researchstudio.sat/won-core

@Override
 public String generateAlias(final X509Certificate certificate) throws CertificateException {
  String alias = null;
  try {
   X500Name dnName = new X500Name(certificate.getSubjectDN().getName());
   alias = dnName.getCommonName();
  } catch (IOException e) {
   throw new CertificateException("SubjectDN problem - cannot generate alias", e);
  }
  if (alias == null || alias.isEmpty()) {
   throw new CertificateException("CN is null - cannot accept as alias");
  }
  return alias;
 }
}

代码示例来源:origin: OpenAttestation/OpenAttestation

public X509Builder issuerName(String dn) {
  try {
    certificateIssuerName = new CertificateIssuerName(new X500Name(dn));
    info.set(X509CertInfo.ISSUER, certificateIssuerName); // CertificateException, IOException
  }
  catch(Exception e) {
    fault(e, "issuerName(%s)", dn);
  }
  return this;
}

代码示例来源:origin: OpenAttestation/OpenAttestation

/**
 * 
 * @param dn like "CN=Dave, OU=JavaSoft, O=Sun Microsystems, C=US"
 * @return 
 */
public X509Builder subjectName(String dn) {
  try {
    certificateSubjectName = new CertificateSubjectName(new X500Name(dn));
    info.set(X509CertInfo.SUBJECT, certificateSubjectName); // CertificateException, IOException
  }
  catch(Exception e) {
    fault(e, "subjectName(%s)", dn);
  }
  return this;        
}

代码示例来源:origin: OpenAttestation/OpenAttestation

/**
 * Creates a self-signed X.509 certificate using SHA-256 with RSA
 * encryption.
 *
 * XXX This method uses Sun "internal" API's, which may be removed in a
 * future JRE release.
 *
 * @param dn
 * @param alternativeName a string like "ip:1.2.3.4"
 * @param pair
 * @param days
 * @return
 * @throws GeneralSecurityException
 * @throws IOException
 */
public static X509Certificate generateX509Certificate(String dn, String alternativeName, KeyPair pair, int days) throws CryptographyException, IOException {
  X500Name owner = new X500Name(dn, "Mt Wilson", "Trusted Data Center", "US"); // the constructor X500Name(dn) was throwing an exception;  replaced "Intel" with "Trusted Data Center" to avoid confusion about the owner of the certificate... this is not an "Intel certificate", it's generated at the customer site.
  return createX509CertificateWithIssuer(pair.getPublic(), dn, alternativeName, days, pair.getPrivate(), new CertificateIssuerName(owner));
}

代码示例来源:origin: appium/sign

/** Write a .RSA file with a digital signature. */
private static void writeSignatureBlock(Signature signature,
  X509Certificate publicKey, OutputStream out) throws IOException,
  GeneralSecurityException {
 SignerInfo signerInfo = new SignerInfo(new X500Name(publicKey
   .getIssuerX500Principal().getName()), publicKey.getSerialNumber(),
   AlgorithmId.get("SHA1"), AlgorithmId.get("RSA"), signature.sign());
 PKCS7 pkcs7 = new PKCS7(new AlgorithmId[] { AlgorithmId.get("SHA1") },
   new ContentInfo(ContentInfo.DATA_OID, null),
   new X509Certificate[] { publicKey }, new SignerInfo[] { signerInfo });
 pkcs7.encodeSignedData(out);
}

代码示例来源:origin: com.android.tools/sdklib

/** Write the certificate file with a digital signature. */
  private void writeSignatureBlock(Signature signature, X509Certificate publicKey,
      PrivateKey privateKey)
      throws IOException, GeneralSecurityException {
    SignerInfo signerInfo = new SignerInfo(
        new X500Name(publicKey.getIssuerX500Principal().getName()),
        publicKey.getSerialNumber(),
        AlgorithmId.get(DIGEST_ALGORITHM),
        AlgorithmId.get(privateKey.getAlgorithm()),
        signature.sign());

    PKCS7 pkcs7 = new PKCS7(
        new AlgorithmId[] { AlgorithmId.get(DIGEST_ALGORITHM) },
        new ContentInfo(ContentInfo.DATA_OID, null),
        new X509Certificate[] { publicKey },
        new SignerInfo[] { signerInfo });

    pkcs7.encodeSignedData(mOutputJar);
  }
}

代码示例来源:origin: com.taobao.android/dex_patch

/**
 * Write the certificate file with a digital signature.
 */
private void writeSignatureBlock(Signature signature, X509Certificate publicKey,
                 PrivateKey privateKey)
    throws IOException, GeneralSecurityException {
  SignerInfo signerInfo = new SignerInfo(
      new X500Name(publicKey.getIssuerX500Principal().getName()),
      publicKey.getSerialNumber(),
      AlgorithmId.get(DIGEST_ALGORITHM),
      AlgorithmId.get(privateKey.getAlgorithm()),
      signature.sign());
  PKCS7 pkcs7 = new PKCS7(
      new AlgorithmId[]{AlgorithmId.get(DIGEST_ALGORITHM)},
      new ContentInfo(ContentInfo.DATA_OID, null),
      new X509Certificate[]{publicKey},
      new SignerInfo[]{signerInfo});
  pkcs7.encodeSignedData(mOutputJar);
}

代码示例来源:origin: javafxports/javafxmobile-plugin

/** Write the certificate file with a digital signature. */
  private void writeSignatureBlock(Signature signature, X509Certificate publicKey,
      PrivateKey privateKey)
      throws IOException, GeneralSecurityException {
    SignerInfo signerInfo = new SignerInfo(
        new X500Name(publicKey.getIssuerX500Principal().getName()),
        publicKey.getSerialNumber(),
        AlgorithmId.get(DIGEST_ALGORITHM),
        AlgorithmId.get(privateKey.getAlgorithm()),
        signature.sign());

    PKCS7 pkcs7 = new PKCS7(
        new AlgorithmId[] { AlgorithmId.get(DIGEST_ALGORITHM) },
        new ContentInfo(ContentInfo.DATA_OID, null),
        new X509Certificate[] { publicKey },
        new SignerInfo[] { signerInfo });

    pkcs7.encodeSignedData(mOutputJar);
  }
}

代码示例来源:origin: appium/sign

/** Write a .RSA file with a digital signature. */
private static void writeSignatureBlock(
    Signature signature, X509Certificate publicKey, OutputStream out)
    throws IOException, GeneralSecurityException {
  SignerInfo signerInfo = new SignerInfo(
      new X500Name(publicKey.getIssuerX500Principal().getName()),
      publicKey.getSerialNumber(),
      AlgorithmId.get("SHA1"),
      AlgorithmId.get("RSA"),
      signature.sign());
  PKCS7 pkcs7 = new PKCS7(
      new AlgorithmId[] { AlgorithmId.get("SHA1") },
      new ContentInfo(ContentInfo.DATA_OID, null),
      new X509Certificate[] { publicKey },
      new SignerInfo[] { signerInfo });
  pkcs7.encodeSignedData(out);
}

代码示例来源:origin: org.jolokia/jolokia-agent-jvm

/**
 * Update the given keystore with a self signed server certificate. This can be used if no
 * server certificate is provided from the outside and no SSL verification is used by the client.
 *
 * @param pKeyStore keystore to update
 */
public static void updateWithSelfSignedServerCertificate(KeyStore pKeyStore)
    throws NoSuchProviderException, NoSuchAlgorithmException, IOException,
        InvalidKeyException, CertificateException, SignatureException, KeyStoreException {
  X500Name x500Name =
    new X500Name(
        "Jolokia Agent " + Version.getAgentVersion(), // CN
        "JVM",                                        // OU
        "jolokia.org",                                // O
        "Pegnitz",                                    // L
        "Franconia",                                  // ST
        "DE"                                          // C
    );
  // Need to do it via reflection because Java8 moved class to a different package
  Object keypair = createKeyPair();
  PrivateKey privKey = getPrivateKey(keypair);
  X509Certificate[] chain = new X509Certificate[1];
  chain[0] = getSelfCertificate(keypair,x500Name, new Date(), (long) 3650 * 24 * 60 * 60);
  pKeyStore.setKeyEntry("jolokia-agent", privKey, new char[0], chain);
}

代码示例来源:origin: Azure/azure-iot-sdk-java

/**
 *
 * @param DN eg "CN=Test, L=Redmond, C=GB"
 * @param validity 24 * 60 * 60 is 1 Day
 * @return A private key and X509 certificate
 * @throws NoSuchAlgorithmException
 * @throws NoSuchProviderException
 * @throws InvalidKeyException
 * @throws IOException
 * @throws CertificateException
 * @throws SignatureException
 */
private CertKeyPair createCertAndKey(String DN, long validity) throws
                                        NoSuchAlgorithmException,
                                        NoSuchProviderException,
                                        InvalidKeyException, IOException,
                                        CertificateException,
                                        SignatureException
{
  //Generate ROOT certificate
  CertAndKeyGen keyGen = new CertAndKeyGen("RSA", "SHA1WithRSA", null);
  keyGen.generate(1024);
  PrivateKey key = keyGen.getPrivateKey();
  X509Certificate x509Certificate = keyGen.getSelfCertificate(new X500Name(DN), validity);
  return new CertKeyPair(key, x509Certificate);
}

代码示例来源:origin: de.esoco/esoco-lib

/***************************************
   * Creates a new instance of the sun-internal security class {@link
   * X500Name} from parameters stored in a relatable object.
   *
   * @param  rCertParams The relatable containing the certificate parameters
   *                     as defined in {@link SecurityRelationTypes}
   *
   * @return The new X500 certificate name
   *
   * @throws IllegalArgumentException If the parsing of the parameters fails
   */
  private static X500Name createX500Name(Relatable rCertParams)
  {
    ObjectRelations.requireNonNull(rCertParams, COMMON_NAME);

    try
    {
      return new X500Name(rCertParams.get(COMMON_NAME),
                rCertParams.get(ORGANIZATION_UNIT),
                rCertParams.get(ORGANIZATION),
                rCertParams.get(LOCALITY),
                rCertParams.get(STATE_PROVINCE_REGION),
                rCertParams.get(COUNTRY));
    }
    catch (IOException e)
    {
      throw new IllegalArgumentException(e);
    }
  }
}

相关文章