本文整理汇总了Java中org.bouncycastle.asn1.x500.style.RFC4519Style类的典型用法代码示例。如果您正苦于以下问题:Java RFC4519Style类的具体用法?Java RFC4519Style怎么用?Java RFC4519Style使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RFC4519Style类属于org.bouncycastle.asn1.x500.style包,在下文中一共展示了RFC4519Style类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkCRLsNotEmpty
import org.bouncycastle.asn1.x500.style.RFC4519Style; //导入依赖的package包/类
static void checkCRLsNotEmpty(Set crls, Object cert)
throws AnnotatedException
{
if (crls.isEmpty())
{
if (cert instanceof X509AttributeCertificate)
{
X509AttributeCertificate aCert = (X509AttributeCertificate)cert;
throw new AnnotatedException("No CRLs found for issuer \"" + aCert.getIssuer().getPrincipals()[0] + "\"");
}
else
{
X509Certificate xCert = (X509Certificate)cert;
throw new AnnotatedException("No CRLs found for issuer \"" + RFC4519Style.INSTANCE.toString(PrincipalUtils.getIssuerPrincipal(xCert)) + "\"");
}
}
}
示例2: getName
import org.bouncycastle.asn1.x500.style.RFC4519Style; //导入依赖的package包/类
public static String getName(ASN1ObjectIdentifier type) {
ParamUtil.requireNonNull("type", type);
String name = oidNameMap.get(type);
if (StringUtil.isBlank(name)) {
try {
name = RFC4519Style.INSTANCE.oidToDisplayName(type);
} catch (IllegalArgumentException ex) { // CHECKSTYLE:SKIP
}
}
return name;
}
示例3: nameToOid
import org.bouncycastle.asn1.x500.style.RFC4519Style; //导入依赖的package包/类
public static ASN1ObjectIdentifier nameToOid(String name) {
ParamUtil.requireNonNull("name", name);
for (ASN1ObjectIdentifier oid : oidNameMap.keySet()) {
if (oidNameMap.get(oid).equalsIgnoreCase(name)) {
return oid;
}
}
try {
return RFC4519Style.INSTANCE.attrNameToOID(name);
} catch (IllegalArgumentException ex) {
return null;
}
}
示例4: generateCert
import org.bouncycastle.asn1.x500.style.RFC4519Style; //导入依赖的package包/类
private X509CertificateObject generateCert(String keyName, KeyPair kp, boolean isCertAuthority,
PublicKey signerPublicKey, PrivateKey signerPrivateKey) throws IOException,
CertIOException, OperatorCreationException, CertificateException,
NoSuchAlgorithmException {
Calendar startDate = DateTimeUtils.calendar();
Calendar endDate = DateTimeUtils.calendar();
endDate.add(Calendar.YEAR, 100);
BigInteger serialNumber = BigInteger.valueOf(startDate.getTimeInMillis());
X500Name issuer = new X500Name(
IETFUtils.rDNsFromString("cn=localhost", RFC4519Style.INSTANCE));
JcaX509v3CertificateBuilder certGen = new JcaX509v3CertificateBuilder(issuer,
serialNumber, startDate.getTime(), endDate.getTime(), issuer, kp.getPublic());
JcaX509ExtensionUtils extensionUtils = new JcaX509ExtensionUtils();
certGen.addExtension(Extension.subjectKeyIdentifier, false,
extensionUtils.createSubjectKeyIdentifier(kp.getPublic()));
certGen.addExtension(Extension.basicConstraints, false,
new BasicConstraints(isCertAuthority));
certGen.addExtension(Extension.authorityKeyIdentifier, false,
extensionUtils.createAuthorityKeyIdentifier(signerPublicKey));
if (isCertAuthority) {
certGen.addExtension(Extension.keyUsage, true, new KeyUsage(KeyUsage.keyCertSign));
}
X509CertificateHolder cert = certGen.build(
new JcaContentSignerBuilder(SIGNING_ALGORITHM).build(signerPrivateKey));
return new X509CertificateObject(cert.toASN1Structure());
}
示例5: performTest
import org.bouncycastle.asn1.x500.style.RFC4519Style; //导入依赖的package包/类
public void performTest()
throws Exception
{
X500NameStyle style = RFC4519Style.INSTANCE;
for (int i = 0; i != attributeTypes.length; i++)
{
if (!attributeTypeOIDs[i].equals(style.attrNameToOID(attributeTypes[i])))
{
fail("mismatch for " + attributeTypes[i]);
}
}
byte[] enc = Hex.decode("305e310b300906035504061302415531283026060355040a0c1f546865204c6567696f6e206f662074686520426f756e637920436173746c653125301006035504070c094d656c626f75726e653011060355040b0c0a4173636f742056616c65");
X500Name n = X500Name.getInstance(style, X500Name.getInstance(enc));
if (!n.toString().equals("l=Melbourne+ou=Ascot Vale,o=The Legion of the Bouncy Castle,c=AU"))
{
fail("Failed composite to string test got: " + n.toString());
}
n = new X500Name(style, "l=Melbourne+ou=Ascot Vale,o=The Legion of the Bouncy Castle,c=AU");
if (!Arrays.areEqual(n.getEncoded(), enc))
{
fail("re-encoding test after parse failed");
}
}
示例6: createRootCert
import org.bouncycastle.asn1.x500.style.RFC4519Style; //导入依赖的package包/类
private static JcaX509v3CertificateBuilder createRootCert(KeyPair keypair) throws Exception {
X500NameBuilder ib = new X500NameBuilder(RFC4519Style.INSTANCE);
ib.addRDN(RFC4519Style.c, "AQ");
ib.addRDN(RFC4519Style.o, "Test");
ib.addRDN(RFC4519Style.l, "Vostok Station");
ib.addRDN(PKCSObjectIdentifiers.pkcs_9_at_emailAddress, "[email protected]");
X500Name issuer = ib.build();
return createCert(keypair, issuer, issuer);
}
示例7: createStdBuilder
import org.bouncycastle.asn1.x500.style.RFC4519Style; //导入依赖的package包/类
private X500NameBuilder createStdBuilder()
{
X500NameBuilder builder = new X500NameBuilder(RFC4519Style.INSTANCE);
builder.addRDN(RFC4519Style.c, "AU");
builder.addRDN(RFC4519Style.o, "The Legion of the Bouncy Castle");
builder.addRDN(RFC4519Style.l, "Melbourne");
builder.addRDN(RFC4519Style.st, "Victoria");
builder.addRDN(PKCSObjectIdentifiers.pkcs_9_at_emailAddress, "[email protected]");
return builder;
}
示例8: performTest
import org.bouncycastle.asn1.x500.style.RFC4519Style; //导入依赖的package包/类
public void performTest()
throws Exception
{
X500NameStyle style = RFC4519Style.INSTANCE;
for (int i = 0; i != attributeTypes.length; i++)
{
if (!attributeTypeOIDs[i].equals(style.attrNameToOID(attributeTypes[i])))
{
fail("mismatch for " + attributeTypes[i]);
}
}
byte[] enc = Hex.decode("305e310b300906035504061302415531283026060355040a0c1f546865204c6567696f6e206f662074686520426f756e637920436173746c653125301006035504070c094d656c626f75726e653011060355040b0c0a4173636f742056616c65");
X500Name n = new X500Name(style, X500Name.getInstance(enc));
if (!n.toString().equals("l=Melbourne+ou=Ascot Vale,o=The Legion of the Bouncy Castle,c=AU"))
{
fail("Failed composite to string test got: " + n.toString());
}
n = new X500Name(style, "l=Melbourne+ou=Ascot Vale,o=The Legion of the Bouncy Castle,c=AU");
if (!Arrays.areEqual(n.getEncoded(), enc))
{
fail("re-encoding test after parse failed");
}
}
示例9: getRfc4519Name
import org.bouncycastle.asn1.x500.style.RFC4519Style; //导入依赖的package包/类
public static String getRfc4519Name(X500Name name) {
ParamUtil.requireNonNull("name", name);
return RFC4519Style.INSTANCE.toString(name);
}
示例10: createKeystores
import org.bouncycastle.asn1.x500.style.RFC4519Style; //导入依赖的package包/类
private static void createKeystores() throws Exception {
// Create KeyPair
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
keyPairGenerator.initialize(1024, new SecureRandom());
KeyPair keyPair = keyPairGenerator.generateKeyPair();
Date currentDate = new Date();
Date expiryDate = new Date(currentDate.getTime() + 365L * 24L * 60L * 60L * 1000L);
// Create X509Certificate
String issuerName = "CN=Issuer";
String subjectName = "CN=Subject";
BigInteger serial = new BigInteger("123456");
X509v3CertificateBuilder certBuilder =
new X509v3CertificateBuilder(new X500Name(RFC4519Style.INSTANCE, issuerName), serial, currentDate,
expiryDate,
new X500Name(RFC4519Style.INSTANCE, subjectName),
SubjectPublicKeyInfo.getInstance(keyPair.getPublic().getEncoded()));
ContentSigner contentSigner = new JcaContentSignerBuilder("SHA256WithRSAEncryption").build(keyPair.getPrivate());
X509Certificate certificate = new JcaX509CertificateConverter().getCertificate(certBuilder.build(contentSigner));
// Store Private Key + Certificate in Keystore
KeyStore keystore = KeyStore.getInstance("JKS");
keystore.load(null, "security".toCharArray());
keystore.setKeyEntry("subject", keyPair.getPrivate(), "security".toCharArray(),
new Certificate[] { certificate });
File keystoreFile = File.createTempFile("samlkeystore", ".jks");
try (OutputStream output = Files.newOutputStream(keystoreFile.toPath())) {
keystore.store(output, "security".toCharArray());
}
keystorePath = keystoreFile.toPath();
// Now store the Certificate in the truststore
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, "security".toCharArray());
trustStore.setCertificateEntry("subject", certificate);
File truststoreFile = File.createTempFile("samltruststore", ".jks");
try (OutputStream output = Files.newOutputStream(truststoreFile.toPath())) {
trustStore.store(output, "security".toCharArray());
}
truststorePath = truststoreFile.toPath();
}
示例11: generationTest
import org.bouncycastle.asn1.x500.style.RFC4519Style; //导入依赖的package包/类
private void generationTest(int keySize, String keyName, String sigName)
throws Exception
{
AsymmetricCipherKeyPairGenerator kpg = new RSAKeyPairGenerator();
RSAKeyGenerationParameters genParam = new RSAKeyGenerationParameters(
BigInteger.valueOf(0x1001), new SecureRandom(), keySize, 25);
kpg.init(genParam);
AsymmetricCipherKeyPair kp = kpg.generateKeyPair();
X500NameBuilder x500NameBld = new X500NameBuilder(RFC4519Style.INSTANCE);
x500NameBld.addRDN(RFC4519Style.c, "AU");
x500NameBld.addRDN(RFC4519Style.o, "The Legion of the Bouncy Castle");
x500NameBld.addRDN(RFC4519Style.l, "Melbourne");
x500NameBld.addRDN(RFC4519Style.st, "Victoria");
x500NameBld.addRDN(PKCSObjectIdentifiers.pkcs_9_at_emailAddress, "[email protected]");
X500Name subject = x500NameBld.build();
PKCS10CertificationRequestBuilder requestBuilder = new BcPKCS10CertificationRequestBuilder(subject, kp.getPublic());
DefaultSignatureAlgorithmIdentifierFinder sigAlgFinder = new DefaultSignatureAlgorithmIdentifierFinder();
DefaultDigestAlgorithmIdentifierFinder digAlgFinder = new DefaultDigestAlgorithmIdentifierFinder();
AlgorithmIdentifier sigAlgId = sigAlgFinder.find("SHA1withRSA");
AlgorithmIdentifier digAlgId = digAlgFinder.find(sigAlgId);
BcContentSignerBuilder contentSignerBuilder = new BcRSAContentSignerBuilder(sigAlgId, digAlgId);
PKCS10CertificationRequest req1 = requestBuilder.build(contentSignerBuilder.build(kp.getPrivate()));
BcPKCS10CertificationRequest req2 = new BcPKCS10CertificationRequest(req1.getEncoded());
if (!req2.isSignatureValid(new BcRSAContentVerifierProviderBuilder(digAlgFinder).build(kp.getPublic())))
{
fail(sigName + ": Failed verify check.");
}
if (!Arrays.areEqual(req2.getSubjectPublicKeyInfo().getEncoded(), req1.getSubjectPublicKeyInfo().getEncoded()))
{
fail(keyName + ": Failed public key check.");
}
}
示例12: getAlternativeNames
import org.bouncycastle.asn1.x500.style.RFC4519Style; //导入依赖的package包/类
private static Collection getAlternativeNames(byte[] extVal)
throws CertificateParsingException
{
if (extVal == null)
{
return null;
}
try
{
Collection temp = new ArrayList();
Enumeration it = ASN1Sequence.getInstance(extVal).getObjects();
while (it.hasMoreElements())
{
GeneralName genName = GeneralName.getInstance(it.nextElement());
List list = new ArrayList();
list.add(Integers.valueOf(genName.getTagNo()));
switch (genName.getTagNo())
{
case GeneralName.ediPartyName:
case GeneralName.x400Address:
case GeneralName.otherName:
list.add(genName.getEncoded());
break;
case GeneralName.directoryName:
list.add(X500Name.getInstance(RFC4519Style.INSTANCE, genName.getName()).toString());
break;
case GeneralName.dNSName:
case GeneralName.rfc822Name:
case GeneralName.uniformResourceIdentifier:
list.add(((ASN1String)genName.getName()).getString());
break;
case GeneralName.registeredID:
list.add(ASN1ObjectIdentifier.getInstance(genName.getName()).getId());
break;
case GeneralName.iPAddress:
byte[] addrBytes = DEROctetString.getInstance(genName.getName()).getOctets();
list.add(addrBytes);
break;
default:
throw new IOException("Bad tag number: " + genName.getTagNo());
}
temp.add(list);
}
if (temp.size() == 0)
{
return null;
}
return Collections.unmodifiableCollection(temp);
}
catch (Exception e)
{
throw new CertificateParsingException(e.getMessage());
}
}