當前位置: 首頁>>代碼示例>>Java>>正文


Java X500Principal類代碼示例

本文整理匯總了Java中javax.security.auth.x500.X500Principal的典型用法代碼示例。如果您正苦於以下問題:Java X500Principal類的具體用法?Java X500Principal怎麽用?Java X500Principal使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


X500Principal類屬於javax.security.auth.x500包,在下文中一共展示了X500Principal類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createKeys

import javax.security.auth.x500.X500Principal; //導入依賴的package包/類
/**
 * Creates a public and private key and stores it using the AndroidKeyStore,
 * so that only this application will be able to access the keys.
 */
@SuppressWarnings("deprecation")
public void createKeys() throws Exception {
    KeyStore keyStore = KeyStore.getInstance(ANDROID_KEY_STORE);
    keyStore.load(null);
    if (keyStore.containsAlias(alias)) {
        Log.d(TAG, "[containsAlias]");
        return;
    }

    Calendar start = Calendar.getInstance();
    Calendar end = Calendar.getInstance();
    end.add(Calendar.YEAR, 30);
    KeyPairGeneratorSpec spec = new KeyPairGeneratorSpec.Builder(context)
        .setAlias(alias)
        .setSubject(new X500Principal("CN=" + alias))
        .setSerialNumber(BigInteger.TEN)
        .setStartDate(start.getTime())
        .setEndDate(end.getTime())
        .build();
    KeyPairGenerator generator = KeyPairGenerator.getInstance(TYPE_RSA, ANDROID_KEY_STORE);
    generator.initialize(spec);
    KeyPair keyPair = generator.generateKeyPair();
    Log.d(TAG, "Public Key is: " + keyPair.getPublic().toString());
}
 
開發者ID:drakeet,項目名稱:rebase-android,代碼行數:29,代碼來源:BlackBox.java

示例2: findByIssuerAndSignature

