public void TestCreateKeyStore()
{
AsymmetricCipherKeyPair keyPair = KeyStoreUtil.GenerateKeyPair();
RsaPrivateCrtKeyParameters RSAprivKey = (RsaPrivateCrtKeyParameters)keyPair.Private;
RsaKeyParameters RSApubKey = (RsaKeyParameters)keyPair.Public;
Org.BouncyCastle.X509.X509Certificate cert = KeyStoreUtil.CreateCert("Test", RSApubKey, RSAprivKey);
Console.WriteLine(cert.ToString());
string pfxPath = TEST_PFX_PATH;
if (File.Exists(pfxPath))
{
pfxPath += "_old";
if (File.Exists(pfxPath))
{
File.Delete(pfxPath);
}
}
FileStream fs = new FileStream(pfxPath, FileMode.CreateNew);
KeyStoreUtil.WritePkcs12(RSAprivKey, cert, TEST_PFX_PASSWORD, fs);
fs.Close();
string crtPath = TEST_CRT_PATH;
if (File.Exists(crtPath))
{
crtPath += "_old";
if (File.Exists(crtPath))
{
File.Delete(crtPath);
}
}
FileStream certFileStream = new FileStream(crtPath, FileMode.CreateNew);
byte[] encodedCert = cert.GetEncoded();
certFileStream.Write(encodedCert, 0, encodedCert.Length);
certFileStream.Close();
}