ฉันใช้ Bouncy Castle เพื่อสร้างคีย์ส่วนตัว รวมถึง PKCS10 CSR ซึ่งฉันจะส่งไปยังเซิร์ฟเวอร์ระยะไกลเพื่อลงนาม ฉันได้รับใบรับรอง SSL ที่เข้ารหัส base64 มาตรฐานที่ลงนามแล้วกลับมาโดยตอบสนองเป็นสตริง คำถามคือ ฉันจะนำเข้าใบรับรองที่ลงนามจากสตริงได้อย่างไร แล้วบันทึกทั้งคีย์ส่วนตัวและใบรับรองที่ลงนามเป็นไฟล์ PKCS12 (.PFX)
นอกจากนี้ ฉันจะรวมใบรับรอง CA เพื่อรวมไว้ในไฟล์ PFX ได้อย่างไร
// Generate the private/public keypair
RsaKeyPairGenerator kpgen = new RsaKeyPairGenerator ();
CryptoApiRandomGenerator randomGenerator = new CryptoApiRandomGenerator ();
kpgen.Init (new KeyGenerationParameters (new SecureRandom (randomGenerator), 2048));
AsymmetricCipherKeyPair keyPair = kpgen.GenerateKeyPair ();
// Generate the CSR
X509Name subjectName = new X509Name ("CN=domain.com/name=Name");
Pkcs10CertificationRequest kpGen = new Pkcs10CertificationRequest ("SHA256withRSA", subjectName, keyPair.Public, null, keyPair.Private);
string certCsr = Convert.ToBase64String (kpGen.GetDerEncoded ());
// ** certCsr is now sent to be signed **
// ** let's assume that we get "certSigned" in response, and also have the CA **
string certSigned = "[standard signed certificate goes here]";
string certCA = "[standard CA certificate goes here]";
// Now how do I import certSigned and certCA
// Finally how do I export everything as a PFX file?