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


Java X509Certificate.getEncoded方法代码示例

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


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

示例1: verifySignature

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
public static boolean verifySignature(CMSSignedData cmsSignedData, X509Certificate cert) {
    try {
        if (Security.getProvider("BC") == null)
            Security.addProvider(new BouncyCastleProvider());

        Collection<SignerInformation> signers = cmsSignedData.getSignerInfos().getSigners();
        X509CertificateHolder ch = new X509CertificateHolder(cert.getEncoded());
        for (SignerInformation si : signers)
            if (si.getSID().match(ch))
                if (si.verify(new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build(ch)))
                    return true;
    } catch (Exception e) {}
    return false;
}
 
开发者ID:damianofalcioni,项目名称:Websocket-Smart-Card-Signer,代码行数:15,代码来源:PKCS7Manager.java

示例2: setCertificateChain

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
@Override
public void setCertificateChain(X509Certificate[] certificateChain) {
    if (CollectionUtil.isEmpty(certificateChain)) {
        this.certificateChain = null;
        this.bcCertificateChain = null;
        return;
    }

    this.certificateChain = certificateChain;
    setPublicKey(certificateChain[0].getPublicKey());
    final int n = certificateChain.length;

    this.bcCertificateChain = new X509CertificateHolder[n];
    for (int i = 0; i < n; i++) {
        X509Certificate cert = this.certificateChain[i];
        try {
            this.bcCertificateChain[i] = new X509CertificateHolder(cert.getEncoded());
        } catch (CertificateEncodingException | IOException ex) {
            throw new IllegalArgumentException(
                    String.format("%s occurred while parsing certificate at index %d: %s",
                            ex.getClass().getName(), i, ex.getMessage()), ex);
        }
    }
}
 
开发者ID:xipki,项目名称:xitk,代码行数:25,代码来源:DfltConcurrentContentSigner.java

