/// <summary> /// Zertifikat mit privatem Schlüssel verknüpfen. (BouncyCastle-Teil) /// </summary> /// <param name="bcCert">Zertifikat</param> /// <param name="rsaKeyPair">Private Schlüssel</param> /// <param name="keyPwd">Passwort mit dem das Zertifikat verschlüsselt werden soll.</param> /// <returns></returns> private static byte[] LinkPrivateKeyToCert( Org.BouncyCastle.X509.X509Certificate bcCert, Org.BouncyCastle.Crypto.AsymmetricCipherKeyPair rsaKeyPair, System.Security.SecureString keyPwd) { var pkcs12store = new Org.BouncyCastle.Pkcs.Pkcs12StoreBuilder().Build(); pkcs12store.SetKeyEntry(string.Empty, new Org.BouncyCastle.Pkcs.AsymmetricKeyEntry(rsaKeyPair.Private), new[] { new Org.BouncyCastle.Pkcs.X509CertificateEntry(bcCert) }); var pkcs12data = new System.IO.MemoryStream(); pkcs12store.Save(pkcs12data, keyPwd.ToUnencryptedString().ToCharArray(), new Org.BouncyCastle.Security.SecureRandom(new CryptoApiRandomGenerator())); return(pkcs12data.ToArray()); }