本文整理汇总了Java中org.bouncycastle.asn1.x509.X509Name类的典型用法代码示例。如果您正苦于以下问题:Java X509Name类的具体用法?Java X509Name怎么用?Java X509Name使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
X509Name类属于org.bouncycastle.asn1.x509包,在下文中一共展示了X509Name类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIssuerX509Principal
import org.bouncycastle.asn1.x509.X509Name; //导入依赖的package包/类
/**
* return the issuer of the given cert as an X509PrincipalObject.
*/
public static X509Principal getIssuerX509Principal(
X509Certificate cert)
throws CertificateEncodingException
{
try
{
TBSCertificateStructure tbsCert = TBSCertificateStructure.getInstance(
ASN1Primitive.fromByteArray(cert.getTBSCertificate()));
return new X509Principal(X509Name.getInstance(tbsCert.getIssuer()));
}
catch (IOException e)
{
throw new CertificateEncodingException(e.toString());
}
}
示例2: makeCertificate
import org.bouncycastle.asn1.x509.X509Name; //导入依赖的package包/类
public static X509Certificate makeCertificate(KeyPair _subKP,
String _subDN, KeyPair _issKP, String _issDN, String algorithm, boolean _ca)
throws Exception
{
PublicKey _subPub = _subKP.getPublic();
PrivateKey _issPriv = _issKP.getPrivate();
PublicKey _issPub = _issKP.getPublic();
X509V3CertificateGenerator _v3CertGen = new X509V3CertificateGenerator();
_v3CertGen.reset();
_v3CertGen.setSerialNumber(allocateSerialNumber());
_v3CertGen.setIssuerDN(new X509Name(_issDN));
_v3CertGen.setNotBefore(new Date(System.currentTimeMillis()));
_v3CertGen.setNotAfter(new Date(System.currentTimeMillis()
+ (1000L * 60 * 60 * 24 * 100)));
_v3CertGen.setSubjectDN(new X509Name(_subDN));
_v3CertGen.setPublicKey(_subPub);
_v3CertGen.setSignatureAlgorithm(algorithm);
_v3CertGen.addExtension(X509Extensions.SubjectKeyIdentifier, false,
createSubjectKeyId(_subPub));
_v3CertGen.addExtension(X509Extensions.AuthorityKeyIdentifier, false,
createAuthorityKeyId(_issPub));
_v3CertGen.addExtension(X509Extensions.BasicConstraints, false,
new BasicConstraints(_ca));
X509Certificate _cert = _v3CertGen.generate(_issPriv);
_cert.checkValidity(new Date());
_cert.verify(_issPub);
return _cert;
}
示例3: getSubjectX509Principal
import org.bouncycastle.asn1.x509.X509Name; //导入依赖的package包/类
/**
* return the subject of the given cert as an X509PrincipalObject.
*/
public static X509Principal getSubjectX509Principal(
X509Certificate cert)
throws CertificateEncodingException
{
try
{
TBSCertificateStructure tbsCert = TBSCertificateStructure.getInstance(
ASN1Primitive.fromByteArray(cert.getTBSCertificate()));
return new X509Principal(X509Name.getInstance(tbsCert.getSubject()));
}
catch (IOException e)
{
throw new CertificateEncodingException(e.toString());
}
}
示例4: CertificationRequestInfo
import org.bouncycastle.asn1.x509.X509Name; //导入依赖的package包/类
public CertificationRequestInfo(
ASN1Sequence seq)
{
version = (DERInteger)seq.getObjectAt(0);
subject = X509Name.getInstance(seq.getObjectAt(1));
subjectPKInfo = SubjectPublicKeyInfo.getInstance(seq.getObjectAt(2));
//
// some CertificationRequestInfo objects seem to treat this field
// as optional.
//
if (seq.size() > 3)
{
DERTaggedObject tagobj = (DERTaggedObject)seq.getObjectAt(3);
attributes = ASN1Set.getInstance(tagobj, false);
}
if ((subject == null) || (version == null) || (subjectPKInfo == null))
{
throw new IllegalArgumentException("Not all mandatory fields set in CertificationRequestInfo generator.");
}
}
示例5: equalityTest
import org.bouncycastle.asn1.x509.X509Name; //导入依赖的package包/类
private void equalityTest(X509Name x509Name, X509Name x509Name1)
{
if (!x509Name.equals(x509Name1))
{
fail("equality test failed for " + x509Name + " : " + x509Name1);
}
if (x509Name.hashCode() != x509Name1.hashCode())
{
fail("hashCodeTest test failed for " + x509Name + " : " + x509Name1);
}
if (!x509Name.equals(x509Name1, true))
{
fail("equality test failed for " + x509Name + " : " + x509Name1);
}
}
示例6: addEntry
import org.bouncycastle.asn1.x509.X509Name; //导入依赖的package包/类
private void addEntry(final String alias) throws GeneralSecurityException {
final KeyPair pair = KG.generateKeyPair();
// build a certificate generator
final X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
final X500Principal dnName = new X500Principal("cn=" + alias);
certGen.setSerialNumber(new BigInteger(256, RND));
certGen.setSubjectDN(new X509Name("dc=" + alias));
certGen.setIssuerDN(dnName); // use the same
certGen.setNotBefore(new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000));
certGen.setNotAfter(new Date(System.currentTimeMillis() + 2 * 365 * 24 * 60 * 60 * 1000));
certGen.setPublicKey(pair.getPublic());
certGen.setSignatureAlgorithm("SHA256WithRSA");
final X509Certificate cert = certGen.generate(pair.getPrivate(), "BC");
ks.setEntry(alias, new KeyStore.PrivateKeyEntry(pair.getPrivate(), new X509Certificate[] { cert }), PP);
}
示例7: addPublicEntry
import org.bouncycastle.asn1.x509.X509Name; //导入依赖的package包/类
private void addPublicEntry(final String alias) throws GeneralSecurityException {
final KeyPair pair = KG.generateKeyPair();
// build a certificate generator
final X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
final X500Principal dnName = new X500Principal("cn=" + alias);
certGen.setSerialNumber(new BigInteger(256, RND));
certGen.setSubjectDN(new X509Name("dc=" + alias));
certGen.setIssuerDN(dnName); // use the same
certGen.setNotBefore(new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000));
certGen.setNotAfter(new Date(System.currentTimeMillis() + 2 * 365 * 24 * 60 * 60 * 1000));
certGen.setPublicKey(pair.getPublic());
certGen.setSignatureAlgorithm("SHA256WithRSA");
final X509Certificate cert = certGen.generate(pair.getPrivate(), "BC");
ks.setEntry(alias, new KeyStore.TrustedCertificateEntry(cert), null);
}
示例8: makePTLSX509Name
import org.bouncycastle.asn1.x509.X509Name; //导入依赖的package包/类
private static X509Name makePTLSX509Name(String subject) throws Exception
{
Vector tdn = new Vector();
Vector elems = new Vector();
StringTokenizer st = new StringTokenizer(subject,",");
for (; st.hasMoreTokens() ;) {
String s = st.nextToken(); // [key=value]
if ( s.indexOf("=") == -1 )
throw new Exception("Invalid subject format: " + subject + " Offending value: " + s);
String key = s.substring(0, s.indexOf("=")).trim();
String val = s.substring(s.indexOf("=") + 1).trim();
if ( val == null || val.equals(""))
throw new Exception("Invalid subject format: " + subject + " Offending value: " + s);
//logger.debug(key + "=" + val);
String[] temp = {key, val};
tdn.addElement(temp);
}
// COM.claymoresystems.cert (puretls.jar)
return CertRequest.makeSimpleDN(tdn);
}
示例9: getAuthorityKeyIdentifier
import org.bouncycastle.asn1.x509.X509Name; //导入依赖的package包/类
/**
* Returns the <code>AuthorityKeyIdentifier</code> corresponding
* to a given <code>PublicKey</code>
* @param publicKey the given public key
* @param issuer the certificate issuer
* @param serial the certificate serial number
* @return the authority key identifier of the public key
* @throws IOException
*/
private AuthorityKeyIdentifier getAuthorityKeyIdentifier(PublicKey publicKey,
String issuer,
BigInteger serial)
throws IOException
{
InputStream input;
SubjectPublicKeyInfo keyInfo;
ASN1EncodableVector vector;
input = new ByteArrayInputStream(publicKey.getEncoded());
keyInfo = new SubjectPublicKeyInfo((ASN1Sequence)new ASN1InputStream(input).readObject());
vector = new ASN1EncodableVector();
vector.add(new GeneralName(new X509Name(issuer)));
return new AuthorityKeyIdentifier(keyInfo, new GeneralNames(new DERSequence(vector)), serial);
}
示例10: responderIDtoString
import org.bouncycastle.asn1.x509.X509Name; //导入依赖的package包/类
/**
* Get String represetation of ResponderID
* @param basResp
* @return stringified responder ID
*/
private String responderIDtoString(BasicOCSPResp basResp) {
if(basResp != null) {
ResponderID respid = basResp.getResponseData().getResponderId().toASN1Object();
Object o = ((DERTaggedObject)respid.toASN1Object()).getObject();
if(o instanceof org.bouncycastle.asn1.DEROctetString) {
org.bouncycastle.asn1.DEROctetString oc = (org.bouncycastle.asn1.DEROctetString)o;
return "byKey: " + SignedDoc.bin2hex(oc.getOctets());
} else {
X509Name name = new X509Name((ASN1Sequence)o);
return "byName: " + name.toString();
}
}
else
return null;
}
示例11: createAndStoreCA
import org.bouncycastle.asn1.x509.X509Name; //导入依赖的package包/类
private void createAndStoreCA(CertificateAuthority ca) throws Exception {
KeyPair rootPair = KeyUtil.generateRSAKeyPair1024(ca.getCACredentialsProvider());
assertNotNull(rootPair);
String rootSub = SUBJECT_PREFIX + "Temp Certificate Authority";
X509Name rootSubject = new X509Name(rootSub);
GregorianCalendar cal = new GregorianCalendar();
Date start = cal.getTime();
cal.add(Calendar.YEAR, 1);
Date end = cal.getTime();
X509Certificate root = CertUtil.generateCACertificate(ca.getCACredentialsProvider(), rootSubject, start, end, rootPair, CertUtil.SHA2_SIGNATURE_ALGORITHM);
assertNotNull(root);
ca.setCACredentials(root, rootPair.getPrivate(), null);
X509Certificate r = ca.getCACertificate();
assertNotNull(r);
assertEquals(r, root);
}
示例12: renewCertifcateAuthorityCredentials
import org.bouncycastle.asn1.x509.X509Name; //导入依赖的package包/类
public synchronized X509Certificate renewCertifcateAuthorityCredentials(Date expirationDate)
throws CertificateAuthorityFault, NoCACredentialsFault {
init();
try {
X509Certificate oldcert = getCACertificate(false);
int size = ((RSAPublicKey) oldcert.getPublicKey()).getModulus().bitLength();
KeyPair pair = KeyUtil.generateRSAKeyPair(getCACredentialsProvider(), size);
X509Certificate cacert = CertUtil.generateCACertificate(getCACredentialsProvider(), new X509Name(oldcert
.getSubjectDN().getName()), new Date(), expirationDate, pair, getSignatureAlgorithm());
deleteCACredentials();
this.setCACredentials(cacert, pair.getPrivate(), properties.getCertificateAuthorityPassword());
return cacert;
} catch (Exception e) {
logError(e.getMessage(), e);
CertificateAuthorityFault fault = new CertificateAuthorityFault();
fault.setFaultString("Unexpected Error, could renew the CA credentials.");
FaultHelper helper = new FaultHelper(fault);
helper.addFaultCause(e);
fault = (CertificateAuthorityFault) helper.getFault();
throw fault;
}
}
示例13: generateCACertificate
import org.bouncycastle.asn1.x509.X509Name; //导入依赖的package包/类
public static X509Certificate generateCACertificate(String provider, X509Name subject, Date start, Date expired, KeyPair pair, int numberOfCAs, String signatureAlgorthm)
throws CertificateEncodingException, IllegalStateException, NoSuchProviderException, NoSuchAlgorithmException, SignatureException, InvalidKeyException, IOException {
// generate the certificate
X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
certGen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis()));
certGen.setIssuerDN(subject);
certGen.setNotBefore(start);
certGen.setNotAfter(expired);
certGen.setSubjectDN(subject);
certGen.setPublicKey(pair.getPublic());
certGen.setSignatureAlgorithm(signatureAlgorthm);
certGen.addExtension(X509Extensions.BasicConstraints, true, new BasicConstraints(numberOfCAs));
certGen.addExtension(X509Extensions.KeyUsage, true, new KeyUsage(KeyUsage.digitalSignature | KeyUsage.keyCertSign | KeyUsage.cRLSign));
SubjectPublicKeyInfo spki = new SubjectPublicKeyInfo((ASN1Sequence) new ASN1InputStream(new ByteArrayInputStream(pair.getPublic().getEncoded())).readObject());
certGen.addExtension(X509Extensions.SubjectKeyIdentifier, false, new SubjectKeyIdentifier(spki));
SubjectPublicKeyInfo apki = new SubjectPublicKeyInfo((ASN1Sequence) new ASN1InputStream(new ByteArrayInputStream(pair.getPublic().getEncoded())).readObject());
certGen.addExtension(X509Extensions.AuthorityKeyIdentifier, false, new AuthorityKeyIdentifier(apki));
return certGen.generate(pair.getPrivate(), provider);
}
示例14: createAndStoreCAShort
import org.bouncycastle.asn1.x509.X509Name; //导入依赖的package包/类
private X509Certificate createAndStoreCAShort(CertificateAuthority ca, int seconds) throws Exception {
KeyPair rootPair = KeyUtil.generateRSAKeyPair2048(ca.getCACredentialsProvider());
assertNotNull(rootPair);
String rootSub = SUBJECT_PREFIX + "Temp Certificate Authority";
X509Name rootSubject = new X509Name(rootSub);
GregorianCalendar cal = new GregorianCalendar();
Date start = cal.getTime();
cal.add(Calendar.SECOND, (seconds / 1000));
Date end = cal.getTime();
X509Certificate root = CertUtil.generateCACertificate(ca.getCACredentialsProvider(), rootSubject, start, end,
rootPair, ca.getSignatureAlgorithm());
assertNotNull(root);
ca.setCACredentials(root, rootPair.getPrivate(), null);
X509Certificate r = ca.getCACertificate();
assertNotNull(r);
if (!r.equals(root)) {
throw new Exception("The CA certificate obtained was not expected");
}
return r;
}
示例15: getComponent
import org.bouncycastle.asn1.x509.X509Name; //导入依赖的package包/类
private static String getComponent() {
String component = null;
while (true) {
component = Util.getInput("Enter name component: ");
if (component == null || component.trim().length() == 0) {
return null;
}
component = component.trim();
if (X509Name.DefaultLookUp.get(component.toLowerCase()) == null) {
System.out.println("Invalid component name");
} else {
break;
}
}
component = component.toUpperCase();
String value = Util.getInput("Enter '" + component + "' value: ");
if (value == null || value.trim().length() == 0) {
return null;
}
return component + "=" + value.trim();
}