gpt4 book ai didi

javax.security.auth.x500.X500PrivateCredential类的使用及代码示例

转载 作者:知者 更新时间:2024-03-22 06:07:05 26 4
gpt4 key购买 nike

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

X500PrivateCredential介绍

暂无

代码示例

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

private static IdentityCredentials getSingleCredential(Object rawCredential) {
  if (rawCredential == null) {
    return IdentityCredentials.NONE;
  } else if (rawCredential instanceof Credential) {
    return IdentityCredentials.NONE.withCredential((Credential) rawCredential);
  } else if (rawCredential instanceof GSSCredential) {
    return IdentityCredentials.NONE.withCredential(new GSSKerberosCredential((GSSCredential) rawCredential));
  } else if (rawCredential instanceof Password) {
    return IdentityCredentials.NONE.withCredential(new PasswordCredential((Password) rawCredential));
  } else if (rawCredential instanceof X509Certificate) {
    return IdentityCredentials.NONE.withCredential(new X509CertificateChainPublicCredential((X509Certificate) rawCredential));
  } else if (rawCredential instanceof X509Certificate[]) {
    return IdentityCredentials.NONE.withCredential(new X509CertificateChainPublicCredential((X509Certificate[]) rawCredential));
  } else if (rawCredential instanceof X500PrivateCredential) {
    final X500PrivateCredential credential = (X500PrivateCredential) rawCredential;
    return IdentityCredentials.NONE.withCredential(new X509CertificateChainPrivateCredential(credential.getPrivateKey(), credential.getCertificate()));
  } else if (rawCredential instanceof String) {
    return IdentityCredentials.NONE.withCredential(new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, ((String) rawCredential).toCharArray())));
  } else if (rawCredential instanceof char[]) {
    // todo: automatically decode to other credential types
    return IdentityCredentials.NONE.withCredential(new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, (char[]) rawCredential)));
  } else if (rawCredential instanceof byte[]) {
    // todo: automatically decode to other credential types
    return IdentityCredentials.NONE.withCredential(new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, new String((byte[]) rawCredential, StandardCharsets.UTF_8).toCharArray())));
  } else {
    return IdentityCredentials.NONE;
  }
}

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

