|
@@ -17,6 +17,7 @@
|
|
|
|
|
|
package org.maxkey.crypto.cert;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.security.KeyPair;
|
|
|
import java.security.Security;
|
|
@@ -33,15 +34,20 @@ public class X509V3CertGenTest {
|
|
|
public void generateV3() throws Exception {
|
|
|
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
|
|
|
KeyPair keyPair =X509V3CertGen.genRSAKeyPair();
|
|
|
- String issuer="CN=connsec.com,O=connsec,L=SH,ST=SH,C=CN";
|
|
|
+ String issuer="CN=maxkey.top,O=maxkey,L=SH,ST=SH,C=CN";
|
|
|
Date startDate=DateTime.now().toDate();
|
|
|
Date endDate=DateTime.now().plusMonths(10).toDate();
|
|
|
System.out.println("Private : "+ keyPair.getPrivate().toString());
|
|
|
|
|
|
System.out.println("Public : "+ keyPair.getPublic().toString());
|
|
|
X509Certificate cert = X509V3CertGen.genV3Certificate(issuer,issuer,startDate,endDate,keyPair);
|
|
|
-
|
|
|
- FileOutputStream out = new FileOutputStream("c:\\Cert345.cer");
|
|
|
+ String certFileString = "D:\\MaxKey\\Workspaces\\maxkey\\Cert345.cer";
|
|
|
+ File certFile =new File(certFileString);
|
|
|
+ if(certFile.exists()) {
|
|
|
+ certFile.deleteOnExit();
|
|
|
+ }
|
|
|
+
|
|
|
+ FileOutputStream out = new FileOutputStream(certFileString);
|
|
|
out.write(cert.getEncoded());
|
|
|
out.close();
|
|
|
|