import javax.security.auth.x500.X500Principal; //導入依賴的package包/類
@Override public X509Certificate findByIssuerAndSignature(X509Certificate cert) {
  X500Principal issuer = cert.getIssuerX500Principal();
  Set<X509Certificate> subjectCaCerts = subjectToCaCerts.get(issuer);
  if (subjectCaCerts == null) return null;

  for (X509Certificate caCert : subjectCaCerts) {
    PublicKey publicKey = caCert.getPublicKey();
    try {
      cert.verify(publicKey);
      return caCert;
    } catch (Exception ignored) {
    }
  }

  return null;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:TrustRootIndex.java

示例3: main

import javax.security.auth.x500.X500Principal; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    X500Principal duke = new X500Principal("CN=Duke");
    // should not throw NullPointerException
    testImplies(duke, (Subject)null, false);

    Set<Principal> principals = new HashSet<>();
    principals.add(duke);
    testImplies(duke, principals, true);

    X500Principal tux = new X500Principal("CN=Tux");
    principals.add(tux);
    testImplies(duke, principals, true);

    principals.add(new KerberosPrincipal("[email protected]"));
    testImplies(duke, principals, true);

    principals.clear();
    principals.add(tux);
    testImplies(duke, principals, false);

    System.out.println("test passed");
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:23,代碼來源:Implies.java

示例4: getIssuerX500Principal

import javax.security.auth.x500.X500Principal; //導入依賴的package包/類
/**
 * Extract the issuer X500Principal from an X509CRL. Parses the encoded
 * form of the CRL to preserve the principal's ASN.1 encoding.
 *
 * Called by java.security.cert.X509CRL.getIssuerX500Principal().
 */
public static X500Principal getIssuerX500Principal(X509CRL crl) {
    try {
        byte[] encoded = crl.getEncoded();
        DerInputStream derIn = new DerInputStream(encoded);
        DerValue tbsCert = derIn.getSequence(3)[0];
        DerInputStream tbsIn = tbsCert.data;

        DerValue tmp;
        // skip version number if present
        byte nextByte = (byte)tbsIn.peekByte();
        if (nextByte == DerValue.tag_Integer) {
            tmp = tbsIn.getDerValue();
        }

        tmp = tbsIn.getDerValue();  // skip signature
        tmp = tbsIn.getDerValue();  // issuer
        byte[] principalBytes = tmp.toByteArray();
        return new X500Principal(principalBytes);
    } catch (Exception e) {
        throw new RuntimeException("Could not parse issuer", e);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:29,代碼來源:X509CRLImpl.java

示例5: verifyHostName

import javax.security.auth.x500.X500Principal; //導入依賴的package包/類
/**
 * Returns true if {@code certificate} matches {@code hostName}.
 */
private boolean verifyHostName(String hostName, X509Certificate certificate) {
  hostName = hostName.toLowerCase(Locale.US);
  boolean hasDns = false;
  List<String> altNames = getSubjectAltNames(certificate, ALT_DNS_NAME);
  for (int i = 0, size = altNames.size(); i < size; i++) {
    hasDns = true;
    if (verifyHostName(hostName, altNames.get(i))) {
      return true;
    }
  }

  if (!hasDns) {
    X500Principal principal = certificate.getSubjectX500Principal();
    // RFC 2818 advises using the most specific name for matching.
    String cn = new DistinguishedNameParser(principal).findMostSpecific("cn");
    if (cn != null) {
      return verifyHostName(hostName, cn);
    }
  }

  return false;
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:26,代碼來源:OkHostnameVerifier.java

示例6: ForwardBuilder

import javax.security.auth.x500.X500Principal; //導入依賴的package包/類
/**
 * Initialize the builder with the input parameters.
 *
 * @param params the parameter set used to build a certification path
 */
ForwardBuilder(BuilderParams buildParams, boolean searchAllCertStores) {
    super(buildParams);

    // populate sets of trusted certificates and subject DNs
    trustAnchors = buildParams.trustAnchors();
    trustedCerts = new HashSet<X509Certificate>(trustAnchors.size());
    trustedSubjectDNs = new HashSet<X500Principal>(trustAnchors.size());
    for (TrustAnchor anchor : trustAnchors) {
        X509Certificate trustedCert = anchor.getTrustedCert();
        if (trustedCert != null) {
            trustedCerts.add(trustedCert);
            trustedSubjectDNs.add(trustedCert.getSubjectX500Principal());
        } else {
            trustedSubjectDNs.add(anchor.getCA());
        }
    }
    this.searchAllCertStores = searchAllCertStores;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:ForwardBuilder.java

示例7: testGetCN

import javax.security.auth.x500.X500Principal; //導入依賴的package包/類
@Test
public void testGetCN(@Mocked X500Principal aX500Principal, @Mocked MyX509Certificate myX509Certificate) {
  new Expectations() {
    {
      aX500Principal.getName();
      result = "CN=Test1234";
      myX509Certificate.getSubjectX500Principal();
      result = aX500Principal;
    }
  };

  MyX509Certificate xxmyX509Certificate = new MyX509Certificate();
  Set<String> strExpect = CertificateUtil.getCN(xxmyX509Certificate);

  Assert.assertEquals(true, strExpect.contains("Test1234"));
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:17,代碼來源:CertificateUtilTest.java

示例8: ResponderId

import javax.security.auth.x500.X500Principal; //導入依賴的package包/類
/**
 * Constructs a {@code ResponderId} object from its DER-encoding.
 *
 * @param encodedData the DER-encoded bytes
 *
 * @throws IOException if the encodedData is not properly DER encoded
 */
public ResponderId(byte[] encodedData) throws IOException {
    DerValue outer = new DerValue(encodedData);

    if (outer.isContextSpecific((byte)Type.BY_NAME.value())
            && outer.isConstructed()) {
        // Use the X500Principal constructor as a way to sanity
        // check the incoming data.
        responderName = new X500Principal(outer.getDataBytes());
        encodedRid = principalToBytes();
        type = Type.BY_NAME;
    } else if (outer.isContextSpecific((byte)Type.BY_KEY.value())
            && outer.isConstructed()) {
        // Use the KeyIdentifier constructor as a way to sanity
        // check the incoming data.
        responderKeyId =
            new KeyIdentifier(new DerValue(outer.getDataBytes()));
        encodedRid = keyIdToBytes();
        type = Type.BY_KEY;
    } else {
        throw new IOException("Invalid ResponderId content");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:30,代碼來源:ResponderId.java

示例9: runTest

import javax.security.auth.x500.X500Principal; //導入依賴的package包/類
@Override
public Map.Entry<Boolean, String> runTest() {
    Boolean pass = Boolean.FALSE;
    String message = null;

    try {
        // Test methods for pulling out the underlying
        // X500Principal object
        X500Principal testPrincipal =
                new X500Principal(RESP_CERT_1_SUBJ);
        if (!respByName.getResponderName().equals(testPrincipal)) {
            message = "ResponderId Name did not match expected value";
        } else if (respByKeyId.getResponderName() != null) {
            message = "Non-null responder name returned from " +
                    "ResponderId constructed byKey";
        } else {
            pass = Boolean.TRUE;
        }
    } catch (Exception e) {
        e.printStackTrace(System.out);
        message = e.getClass().getName();
    }

    return new AbstractMap.SimpleEntry<>(pass, message);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:ResponderIdTests.java

示例10: createNewKeys

import javax.security.auth.x500.X500Principal; //導入依賴的package包/類
private static KeyPair createNewKeys(Context ctx, String alias) {
    KeyPair keyPair = null;
    try {
        Calendar start = Calendar.getInstance();
        Calendar end = Calendar.getInstance();
        end.add(Calendar.YEAR, 1);
        KeyPairGeneratorSpec spec = new KeyPairGeneratorSpec.Builder(ctx)
                .setAlias(alias)
                .setSubject(new X500Principal("CN=" + alias))
                .setSerialNumber(BigInteger.ONE)
                .setStartDate(start.getTime())
                .setEndDate(end.getTime())
                .build();
        KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA", keyStoreInstance);
        generator.initialize(spec);
        keyPair = generator.generateKeyPair();
    } catch (Exception e) {
        Toast.makeText(ctx, "Exception " + e.getMessage() + " occured", Toast.LENGTH_LONG).show();
        Log.e(TAG, Log.getStackTraceString(e));
    }
    return keyPair;
}
 
開發者ID:ceanyd,項目名稱:react-native-caller-id-android,代碼行數:23,代碼來源:DataBase.java

示例11: generateKeyPair

import javax.security.auth.x500.X500Principal; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private static void generateKeyPair(Context context, String alias)
        throws GeneralSecurityException {
    final Calendar start = new GregorianCalendar();
    final Calendar end = new GregorianCalendar();
    end.add(Calendar.YEAR, 100);
    final KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA", "AndroidKeyStore");
    final KeyPairGeneratorSpec spec = new KeyPairGeneratorSpec.Builder(context)
            .setAlias(alias)
            .setSubject(new X500Principal("CN=" + alias))
            .setSerialNumber(BigInteger.ONE)
            .setStartDate(start.getTime())
            .setEndDate(end.getTime())
            .build();
    gen.initialize(spec);
    gen.generateKeyPair();
}
 
開發者ID:privacyidea,項目名稱:privacyidea-authenticator,代碼行數:18,代碼來源:SecretKeyWrapper.java

示例12: setTrustedSubjects

import javax.security.auth.x500.X500Principal; //導入依賴的package包/類
/**
 * Populate the trustedSubjects Map using the DN and public keys from
 * the list of trusted certificates
 *
 * @return Map containing each subject DN and one or more public keys
 *    tied to those DNs.
 */
private Map<X500Principal, List<PublicKey>> setTrustedSubjects() {
    Map<X500Principal, List<PublicKey>> subjectMap = new HashMap<>();

    for (X509Certificate cert : trustedCerts) {
        X500Principal dn = cert.getSubjectX500Principal();
        List<PublicKey> keys;
        if (subjectMap.containsKey(dn)) {
            keys = subjectMap.get(dn);
        } else {
            keys = new ArrayList<PublicKey>();
            subjectMap.put(dn, keys);
        }
        keys.add(cert.getPublicKey());
    }

    return subjectMap;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:PKIXValidator.java

示例13: generateAsymmetricKeyPair

import javax.security.auth.x500.X500Principal; //導入依賴的package包/類
private static void generateAsymmetricKeyPair() throws SecureStorageException {
    try {
        if (isRTL()) {
            Locale.setDefault(Locale.US);
        }

        Calendar start = Calendar.getInstance();
        Calendar end = Calendar.getInstance();
        end.add(Calendar.YEAR, 99);

        KeyPairGeneratorSpec spec = new KeyPairGeneratorSpec.Builder(context.get())
                .setAlias(KEY_ALIAS)
                .setSubject(new X500Principal(KEY_X500PRINCIPAL))
                .setSerialNumber(BigInteger.TEN)
                .setStartDate(start.getTime())
                .setEndDate(end.getTime())
                .build();

        KeyPairGenerator generator
                = KeyPairGenerator.getInstance(KEY_ENCRYPTION_ALGORITHM, KEY_KEYSTORE_NAME);
        generator.initialize(spec);
        generator.generateKeyPair();
    } catch (Exception e) {
        throw new SecureStorageException(e.getMessage(), e, KEYSTORE_EXCEPTION);
    }
}
 
開發者ID:adorsys,項目名稱:secure-storage-android,代碼行數:27,代碼來源:KeystoreTool.java

示例14: getSubjectX500Name

import javax.security.auth.x500.X500Principal; //導入依賴的package包/類
/**
 * Return the subject of a certificate as X500Name, by reparsing if
 * necessary. X500Name should only be used if access to name components
 * is required, in other cases X500Principal is to be preferred.
 *
 * This method is currently used from within JSSE, do not remove.
 */
public static X500Name getSubjectX500Name(X509Certificate cert)
        throws CertificateParsingException {
    try {
        Principal subjectDN = cert.getSubjectDN();
        if (subjectDN instanceof X500Name) {
            return (X500Name)subjectDN;
        } else {
            X500Principal subjectX500 = cert.getSubjectX500Principal();
            return new X500Name(subjectX500.getEncoded());
        }
    } catch (IOException e) {
        throw(CertificateParsingException)
            new CertificateParsingException().initCause(e);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:HostnameChecker.java

示例15: makeHelloMultiV2andSingle

import javax.security.auth.x500.X500Principal; //導入依賴的package包/類
/**
 * Make a TLSv1.2 ClientHello multiple CertStatusReqItemV2s of different
 * types.  One of the middle items should be acceptable while the others
 * have responder IDs.  The status_request (v1) should also be acceptable
 * but should be overridden in favor of the status_request_v2.
 */
private static ByteBuffer makeHelloMultiV2andSingle() throws IOException {
    // Craft the ClientHello byte buffer
    HelloExtensions exts = new HelloExtensions();
    List<ResponderId> fooRid = Collections.singletonList(
            new ResponderId(new X500Principal("CN=Foo")));
    List<ResponderId> barRid = Collections.singletonList(
            new ResponderId(new X500Principal("CN=Bar")));
    List<CertStatusReqItemV2> itemList = new ArrayList<>();
    itemList.add(new CertStatusReqItemV2(StatusRequestType.OCSP,
            new OCSPStatusRequest(null, null)));
    itemList.add(new CertStatusReqItemV2(StatusRequestType.OCSP_MULTI,
            new OCSPStatusRequest(fooRid, null)));
    itemList.add(new CertStatusReqItemV2(StatusRequestType.OCSP_MULTI,
            new OCSPStatusRequest(null, null)));
    itemList.add(new CertStatusReqItemV2(StatusRequestType.OCSP_MULTI,
            new OCSPStatusRequest(barRid, null)));

    exts.add(RNIEXT);
    exts.add(SIGALGEXT);
    exts.add(new CertStatusReqExtension(StatusRequestType.OCSP,
            new OCSPStatusRequest(null, null)));
    exts.add(new CertStatusReqListV2Extension(itemList));
    return createTlsRecord(Record.ct_handshake, VER_1_2,
            createClientHelloMsg(VER_1_2, SID, SUITES, exts));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:32,代碼來源:StatusReqSelection.java


注:本文中的javax.security.auth.x500.X500Principal類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。