本文整理汇总了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");
}
}
示例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;
}
示例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);
}
示例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());
}
}
}
}
示例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);
}
示例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;
}
示例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();
}
示例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()
);
}
示例9: JceKeyAgreeRecipientId
import java.security.cert.X509Certificate; //导入方法依赖的package包/类
public JceKeyAgreeRecipientId(X509Certificate certificate)
{
this(certificate.getIssuerX500Principal(), certificate.getSerialNumber());
}
示例10: getSerialNumber
import java.security.cert.X509Certificate; //导入方法依赖的package包/类
public BigInteger getSerialNumber() {
X509Certificate cert = getCertificateList().get(0);
return cert.getSerialNumber();
}
示例11: getSerialNumberString
import java.security.cert.X509Certificate; //导入方法依赖的package包/类
public String getSerialNumberString() {
X509Certificate cert = getCertificateList().get(0);
BigInteger sn = cert.getSerialNumber();
return byteArrayToColonSeparatedHexString(sn.toByteArray(), ":");
}
示例12: X509IssuerSerial
import java.security.cert.X509Certificate; //导入方法依赖的package包/类
/**
* Construct an X509IssuerSerial from an X509Certificate.
*/
X509IssuerSerial(X509Certificate cert) {
this(cert.getIssuerX500Principal(), cert.getSerialNumber());
}
示例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));
}
示例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));
}