本文整理汇总了C#中Store.Open方法的典型用法代码示例。如果您正苦于以下问题:C# Store.Open方法的具体用法?C# Store.Open怎么用?C# Store.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Store
的用法示例。
在下文中一共展示了Store.Open方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSignatureKey
private static void GetSignatureKey(out RSACryptoServiceProvider rsa, out X509Certificate x509Cert)
{
rsa = null;
x509Cert = null;
try {
Store st = new Store();
st.Open(CAPICOM_STORE_LOCATION.CAPICOM_CURRENT_USER_STORE,
"MY", // Store Name
CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_MAXIMUM_ALLOWED);
Certificates selectedCerts = ((ICertificates2)st.Certificates).Select(
Messages.DemoTitle,
Messages.ChooseCertMessage,
false);
ICertificate2 selectedCert = ((ICertificate2)selectedCerts[1]);
if (selectedCert.HasPrivateKey() == false) {
MessageBox.Show(Messages.ChooseCertNoPrivateKey, Messages.ExceptionTitle, MessageBoxButtons.OK, MessageBoxIcon.Stop);
return;
}
// This only works with RSA keys
if (selectedCert.PublicKey().Algorithm.FriendlyName != "RSA") {
MessageBox.Show(Messages.ChooseCertKeyAlgorithm, Messages.ExceptionTitle, MessageBoxButtons.OK, MessageBoxIcon.Stop);
return;
}
// Construct the public key
CspParameters csp = new CspParameters();
csp.KeyContainerName = selectedCert.PrivateKey.ContainerName;
csp.ProviderName = selectedCert.PrivateKey.ProviderName;
csp.ProviderType = Convert.ToInt32(selectedCert.PrivateKey.ProviderType);
switch (selectedCert.PrivateKey.KeySpec) {
case CAPICOM_KEY_SPEC.CAPICOM_KEY_SPEC_KEYEXCHANGE:
csp.KeyNumber = 1;
break;
case CAPICOM_KEY_SPEC.CAPICOM_KEY_SPEC_SIGNATURE:
csp.KeyNumber = 2;
break;
}
if (selectedCert.PrivateKey.IsMachineKeyset())
csp.Flags = CspProviderFlags.UseMachineKeyStore;
rsa = new RSACryptoServiceProvider(csp);
x509Cert = GetX509Certificate(selectedCert);
} catch (Exception) {
MessageBox.Show(Messages.ChooseCertUnableToConstructKey, Messages.ExceptionTitle, MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
}
示例2: parseCommandLine
static bool parseCommandLine( String input)
{
ArrayList alArgs = ParseArgs(input);
Certificate oCert = null;
switch ((String)alArgs[0])
{
case "cd":
{
//This is the 'change directory' command
String storename;
if (alArgs.Count > 1)
{
storename = (String)alArgs[1];
}
else
{
storename = _currStoreName; //reset store name
}
if (storename.Equals("..") && _currStoreName.Length > 0 )
{
_oCurrStore = new StoreClass();
storename = null;
_currFilter = null;
_currStoreName = "";
}
else if (storename.StartsWith("..") && _currStoreName.Length > 0 )
{
_oCurrStore = new StoreClass();
_currFilter = null;
storename = storename.Substring(3,storename.Length - 3);
_currStoreName = "";
}
else if (storename.Equals(".."))
{
storename = null;
}
else if (storename.Equals("\\" + LocalMachine) || storename.Equals("\\lm" ))
{
_oCurrStore = new StoreClass();
_currStoreName = "";
storename = null;
_currStoreLocation = LocalMachine;
_currFilter = null;
}
else if (storename.Equals("\\" + CurrentUser) || storename.Equals("\\cu" ))
{
_oCurrStore = new StoreClass();
_currStoreName = "";
storename = null;
_currStoreLocation = CurrentUser;
_currFilter = null;
}
if (storename != null && _currStoreName.Equals(""))
{
try
{
CAPICOM_STORE_LOCATION OpenMode = CAPICOM_STORE_LOCATION.CAPICOM_CURRENT_USER_STORE;
if (_currStoreLocation.Equals(LocalMachine))
{
OpenMode = CAPICOM_STORE_LOCATION.CAPICOM_LOCAL_MACHINE_STORE;
}
//Open the store MAX_ALLOWED in case the user wants to import/rem/export
//They may not have permission to modify HKLM stores
_oCurrStore.Open( OpenMode,
storename,
CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_EXISTING_ONLY |
CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_MAXIMUM_ALLOWED);
_currStoreName = storename;
}
catch (Exception e)
{
Console.WriteLine (e.Message);
}
}
return false;
}
case "q":
case "quit":
{
return true;
}
case "h":
case "help":
{
DisplayHelp();
return false;
}
case "v":
case "view":
try
{
oCert = GetCertByIndex(Convert.ToInt32(alArgs[1]));
if (oCert != null )
{
//.........这里部分代码省略.........