我正在尝试使用Java程序自动执行通过openSSL和命令提示符创建CSR的过程。我想输入一个字符串,如koo_AH,Kut_Po和uuu_Pl,并使用默认参数将它们转换为CSR。我能够创建密钥文件,但不能创建CSR,我认为这与openSSL将开始询问参数的事实有关。我在这做错了什么?下面是代码以及命令提示符的输入/输出,同时在非Java进程中手动使用它。
while (true) {
input[i] = inputScan.next();
if (input[i].length() < 5) {System.out.println("End of creation"); break;}
common = ("aaa."+ input[i].substring(4)+".aaa.com").toLowerCase();
pass = "aaa"+input[i].substring(4)+year;
rt = Runtime.getRuntime();
pr = rt.exec("cmd.exe");
pr = rt.exec("cmd /c cd "+directory1+" && " //change directory
+ "set OPENSSL_CONF=c:\\OpenSSL-Win32\\bin\\openssl.cfg && " //setup
+ "openssl genrsa -out "+directory2+input[i]+".key 2048 &&" //generate key
+ "openssl req -new -key "+directory2+input[i]+".key -out "+directory2+input[i]+".key.csr &&"
+ countryName + " &&"
+ state + " &&"
+ locality + " &&"
+ organization + " &&"
+ unit + " &&"
+ common + " &&"
+ email + " &&"
+ pass + " &&"
+ company);
i++;
}
C:\OpenSSL-Win32\bin>set OPENSSL_CONF=c:\OpenSSL-Win32\bin\openssl.cfg
C:\OpenSSL-Win32\bin>openssl genrsa -out C:\Keys\rkm_test.key 2048
Loading 'screen' into random state - done
Generating RSA private key, 2048 bit long modulus
........+++
...................+++
e is 65537 (0x10001)
C:\OpenSSL-Win32\bin>openssl req -new -key C:\Keys\rkm_test.key -out C:\keys\rkm
_test.key.csr
Loading 'screen' into random state - done
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:New York
Locality Name (eg, city) []:Yonk
Organization Name (eg, company) [Internet Widgits Pty Ltd]:AAA
Organizational Unit Name (eg, section) []:InfoSec
Common Name (e.g. server FQDN or YOUR name) []:aaa
Email Address []:gmail@gmail.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:aaa_123
An optional company name []:aaa
C:\OpenSSL-Win32\bin>