@@ -85,8 +85,8 @@ class CertificateGenerator
8585 openssl_x509_export_to_file ($ this ->ca , $ file );
8686 }
8787
88- public function saveNewCertAsFileWithKey (
89- $ commonNameForCert , $ file , $ keyLength = null , $ subjectAltName = null
88+ public function saveNewCertAndKey (
89+ $ commonNameForCert , $ certFile , $ keyFile , $ keyLength = null , $ subjectAltName = null
9090 ) {
9191 $ dn = [
9292 'countryName ' => 'BY ' ,
@@ -117,7 +117,7 @@ $subjectAltNameConfig
117117basicConstraints = CA:FALSE
118118$ subjectAltNameConfig
119119CONFIG ;
120- $ configFile = $ file . '.cnf ' ;
120+ $ configFile = $ certFile . '.cnf ' ;
121121 file_put_contents ($ configFile , $ configCode );
122122
123123 try {
@@ -146,12 +146,24 @@ CONFIG;
146146 $ keyText = '' ;
147147 openssl_pkey_export ($ this ->lastKey , $ keyText , null , $ config );
148148
149- file_put_contents ($ file , $ certText . PHP_EOL . $ keyText );
149+ if ($ certFile === $ keyFile ) {
150+ file_put_contents ($ certFile , $ certText . PHP_EOL . $ keyText );
151+ } else {
152+ file_put_contents ($ certFile , $ certText );
153+ file_put_contents ($ keyFile , $ keyText );
154+ }
150155 } finally {
151156 unlink ($ configFile );
152157 }
153158 }
154159
160+
161+ public function saveNewCertAsFileWithKey (
162+ $ commonNameForCert , $ file , $ keyLength = null , $ subjectAltName = null
163+ ) {
164+ $ this ->saveNewCertAndKey ($ commonNameForCert , $ file , $ file , $ keyLength , $ subjectAltName );
165+ }
166+
155167 public function getCertDigest ($ algo )
156168 {
157169 return openssl_x509_fingerprint ($ this ->lastCert , $ algo );
0 commit comments