示例3: getSha1Fingerprint

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
@Override
public String getSha1Fingerprint(X509Certificate cert) throws NoSuchAlgorithmException, CertificateEncodingException, IllegalArgumentException {

    if(cert == null) {
        throw new IllegalArgumentException("Provided certificate is empty");
    }

    MessageDigest md = MessageDigest.getInstance("SHA-1");
    byte[] der = cert.getEncoded();
    md.update(der);
    byte[] digest = md.digest();
    return DatatypeConverter.printHexBinary(digest);
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:14,代码来源:X509TrustManagerFactory.java

示例4: getSigningKeyCertificate

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
 * Gets the encoded representation of the first signing certificated used to sign current APK
 *
 * @param ctx
 * @return
 */
private static byte[] getSigningKeyCertificate(Context ctx) {
    try {
        PackageManager pm = ctx.getPackageManager();
        String packageName = ctx.getPackageName();
        int flags = PackageManager.GET_SIGNATURES;
        PackageInfo packageInfo = pm.getPackageInfo(packageName, flags);
        Signature[] signatures = packageInfo.signatures;

        if (signatures != null && signatures.length >= 1) {
            //takes just the first signature, TODO: handle multi signed apks
            byte[] cert = signatures[0].toByteArray();
            InputStream input = new ByteArrayInputStream(cert);
            CertificateFactory cf = CertificateFactory.getInstance("X509");
            X509Certificate c = (X509Certificate) cf.generateCertificate(input);
            return c.getEncoded();
        }
    } catch (Exception e) {
        Log.w(TAG, e);
    }
    return null;
}
 
开发者ID:Catherine22,项目名称:SecuritySample,代码行数:28,代码来源:Utils.java

示例5: getCertificateFingerPrint

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
 * Gets the requested finger print of the certificate.
 */
private static String getCertificateFingerPrint(String mdAlg,
                                                X509Certificate cert) {
    String fingerPrint = "";
    try {
        byte[] encCertInfo = cert.getEncoded();
        MessageDigest md = MessageDigest.getInstance(mdAlg);
        byte[] digest = md.digest(encCertInfo);
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < digest.length; i++) {
            byte2hex(digest[i], buf);
        }
        fingerPrint = buf.toString();
    } catch (NoSuchAlgorithmException | CertificateEncodingException e) {
        // ignored
    }
    return fingerPrint;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:BlacklistedCertsConverter.java

示例6: getThumbPrint

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
public static String getThumbPrint(X509Certificate cert) 
	throws NoSuchAlgorithmException, CertificateEncodingException {
	MessageDigest md = MessageDigest.getInstance("SHA-1"); // NOI18N
	byte[] der = cert.getEncoded();
	md.update(der);
	byte[] digest = md.digest();
	StringBuilder sb = new StringBuilder();
    for (int i = 0; i < digest.length; i++) {
        sb.append(":").append(Integer.toHexString(((int)digest[i]) & 0xff));
    }
    return sb.substring(1);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:CertificationPanel.java

示例7: Asn1EntityIdAndCert

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
public Asn1EntityIdAndCert(P11EntityIdentifier entityId, X509Certificate certificate) {
    ParamUtil.requireNonNull("entityId", entityId);
    ParamUtil.requireNonNull("certificate", certificate);
    this.entityId = new Asn1P11EntityIdentifier(entityId);
    byte[] encoded;
    try {
        encoded = certificate.getEncoded();
    } catch (CertificateEncodingException ex) {
        throw new IllegalArgumentException("could not encode certificate: " + ex.getMessage(),
                ex);
    }
    this.certificate = Certificate.getInstance(encoded);
}
 
开发者ID:xipki,项目名称:xitk,代码行数:14,代码来源:Asn1EntityIdAndCert.java

示例8: getMobileInfoString

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
@SuppressLint({"StringFormatMatches", "StringFormatInvalid"})
private String getMobileInfoString(Context c) {
    c.getPackageManager();
    String apksign = "error getting package signature";
    String version = "error getting version";
    try {
        @SuppressLint("PackageManagerGetSignatures") Signature raw = c.getPackageManager().getPackageInfo(c.getPackageName(), PackageManager.GET_SIGNATURES).signatures[0];
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        X509Certificate cert = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(raw.toByteArray()));
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        byte[] der = cert.getEncoded();
        md.update(der);
        byte[] digest = md.digest();
        if (Arrays.equals(digest, VpnStatus.officalkey)) apksign = c.getString(R.string.official_build);
        else if (Arrays.equals(digest, VpnStatus.officaldebugkey)) apksign = c.getString(R.string.debug_build);
        else if (Arrays.equals(digest, VpnStatus.amazonkey)) apksign = "amazon version";
        else if (Arrays.equals(digest, VpnStatus.fdroidkey)) apksign = "F-Droid built and signed version";
        else apksign = c.getString(R.string.built_by, cert.getSubjectX500Principal().getName());
        PackageInfo packageinfo = c.getPackageManager().getPackageInfo(c.getPackageName(), 0);
        version = packageinfo.versionName;
    } catch (PackageManager.NameNotFoundException | CertificateException |
            NoSuchAlgorithmException ignored) {
    }
    Object[] argsext = Arrays.copyOf(mArgs, mArgs.length);
    argsext[argsext.length - 1] = apksign;
    argsext[argsext.length - 2] = version;
    return c.getString(R.string.mobile_info, argsext);
}
 
开发者ID:akashdeepsingh9988,项目名称:Cybernet-VPN,代码行数:29,代码来源:LogItem.java

示例9: getThumbprint

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
public static String getThumbprint(X509Certificate cert, boolean space) throws NoSuchAlgorithmException, CertificateEncodingException {
	MessageDigest md = MessageDigest.getInstance("SHA-1");
	byte[] der = cert.getEncoded();
	md.update(der);
	byte[] digest = md.digest();
	return hexify(digest, space);
}
 
开发者ID:prydin,项目名称:vrops-export,代码行数:8,代码来源:CertUtils.java

示例10: encodePKIPATH

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
 * Encode the CertPath using PKIPATH format.
 *
 * @return a byte array containing the binary encoding of the PkiPath object
 * @exception CertificateEncodingException if an exception occurs
 */
private byte[] encodePKIPATH() throws CertificateEncodingException {

    ListIterator<X509Certificate> li = certs.listIterator(certs.size());
    try {
        DerOutputStream bytes = new DerOutputStream();
        // encode certs in reverse order (trust anchor to target)
        // according to PkiPath format
        while (li.hasPrevious()) {
            X509Certificate cert = li.previous();
            // check for duplicate cert
            if (certs.lastIndexOf(cert) != certs.indexOf(cert)) {
                throw new CertificateEncodingException
                    ("Duplicate Certificate");
            }
            // get encoded certificates
            byte[] encoded = cert.getEncoded();
            bytes.write(encoded);
        }

        // Wrap the data in a SEQUENCE
        DerOutputStream derout = new DerOutputStream();
        derout.write(DerValue.tag_SequenceOf, bytes);
        return derout.toByteArray();

    } catch (IOException ioe) {
       throw new CertificateEncodingException("IOException encoding " +
               "PkiPath data: " + ioe, ioe);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:X509CertPath.java

示例11: getCertificateFingerPrint

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
 * Gets the requested finger print of the certificate.
 */
private static String getCertificateFingerPrint(
        String mdAlg, X509Certificate cert) throws Exception {
    byte[] encCertInfo = cert.getEncoded();
    MessageDigest md = MessageDigest.getInstance(mdAlg);
    byte[] digest = md.digest(encCertInfo);
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < digest.length; i++) {
        byte2hex(digest[i], buf);
    }
    return buf.toString();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:BlacklistedCertsConverter.java

示例12: getPinData

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
@Override
protected byte[] getPinData(X509Certificate cert) throws CertificateEncodingException {
	return cert.getEncoded();
}
 
开发者ID:haducloc,项目名称:appslandia-sweetsop,代码行数:5,代码来源:CertificatePin.java


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