使用keytool实用程序创建自签名的Java密钥库和证书文件。 能够通过使用mmc.exe命令转到证书控制台,将证书添加到Windows信任存储区。
但是无论如何都要以编程方式将证书添加到Windows信任存储中。并且MAC系统也需要相同的东西。
感谢任何建议。
答案 0 :(得分:4)
以下是Windows / MAC的代码片段,用于在信任库中添加证书。
窗口:
recorder = new AudioRecord(
MediaRecorder.AudioSource.MIC,
RECORDER_SAMPLERATE,
RECORDER_CHANNELS,
RECORDER_AUDIO_ENCODING,
bufferSize);
recorder.startRecording();
isRecording = true;
FileOutputStream os = null;
try {
os = new FileOutputStream(filePathAudioRec);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
while (isRecording) {
// gets the voice output from microphone to byte format
recorder.read(sData, 0, BufferElements2Rec);
try {
// writes the data to file from buffer
// stores the voice buffer
byte bData[] = short2byte(sData);
os.write(bData, 0, BufferElements2Rec * BytesPerElement); //do I need to write it to a file ??
} catch (IOException e) {
e.printStackTrace();
}
// inside while loop: add code to convert to .mp4 while the data is collected from the MIC
}
在Windows中,它成功地在信任库中添加证书,但由于没有管理员权限,某些系统无法运行。因此,如果以管理员身份登录或为用户授予一些管理员权限,那么在这些计算机中它将起作用。
MAC:
KeyStore root = KeyStore.getInstance("Windows-ROOT","SunMSCAPI");
root.load(null,null);
/* certificate must be DER-encoded */
FileInputStream in = new FileInputStream("yourcertificate.cer");
X509Certificate cacert = (X509Certificate)CertificateFactory.getInstance("X.509").generateCertificate(in);
root.setCertificateEntry("certificatealiasname", cacert);
能够在钥匙串中成功添加证书,但不能信任证书。因此需要转到KeyChain Access并手动信任证书。