KeyStore ks = KeyStore.getInstance(KEYSTORE_TYPE, "BC");
ks.load(new FileInputStream(KEYSTORE_FILE), KEYSTORE_PWD);
X500PrivateCredential creds = new X500PrivateCredential(
    (X509Certificate) ks.getCertificate(KEYSTORE_ALIAS),
    (PrivateKey) ks.getKey(KEYSTORE_ALIAS, KEYSTORE_PWD)
            new JcaDigestCalculatorProviderBuilder().setProvider("BC").build()
        ).build(
            new JcaContentSignerBuilder("SHA1withRSA").setProvider("BC").build(creds.getPrivateKey()),
            creds.getCertificate()

代码示例来源:origin: au.net.zeus.jgdms/jgdms-rmi-tls

if (cred instanceof X500PrivateCredential) {
  X500PrivateCredential xpc = (X500PrivateCredential) cred;
  if (cert.equals(xpc.getCertificate())) {
  result = xpc;
  break;

代码示例来源:origin: net.sf.wsag4j/wsag4j-api

userCredential = new X500PrivateCredential( userCertificateChain[0], userKey );
  new X500Principal( userCredential.getCertificate().getSubjectX500Principal().getName() );

代码示例来源:origin: com.hynnet/xws-security

while (it.hasNext()) {
  X500PrivateCredential cred = (X500PrivateCredential)it.next();
  if (cred.getAlias().equals(actualAlias))
    return cred.getCertificate();

代码示例来源:origin: au.net.zeus.jgdms/jgdms-rmi-tls

throw new GeneralSecurityException(
  "Client is not authenticated");
} else if (clientCredential.isDestroyed()) {
  throw new GeneralSecurityException(
  "Private credentials are destroyed");
  X509Certificate cert = clientCredential.getCertificate();
  if (getPrincipal(subject, cert) == null) {
  throw new GeneralSecurityException("Missing principal");

代码示例来源:origin: au.net.zeus.jgdms/jgdms-rmi-tls

new GetPrivateCredentialAction(subject, cert));
PrivateKey privateKey =
cred != null ? cred.getPrivateKey() : null;
if (privateKey == null) {
buf.append("Not found");

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

KeyStore ks = KeyStore.getInstance(KEYSTORE_TYPE, "BC");
ks.load(new FileInputStream(KEYSTORE_FILE), KEYSTORE_PWD);
X500PrivateCredential creds = new X500PrivateCredential(
    (X509Certificate) ks.getCertificate(KEYSTORE_ALIAS),
    (PrivateKey) ks.getKey(KEYSTORE_ALIAS, KEYSTORE_PWD)
signature.initSign(creds.getPrivateKey());
signature.update(fileContent);
            new JcaDigestCalculatorProviderBuilder().setProvider("BC").build()
        ).build(
            new JcaContentSignerBuilder("SHA1withRSA").setProvider("BC").build(creds.getPrivateKey()),
            creds.getCertificate()

代码示例来源:origin: au.net.zeus.jgdms/jgdms-rmi-tls

X509Certificate cert = clientCredential.getCertificate();
clientPrincipal = cert.getSubjectX500Principal();
credentialsValidUntil = Math.min(credentialsValidUntil, certificatesValidUntil(getCertificateChain(getSubject(), cert)));
authenticationPermission = getAuthenticationPermission(cert);
String result = getCertificateName(clientCredential.getCertificate());
  if (logger.isLoggable(Level.FINE)) {
    logger.log(

代码示例来源:origin: com.hynnet/xws-security

while (it.hasNext()) {
  X500PrivateCredential cred = (X500PrivateCredential)it.next();
  if (cred.getAlias().equals(alias))
   return cred.getCertificate();

代码示例来源:origin: au.net.zeus.jgdms/jgdms-rmi-tls

public PrivateKey getPrivateKey(String alias) {
CertPath chain =
  getCertificateChain(getSubject(), alias);
if (chain != null) {
  try {
  X500PrivateCredential xpc =
    getPrivateCredential(firstX509Cert(chain));
  if (xpc != null) {
    return xpc.getPrivateKey();
  }
  } catch (SecurityException e) {
  Logger logger = getLogger();
  if (logger.isLoggable(Levels.HANDLED)) {
    logThrow(logger, Levels.HANDLED,
       SubjectKeyManager.class, "getPrivateKey",
       "get private key for alias {0}\n" +
       "caught exception",
       new Object[] { alias },
       e);
  }
  }
}
return null;
}

代码示例来源:origin: au.net.zeus.jgdms/jgdms-rmi-tls

/**
 * Checks if the two private credentials refer to the same principal and
 * have the equivalent private key.
 */
boolean equalPrivateCredentials(X500PrivateCredential cred1,
        X500PrivateCredential cred2)
{
if (cred1 == null || cred2 == null) {
  return false;
}
X509Certificate cert1 = cred1.getCertificate();
X509Certificate cert2 = cred2.getCertificate();
if (cert1 == null
  || cert2 == null
  || !safeEquals(cert1.getSubjectDN(), cert2.getSubjectDN()))
{
  return false;
}
/*
 * I'm assuming I can depend on the equals method for private keys to
 * check if the two objects represent the same key without being
 * identical objects.  Although that behavior isn't documented, at
 * least the sun.security.pkcs.PKCS8Key class does that.
 * -tjb[8.Jan.2001]
 */
PrivateKey key1 = cred1.getPrivateKey();
return key1 != null && key1.equals(cred2.getPrivateKey());
}

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

KeyStore ks = KeyStore.getInstance(KEYSTORE_TYPE, "BC");
ks.load(new FileInputStream(KEYSTORE_FILE), KEYSTORE_PWD);
X500PrivateCredential creds = new X500PrivateCredential(
    (X509Certificate) ks.getCertificate(KEYSTORE_ALIAS),
    (PrivateKey) ks.getKey(KEYSTORE_ALIAS, KEYSTORE_PWD)
            new JcaDigestCalculatorProviderBuilder().setProvider("BC").build()
        ).build(
            new JcaContentSignerBuilder("SHA1withRSA").setProvider("BC").build(creds.getPrivateKey()),
            creds.getCertificate()

代码示例来源:origin: au.net.zeus.jgdms/jgdms-rmi-tls

for (int i = readOnlyPrivateCredentials.length; --i >= 0; ) {
X500PrivateCredential xpc = readOnlyPrivateCredentials[i];
if (cert.equals(xpc.getCertificate())) {
  return xpc;

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

private static void createSignature(Path srcfile, X500PrivateCredential creds, FileOutputStream target) throws Exception {                
  CMSSignedDataStreamGenerator gen = new CMSSignedDataStreamGenerator() {
    {
      addSignerInfoGenerator(
          new JcaSignerInfoGeneratorBuilder(
              new JcaDigestCalculatorProviderBuilder().setProvider("BC").build()
          ).build(
              new JcaContentSignerBuilder("SHA1withRSA").setProvider("BC").build(creds.getPrivateKey()),
              creds.getCertificate()
          )
      );
      addCertificates(new JcaCertStore(new ArrayList<X509Certificate>() {
        {
          add(creds.getCertificate());
        }
      }));
    }
  };
  try (OutputStream sigOut = gen.open(target, true)) {
    Files.copy(srcfile, sigOut);
  }
}

代码示例来源:origin: com.hynnet/xws-security

while (it.hasNext()) {
  X500PrivateCredential cred = (X500PrivateCredential)it.next();
  X509Certificate cert = cred.getCertificate();
    if (cert.getPublicKey().equals(publicKey))
    return cert;

代码示例来源:origin: com.hynnet/xws-security

while (it.hasNext()) {
 X500PrivateCredential cred = (X500PrivateCredential)it.next();
 X509Certificate x509Cert = cred.getCertificate();
 BigInteger serialNo = x509Cert.getSerialNumber();
 String currentIssuerName =
 if (serialNo.equals(serialNumber) &&
   currentIssuerName.equals(issuerName)) {
   return cred.getPrivateKey();

代码示例来源:origin: au.net.zeus.jgdms/jgdms-rmi-tls

throw new SecurityException("Missing subject");
X509Certificate cert = cred.getCertificate();
if (getPrincipal(subject, cert) == null) {
  throw new SecurityException("Missing principal");

代码示例来源:origin: com.hynnet/xws-security

while (it.hasNext()) {
 X500PrivateCredential cred = (X500PrivateCredential)it.next();
 X509Certificate x509Cert = cred.getCertificate();
 BigInteger serialNo = x509Cert.getSerialNumber();
 String currentIssuerName =
 if (serialNo.equals(serialNumber) &&
   currentIssuerName.equals(issuerName)) {
   return cred.getPrivateKey();

代码示例来源:origin: au.net.zeus.jgdms/jgdms-rmi-tls

: getCertificateName(cred.getCertificate());
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com