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


Java Certificate.getEncoded方法代码示例

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


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

示例1: getFingerprint

import java.security.cert.Certificate; //导入方法依赖的package包/类
public static String getFingerprint(Certificate certificate)
{
    if (certificate == null)
    {
        return "NO VALID CERTIFICATE FOUND";
    }
    try
    {
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        byte[] der = certificate.getEncoded();
        md.update(der);
        byte[] digest = md.digest();
        return hexify(digest);
    }
    catch (Exception e)
    {
        return null;
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:20,代码来源:CertificateHelper.java

示例2: encodeCertificate

import java.security.cert.Certificate; //导入方法依赖的package包/类
private void encodeCertificate(
    Certificate         cert,
    DataOutputStream    dOut)
    throws IOException
{
    try
    {
        byte[]      cEnc = cert.getEncoded();

        dOut.writeUTF(cert.getType());
        dOut.writeInt(cEnc.length);
        dOut.write(cEnc);
    }
    catch (CertificateEncodingException ex)
    {
        throw new IOException(ex.toString());
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:19,代码来源:BcKeyStoreSpi.java

示例3: writeCertArray

import java.security.cert.Certificate; //导入方法依赖的package包/类
private void writeCertArray(Writer writer, Certificate[] certificates) throws IOException {
  if (certificates == null) {
    writer.write("-1\n");
    return;
  }
  try {
    writer.write(Integer.toString(certificates.length) + '\n');
    for (Certificate certificate : certificates) {
      byte[] bytes = certificate.getEncoded();
      String line = Base64.encode(bytes);
      writer.write(line + '\n');
    }
  } catch (CertificateEncodingException e) {
    throw new IOException(e.getMessage());
  }
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:17,代码来源:HttpResponseCache.java

示例4: createSignatureSerializableObjects

import java.security.cert.Certificate; //导入方法依赖的package包/类
private void createSignatureSerializableObjects(Set<Certificate> certs) {
	for(Certificate cert : certs) {
		try {
			SignatureSerializableObject sso = new SignatureSerializableObject(cert.getEncoded());
			certificates.add(sso);
		}catch(Exception ex) {
			LoggerHelper.logEvent(MyLevel.EXCEPTION_ANALYSIS, ex.getMessage());
			ex.printStackTrace();
			System.exit(0);
		}
	}
}
 
开发者ID:srasthofer,项目名称:FuzzDroid,代码行数:13,代码来源:AntiIntegrityCheckFuzzyAnalysis.java

示例5: writeCert

import java.security.cert.Certificate; //导入方法依赖的package包/类
private static void writeCert(DataOutputStream dout, Certificate cert)
    throws IOException, CertificateException
{
    dout.writeUTF(cert.getType());
    byte[] b = cert.getEncoded();
    dout.writeInt(b.length);
    dout.write(b);
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:9,代码来源:JKS.java

示例6: equals

import java.security.cert.Certificate; //导入方法依赖的package包/类
public boolean equals(
    Object o)
{
    if (o == this)
    {
        return true;
    }

    if (!(o instanceof Certificate))
    {
        return false;
    }

    Certificate other = (Certificate)o;

    try
    {
        byte[] b1 = this.getEncoded();
        byte[] b2 = other.getEncoded();

        return Arrays.areEqual(b1, b2);
    }
    catch (CertificateEncodingException e)
    {
        return false;
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:28,代码来源:X509CertificateObject.java

示例7: addCertificateToKeychain

import java.security.cert.Certificate; //导入方法依赖的package包/类
private long addCertificateToKeychain(String alias, Certificate cert) {
    byte[] certblob = null;
    long returnValue = 0;

    try {
        certblob = cert.getEncoded();
        returnValue = _addItemToKeychain(alias, true, certblob, null);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return returnValue;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:KeychainStore.java

示例8: getCertFingerPrint

import java.security.cert.Certificate; //导入方法依赖的package包/类
/**
 * Gets the requested finger print of the certificate.
 */
private String getCertFingerPrint(String mdAlg, Certificate cert)
    throws Exception
{
    byte[] encCertInfo = cert.getEncoded();
    MessageDigest md = MessageDigest.getInstance(mdAlg);
    byte[] digest = md.digest(encCertInfo);
    return toHexString(digest);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:Main.java

示例9: resolveX509Certificate

import java.security.cert.Certificate; //导入方法依赖的package包/类
private PrivateKey resolveX509Certificate(
    XMLX509Certificate x509Cert
) throws XMLSecurityException, KeyStoreException {
    log.log(java.util.logging.Level.FINE, "Can I resolve X509Certificate?");
    byte[] x509CertBytes = x509Cert.getCertificateBytes();

    Enumeration<String> aliases = keyStore.aliases();
    while (aliases.hasMoreElements()) {
        String alias = aliases.nextElement();
        if (keyStore.isKeyEntry(alias)) {

            Certificate cert = keyStore.getCertificate(alias);
            if (cert instanceof X509Certificate) {
                byte[] certBytes = null;

                try {
                    certBytes = cert.getEncoded();
                } catch (CertificateEncodingException e1) {
                }

                if (certBytes != null && Arrays.equals(certBytes, x509CertBytes)) {
                    log.log(java.util.logging.Level.FINE, "match !!! ");

                    try {
                        Key key = keyStore.getKey(alias, password);
                        if (key instanceof PrivateKey) {
                            return (PrivateKey) key;
                        }
                    }
                    catch (Exception e) {
                        log.log(java.util.logging.Level.FINE, "Cannot recover the key", e);
                        // Keep searching
                    }
                }
            }
        }
    }

    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:41,代码来源:PrivateKeyResolver.java

示例10: main

import java.security.cert.Certificate; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    int n = 500000;
    String ks = System.getProperty("test.src", ".")
            + "/../../ssl/etc/keystore";
    String pass = "passphrase";
    String alias = "dummy";

    KeyStore keyStore = KeyStore.getInstance("JKS");
    keyStore.load(new FileInputStream(ks), pass.toCharArray());
    Certificate signerCert = keyStore.getCertificate(alias);
    byte[] encoded = signerCert.getEncoded();
    X509CertImpl signerCertImpl = new X509CertImpl(encoded);
    X509CertInfo signerCertInfo = (X509CertInfo)signerCertImpl.get(
            X509CertImpl.NAME + "." + X509CertImpl.INFO);
    X500Name owner = (X500Name)signerCertInfo.get(X509CertInfo.SUBJECT + "."
            + X509CertInfo.DN_NAME);

    Date date = new Date();
    PrivateKey privateKey = (PrivateKey)
            keyStore.getKey(alias, pass.toCharArray());
    String sigAlgName = signerCertImpl.getSigAlgOID();

    X509CRLEntry[] badCerts = new X509CRLEntry[n];
    CRLExtensions ext = new CRLExtensions();
    ext.set("Reason", new CRLReasonCodeExtension(1));
    for (int i = 0; i < n; i++) {
        badCerts[i] = new X509CRLEntryImpl(
                BigInteger.valueOf(i), date, ext);
    }
    X509CRLImpl crl = new X509CRLImpl(owner, date, date, badCerts);
    crl.sign(privateKey, sigAlgName);
    byte[] data = crl.getEncodedInternal();

    // Make sure the CRL is big enough
    if ((data[1]&0xff) != 0x84) {
        throw new Exception("The file should be big enough?");
    }

    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    cf.generateCRL(new ByteArrayInputStream(data));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:42,代码来源:BigCRL.java

示例11: getSslSocketFactory

import java.security.cert.Certificate; //导入方法依赖的package包/类
/**
 * @param context   上下文
 * @param bksFileId "XXX.bks"文件(文件位置res/raw/XXX.bks)
 * @param password  The certificate's password.
 * @return SSLParams
 */
public static SSLParams getSslSocketFactory(Context context, @RawRes int bksFileId, String password, String alias) {
    if (context == null) {
        throw new NullPointerException("context == null");
    }
    if (TextUtils.isEmpty(password) || TextUtils.isEmpty(alias)) {
        throw new NullPointerException("password == null or alias == null!");
    }
    SSLParams sslParams = new SSLParams();
    try {
        // 创建一个BKS类型的KeyStore,存储我们信任的证书
        KeyStore clientKeyStore = KeyStore.getInstance("BKS");
        clientKeyStore.load(context.getResources().openRawResource(bksFileId), password.toCharArray());
        //通过alias直接从密钥库中读取证书
        Certificate rootCA = clientKeyStore.getCertificate(alias);
        // Turn it to X509 format.
        InputStream certInput = new ByteArrayInputStream(rootCA.getEncoded());
        X509Certificate serverCert = (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(certInput);
        //关闭流
        CloseUtils.closeIO(certInput);

        TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        //用我们之前的keyStore实例初始化TrustManagerFactory,这样trustManagerFactory就会信任keyStore中的证书
        trustManagerFactory.init(clientKeyStore);

        KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        keyManagerFactory.init(clientKeyStore, password.toCharArray());

        X509TrustManager x509TrustManager = new SafeTrustManager(serverCert);

        //创建TLS类型的SSLContext对象,that uses our TrustManager
        SSLContext sslContext = SSLContext.getInstance("TLS");

        //用上面得到的trustManagers初始化SSLContext,这样sslContext就会信任keyStore中的证书
        sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), new SecureRandom());

        //Android 4.X 对TLS1.1、TLS1.2的支持
        sslParams.sSLSocketFactory = new Tls12SocketFactory(sslContext.getSocketFactory());
        sslParams.trustManager = x509TrustManager;
        return sslParams;
    } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException | UnrecoverableKeyException | IOException | CertificateException e) {
        throw new AssertionError(e);
    }
}
 
开发者ID:guiying712,项目名称:AndroidModulePattern,代码行数:50,代码来源:HttpsUtils.java

示例12: doGenCRL

import java.security.cert.Certificate; //导入方法依赖的package包/类
private void doGenCRL(PrintStream out)
        throws Exception {
    if (ids == null) {
        throw new Exception("Must provide -id when -gencrl");
    }
    Certificate signerCert = keyStore.getCertificate(alias);
    byte[] encoded = signerCert.getEncoded();
    X509CertImpl signerCertImpl = new X509CertImpl(encoded);
    X509CertInfo signerCertInfo = (X509CertInfo)signerCertImpl.get(
            X509CertImpl.NAME + "." + X509CertImpl.INFO);
    X500Name owner = (X500Name)signerCertInfo.get(X509CertInfo.SUBJECT + "." +
                                                  X509CertInfo.DN_NAME);

    Date firstDate = getStartDate(startDate);
    Date lastDate = (Date) firstDate.clone();
    lastDate.setTime(lastDate.getTime() + validity*1000*24*60*60);
    CertificateValidity interval = new CertificateValidity(firstDate,
                                                           lastDate);


    PrivateKey privateKey =
            (PrivateKey)recoverKey(alias, storePass, keyPass).fst;
    if (sigAlgName == null) {
        sigAlgName = getCompatibleSigAlgName(privateKey.getAlgorithm());
    }

    X509CRLEntry[] badCerts = new X509CRLEntry[ids.size()];
    for (int i=0; i<ids.size(); i++) {
        String id = ids.get(i);
        int d = id.indexOf(':');
        if (d >= 0) {
            CRLExtensions ext = new CRLExtensions();
            ext.set("Reason", new CRLReasonCodeExtension(Integer.parseInt(id.substring(d+1))));
            badCerts[i] = new X509CRLEntryImpl(new BigInteger(id.substring(0, d)),
                    firstDate, ext);
        } else {
            badCerts[i] = new X509CRLEntryImpl(new BigInteger(ids.get(i)), firstDate);
        }
    }
    X509CRLImpl crl = new X509CRLImpl(owner, firstDate, lastDate, badCerts);
    crl.sign(privateKey, sigAlgName);
    if (rfc) {
        out.println("-----BEGIN X509 CRL-----");
        out.println(Base64.getMimeEncoder().encodeToString(crl.getEncodedInternal()));
        out.println("-----END X509 CRL-----");
    } else {
        out.write(crl.getEncodedInternal());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:50,代码来源:Main.java

示例13: doGenCRL

import java.security.cert.Certificate; //导入方法依赖的package包/类
private void doGenCRL(PrintStream out)
        throws Exception {
    if (ids == null) {
        throw new Exception("Must provide -id when -gencrl");
    }
    Certificate signerCert = keyStore.getCertificate(alias);
    byte[] encoded = signerCert.getEncoded();
    X509CertImpl signerCertImpl = new X509CertImpl(encoded);
    X509CertInfo signerCertInfo = (X509CertInfo)signerCertImpl.get(
            X509CertImpl.NAME + "." + X509CertImpl.INFO);
    X500Name owner = (X500Name)signerCertInfo.get(X509CertInfo.SUBJECT + "." +
                                                  X509CertInfo.DN_NAME);

    Date firstDate = getStartDate(startDate);
    Date lastDate = (Date) firstDate.clone();
    lastDate.setTime(lastDate.getTime() + validity*1000*24*60*60);
    CertificateValidity interval = new CertificateValidity(firstDate,
                                                           lastDate);


    PrivateKey privateKey =
            (PrivateKey)recoverKey(alias, storePass, keyPass).fst;
    if (sigAlgName == null) {
        sigAlgName = getCompatibleSigAlgName(privateKey);
    }

    X509CRLEntry[] badCerts = new X509CRLEntry[ids.size()];
    for (int i=0; i<ids.size(); i++) {
        String id = ids.get(i);
        int d = id.indexOf(':');
        if (d >= 0) {
            CRLExtensions ext = new CRLExtensions();
            ext.set("Reason", new CRLReasonCodeExtension(Integer.parseInt(id.substring(d+1))));
            badCerts[i] = new X509CRLEntryImpl(new BigInteger(id.substring(0, d)),
                    firstDate, ext);
        } else {
            badCerts[i] = new X509CRLEntryImpl(new BigInteger(ids.get(i)), firstDate);
        }
    }
    X509CRLImpl crl = new X509CRLImpl(owner, firstDate, lastDate, badCerts);
    crl.sign(privateKey, sigAlgName);
    if (rfc) {
        out.println("-----BEGIN X509 CRL-----");
        out.println(Base64.getMimeEncoder(64, CRLF).encodeToString(crl.getEncodedInternal()));
        out.println("-----END X509 CRL-----");
    } else {
        out.write(crl.getEncodedInternal());
    }
    checkWeak(rb.getString("the.generated.crl"), crl, privateKey);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:51,代码来源:Main.java

示例14: doGenCRL

import java.security.cert.Certificate; //导入方法依赖的package包/类
private void doGenCRL(PrintStream out)
        throws Exception {
    if (ids == null) {
        throw new Exception("Must provide -id when -gencrl");
    }
    Certificate signerCert = keyStore.getCertificate(alias);
    byte[] encoded = signerCert.getEncoded();
    X509CertImpl signerCertImpl = new X509CertImpl(encoded);
    X509CertInfo signerCertInfo = (X509CertInfo)signerCertImpl.get(
            X509CertImpl.NAME + "." + X509CertImpl.INFO);
    X500Name owner = (X500Name)signerCertInfo.get(X509CertInfo.SUBJECT + "." +
                                                  X509CertInfo.DN_NAME);

    Date firstDate = getStartDate(startDate);
    Date lastDate = (Date) firstDate.clone();
    lastDate.setTime(lastDate.getTime() + validity*1000*24*60*60);
    CertificateValidity interval = new CertificateValidity(firstDate,
                                                           lastDate);


    PrivateKey privateKey =
            (PrivateKey)recoverKey(alias, storePass, keyPass).fst;
    if (sigAlgName == null) {
        sigAlgName = getCompatibleSigAlgName(privateKey.getAlgorithm());
    }

    X509CRLEntry[] badCerts = new X509CRLEntry[ids.size()];
    for (int i=0; i<ids.size(); i++) {
        String id = ids.get(i);
        int d = id.indexOf(':');
        if (d >= 0) {
            CRLExtensions ext = new CRLExtensions();
            ext.set("Reason", new CRLReasonCodeExtension(Integer.parseInt(id.substring(d+1))));
            badCerts[i] = new X509CRLEntryImpl(new BigInteger(id.substring(0, d)),
                    firstDate, ext);
        } else {
            badCerts[i] = new X509CRLEntryImpl(new BigInteger(ids.get(i)), firstDate);
        }
    }
    X509CRLImpl crl = new X509CRLImpl(owner, firstDate, lastDate, badCerts);
    crl.sign(privateKey, sigAlgName);
    if (rfc) {
        out.println("-----BEGIN X509 CRL-----");
        out.println(Base64.getMimeEncoder(64, CRLF).encodeToString(crl.getEncodedInternal()));
        out.println("-----END X509 CRL-----");
    } else {
        out.write(crl.getEncodedInternal());
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:50,代码来源:Main.java


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