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


Java X509Certificate.getSerialNumber方法代码示例

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


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

示例1: main

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

        byte[] data = "Hello".getBytes();
        X500Name n = new X500Name("cn=Me");

        CertAndKeyGen cakg = new CertAndKeyGen("RSA", "SHA256withRSA");
        cakg.generate(1024);
        X509Certificate cert = cakg.getSelfCertificate(n, 1000);

        MessageDigest md = MessageDigest.getInstance("SHA-256");
        PKCS9Attributes authed = new PKCS9Attributes(new PKCS9Attribute[]{
            new PKCS9Attribute(PKCS9Attribute.CONTENT_TYPE_OID, ContentInfo.DATA_OID),
            new PKCS9Attribute(PKCS9Attribute.MESSAGE_DIGEST_OID, md.digest(data)),
        });

        Signature s = Signature.getInstance("SHA256withRSA");
        s.initSign(cakg.getPrivateKey());
        s.update(authed.getDerEncoding());
        byte[] sig = s.sign();

        SignerInfo signerInfo = new SignerInfo(
                n,
                cert.getSerialNumber(),
                AlgorithmId.get("SHA-256"),
                authed,
                AlgorithmId.get("SHA256withRSA"),
                sig,
                null
                );

        PKCS7 pkcs7 = new PKCS7(
                new AlgorithmId[] {signerInfo.getDigestAlgorithmId()},
                new ContentInfo(data),
                new X509Certificate[] {cert},
                new SignerInfo[] {signerInfo});

        if (pkcs7.verify(signerInfo, data) == null) {
            throw new Exception("Not verified");
        }
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:41,代码来源:NonStandardNames.java

示例2: getCertificate

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
 * Returns the X.509 certificate listed in this PKCS7 block
 * which has a matching serial number and Issuer name, or
 * null if one is not found.
 *
 * @param serial the serial number of the certificate to retrieve.
 * @param issuerName the Distinguished Name of the Issuer.
 */
public X509Certificate getCertificate(BigInteger serial, X500Name issuerName) {
    if (certificates != null) {
        if (certIssuerNames == null)
            populateCertIssuerNames();
        for (int i = 0; i < certificates.length; i++) {
            X509Certificate cert = certificates[i];
            BigInteger thisSerial = cert.getSerialNumber();
            if (serial.equals(thisSerial)
                && issuerName.equals(certIssuerNames[i]))
            {
                return cert;
            }
        }
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:PKCS7.java

示例3: signatureBlock

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/** Write a .RSA file with a digital signature. */
private static void signatureBlock(
        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 });
    
    System.out.print("\rGenerating signature block...");
    
    pkcs7.encodeSignedData(out);
}
 
开发者ID:KuroroLucilfer,项目名称:PackageSigner2,代码行数:24,代码来源:Signer.java

示例4: checkServerTrusted

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType)
    throws CertificateException
{
  trustManager.checkServerTrusted(chain, authType);

  for (X509Certificate certificate : chain) {
    for (Pair<String, BigInteger> blacklistedSerial : BLACKLIST) {
      if (certificate.getIssuerDN().getName().equals(blacklistedSerial.first()) &&
          certificate.getSerialNumber().equals(blacklistedSerial.second()))
      {
        throw new CertificateException("Blacklisted Serial: " + certificate.getSerialNumber());
      }
    }
  }

}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:18,代码来源:BlacklistingTrustManager.java

示例5: writeSignatureBlock

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/** 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);
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:20,代码来源:SignedJarBuilder.java

示例6: engineGetCertificateAlias

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public String engineGetCertificateAlias(final Certificate cert) {
    if (!(cert instanceof X509Certificate)) {
        return null;
    }
    final BigInteger serial = ((X509Certificate) cert).getSerialNumber();
    final X500Principal principal = ((X509Certificate) cert).getIssuerX500Principal();
    for (final String alias : userCertAliases) {
    	final X509Certificate c = (X509Certificate) engineGetCertificate(alias);
        if (c.getSerialNumber() == serial && principal.equals(principal)) {
            return alias;
        }
    }
    return null;
}
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:17,代码来源:CeresKeyStoreImpl.java

示例7: getID

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
 * build [alias + issuer + serialNumber] string from a cert
 */
private String getID(String alias, X509Certificate cert) {
    X500Principal issuer = cert.getIssuerX500Principal();
    BigInteger serialNum = cert.getSerialNumber();

    return alias +
            ALIAS_SEP +
            issuer.getName(X500Principal.CANONICAL) +
            ALIAS_SEP +
            serialNum.toString();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:P11KeyStore.java

示例8: XMLX509IssuerSerial

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
 * Constructor XMLX509IssuerSerial
 *
 * @param doc
 * @param x509certificate
 */
public XMLX509IssuerSerial(Document doc, X509Certificate x509certificate) {
    this(
        doc,
        x509certificate.getIssuerX500Principal().getName(),
        x509certificate.getSerialNumber()
    );
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:XMLX509IssuerSerial.java

示例9: JceKeyAgreeRecipientId

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
public JceKeyAgreeRecipientId(X509Certificate certificate)
{
    this(certificate.getIssuerX500Principal(), certificate.getSerialNumber());
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:5,代码来源:JceKeyAgreeRecipientId.java

示例10: getSerialNumber

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
public BigInteger getSerialNumber() {
    X509Certificate cert = getCertificateList().get(0);
    return cert.getSerialNumber();
}
 
开发者ID:Hitachi-Data-Systems,项目名称:Open-DM,代码行数:5,代码来源:SSLCertChain.java

示例11: getSerialNumberString

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
public String getSerialNumberString() {
    X509Certificate cert = getCertificateList().get(0);
    BigInteger sn = cert.getSerialNumber();
    return byteArrayToColonSeparatedHexString(sn.toByteArray(), ":");
}
 
开发者ID:Hitachi-Data-Systems,项目名称:Open-DM,代码行数:6,代码来源:SSLCertChain.java

示例12: X509IssuerSerial

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
 * Construct an X509IssuerSerial from an X509Certificate.
 */
X509IssuerSerial(X509Certificate cert) {
    this(cert.getIssuerX500Principal(), cert.getSerialNumber());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:7,代码来源:X509CRLImpl.java

示例13: JcaX509CertificateHolderSelector

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
 * Construct a signer identifier based on the issuer, serial number and subject key identifier (if present) of the passed in
 * certificate.
 *
 * @param certificate certificate providing the issue and serial number and subject key identifier.
 */
public JcaX509CertificateHolderSelector(X509Certificate certificate)
{
    super(convertPrincipal(certificate.getIssuerX500Principal()), certificate.getSerialNumber(), getSubjectKeyId(certificate));
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:11,代码来源:JcaX509CertificateHolderSelector.java

示例14: JceKeyTransRecipientId

import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
 * Construct a recipient id based on the issuer, serial number and subject key identifier (if present) of the passed in
 * certificate.
 *
 * @param certificate certificate providing the issue and serial number and subject key identifier.
 */
public JceKeyTransRecipientId(X509Certificate certificate)
{
    super(convertPrincipal(certificate.getIssuerX500Principal()), certificate.getSerialNumber(), CMSUtils.getSubjectKeyId(certificate));
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:11,代码来源:JceKeyTransRecipientId.java


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