use of sun.security.x509.X500Name in project runwar by cfmlprojects.
the class SelfSignedCertificate method generateCertificate.
private static X509Certificate generateCertificate(String fqdn, KeyPair keypair, SecureRandom random) throws Exception {
final X500Name subject = new X500Name("CN=" + fqdn);
final SubjectPublicKeyInfo subPubKeyInfo = SubjectPublicKeyInfo.getInstance(keypair.getPublic().getEncoded());
final AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find("SHA1withRSA");
final AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);
final AsymmetricKeyParameter keyParam = PrivateKeyFactory.createKey(keypair.getPrivate().getEncoded());
final ContentSigner sigGen = new BcRSAContentSignerBuilder(sigAlgId, digAlgId).build(keyParam);
X509v3CertificateBuilder v3CertBuilder = new X509v3CertificateBuilder(subject, new BigInteger(64, random), NOT_BEFORE, NOT_AFTER, subject, subPubKeyInfo);
v3CertBuilder.addExtension(Extension.basicConstraints, true, new BasicConstraints(true));
v3CertBuilder.addExtension(Extension.keyUsage, true, new X509KeyUsage(X509KeyUsage.digitalSignature | X509KeyUsage.nonRepudiation | X509KeyUsage.keyEncipherment | X509KeyUsage.dataEncipherment));
v3CertBuilder.addExtension(Extension.subjectKeyIdentifier, false, createSubjectKeyIdentifier(keypair.getPublic()));
JcaX509CertificateConverter converter = new JcaX509CertificateConverter();
X509Certificate cert = converter.getCertificate(v3CertBuilder.build(sigGen));
cert.checkValidity();
cert.verify(keypair.getPublic());
return cert;
}
use of sun.security.x509.X500Name in project keystore-explorer by kaikramer.
the class DPreferences method storeDefaultDN.
private boolean storeDefaultDN() {
X500Name dn = distinguishedNameChooser.getDNWithEmptyRdns();
defaultDN = dn.toString();
return true;
}
use of sun.security.x509.X500Name in project keystore-explorer by kaikramer.
the class DViewCsr method main.
// for quick testing
public static void main(String[] args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", "BC");
KeyPair keyPair = keyGen.genKeyPair();
JcaPKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder(new X500Name("cn=test"), keyPair.getPublic());
PKCS10CertificationRequest csr = csrBuilder.build(new JcaContentSignerBuilder("SHA256withRSA").setProvider("BC").build(keyPair.getPrivate()));
DViewCsr dialog = new DViewCsr(new javax.swing.JFrame(), "Title", csr);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
use of sun.security.x509.X500Name in project keystore-explorer by kaikramer.
the class DViewPem method main.
// for quick testing
public static void main(String[] args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", "BC");
KeyPair keyPair = keyGen.genKeyPair();
JcaPKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder(new X500Name("cn=test"), keyPair.getPublic());
PKCS10CertificationRequest csr = csrBuilder.build(new JcaContentSignerBuilder("SHA256withRSA").setProvider("BC").build(keyPair.getPrivate()));
DViewPem dialog = new DViewPem(new javax.swing.JFrame(), "Title", csr);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
use of sun.security.x509.X500Name in project keystore-explorer by kaikramer.
the class DGenerateKeyPairCert method addExtensionsPressed.
private void addExtensionsPressed() {
PublicKey subjectPublicKey = keyPair.getPublic();
PublicKey caPublicKey = null;
X500Name caIssuerName = null;
BigInteger caSerialNumber = null;
if (issuerCert != null) {
caIssuerName = X500NameUtils.x500PrincipalToX500Name(issuerCert.getIssuerX500Principal());
caPublicKey = issuerCert.getPublicKey();
caSerialNumber = issuerCert.getSerialNumber();
} else {
// May be null
caIssuerName = jdnName.getDistinguishedName();
caPublicKey = keyPair.getPublic();
String serialNumberStr = jtfSerialNumber.getText().trim();
if (serialNumberStr.length() != 0) {
try {
caSerialNumber = new BigInteger(serialNumberStr);
} catch (NumberFormatException ex) {
// Don't set serial number
}
}
}
DAddExtensions dAddExtensions = new DAddExtensions(this, extensions, caPublicKey, caIssuerName, caSerialNumber, subjectPublicKey);
dAddExtensions.setLocationRelativeTo(this);
dAddExtensions.setVisible(true);
if (dAddExtensions.getExtensions() != null) {
extensions = dAddExtensions.getExtensions();
}
}
Aggregations