本文整理汇总了C#中CspProviderFlags类的典型用法代码示例。如果您正苦于以下问题:C# CspProviderFlags类的具体用法?C# CspProviderFlags怎么用?C# CspProviderFlags使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CspProviderFlags类属于命名空间,在下文中一共展示了CspProviderFlags类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CspParameters
internal CspParameters(int providerType, string providerName, string keyContainerName, CspProviderFlags flags)
{
this.ProviderType = providerType;
this.ProviderName = providerName;
this.KeyContainerName = keyContainerName;
this.KeyNumber = -1;
this.Flags = flags;
}
示例2: CspParameters
private CspParameters(int providerType, string providerName, string keyContainerName, CspProviderFlags flags)
{
ProviderType = providerType;
ProviderName = providerName;
KeyContainerName = keyContainerName;
KeyNumber = -1;
Flags = flags;
}
示例3: KeyContainerStore
public KeyContainerStore(string storeType)
{
flags = "machine".Equals(storeType)
? CspProviderFlags.UseMachineKeyStore
: CspProviderFlags.UseUserProtectedKey;
Log.Verbose($"using key container, flags: {flags}");
}
示例4: GetKey
extern public static byte[] GetKey(int algorithm, String name,
CspProviderFlags flag,
out int result);
示例5: ValidateCspFlags
/// <summary>
/// Validates the CSP flags are expected
/// </summary>
/// <param name="flags">CSP provider flags</param>
private static void ValidateCspFlags(CspProviderFlags flags)
{
// check that the flags are consistent.
if (IsFlagBitSet((uint)flags, (uint)CspProviderFlags.UseExistingKey))
{
CspProviderFlags keyFlags = (CspProviderFlags.UseNonExportableKey |
CspProviderFlags.UseArchivableKey |
CspProviderFlags.UseUserProtectedKey);
if ((flags & keyFlags) != CspProviderFlags.NoFlags)
{
throw new ArgumentException(SR.Format(SR.Argument_InvalidValue, Convert.ToString(flags)));
}
}
}
示例6: SaveCspParameters
internal static CspParameters SaveCspParameters (CspAlgorithmType keyType, CspParameters userParameters, CspProviderFlags defaultFlags, ref bool randomKeyContainer) {
CspParameters parameters;
if (userParameters == null) {
parameters = new CspParameters(keyType == CspAlgorithmType.Dss ? Constants.PROV_DSS_DH : DefaultRsaProviderType, null, null, defaultFlags);
} else {
ValidateCspFlags(userParameters.Flags);
parameters = new CspParameters(userParameters);
}
if (parameters.KeyNumber == -1)
parameters.KeyNumber = keyType == CspAlgorithmType.Dss ? Constants.AT_SIGNATURE : Constants.AT_KEYEXCHANGE;
else if (parameters.KeyNumber == Constants.CALG_DSS_SIGN || parameters.KeyNumber == Constants.CALG_RSA_SIGN)
parameters.KeyNumber = Constants.AT_SIGNATURE;
else if (parameters.KeyNumber == Constants.CALG_RSA_KEYX)
parameters.KeyNumber = Constants.AT_KEYEXCHANGE;
// If no key container was specified and UseDefaultKeyContainer is not used, then use CRYPT_VERIFYCONTEXT
// to generate an ephemeral key
randomKeyContainer = (parameters.Flags & CspProviderFlags.CreateEphemeralKey) == CspProviderFlags.CreateEphemeralKey;
if (parameters.KeyContainerName == null && (parameters.Flags & CspProviderFlags.UseDefaultKeyContainer) == 0) {
parameters.Flags |= CspProviderFlags.CreateEphemeralKey;
randomKeyContainer = true;
}
return parameters;
}
示例7: ValidateCspFlags
[System.Security.SecurityCritical] // auto-generated
private static void ValidateCspFlags (CspProviderFlags flags) {
// check that the flags are consistent.
if ((flags & CspProviderFlags.UseExistingKey) != 0) {
CspProviderFlags keyFlags = (CspProviderFlags.UseNonExportableKey | CspProviderFlags.UseArchivableKey | CspProviderFlags.UseUserProtectedKey);
if ((flags & keyFlags) != CspProviderFlags.NoFlags)
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"));
}
// make sure we are allowed to display the key protection UI if a user protected key is requested.
if ((flags & CspProviderFlags.UseUserProtectedKey) != 0) {
// UI only allowed in interactive session.
if (!System.Environment.UserInteractive)
throw new InvalidOperationException(Environment.GetResourceString("Cryptography_NotInteractive"));
// we need to demand UI permission here.
UIPermission uiPermission = new UIPermission(UIPermissionWindow.SafeTopLevelWindows);
uiPermission.Demand();
}
}
示例8: _ImportCspBlob
internal static extern int _ImportCspBlob(byte[] keyBlob, SafeProvHandle hProv, CspProviderFlags flags, ref SafeKeyHandle hKey);
示例9: _ImportKey
internal static extern void _ImportKey(SafeProvHandle hCSP, int keyNumber, CspProviderFlags flags, object cspObject, ref SafeKeyHandle hKey);
示例10: ImportKeyBlob
/// <summary>
/// Helper for Import CSP
/// </summary>
internal static void ImportKeyBlob(SafeProvHandle saveProvHandle, CspProviderFlags flags, byte[] keyBlob, out SafeKeyHandle safeKeyHandle)
{
// Compat note: This isn't the same check as the one done by the CLR _ImportCspBlob QCall,
// but this does match the desktop CLR behavior and the only scenarios it
// affects are cases where a corrupt blob is passed in.
bool isPublic = keyBlob.Length > 0 && keyBlob[0] == CapiHelper.PUBLICKEYBLOB;
int dwCapiFlags = MapCspKeyFlags((int)flags);
if (isPublic)
{
dwCapiFlags &= ~(int)(CryptGenKeyFlags.CRYPT_EXPORTABLE);
}
SafeKeyHandle hKey;
if (!Interop.CryptImportKey(saveProvHandle, keyBlob, keyBlob.Length, SafeKeyHandle.InvalidHandle, dwCapiFlags, out hKey))
{
int hr = Marshal.GetHRForLastWin32Error();
hKey.Dispose();
throw hr.ToCryptographicException();
}
hKey.PublicOnly = isPublic;
safeKeyHandle = hKey;
return;
}
示例11: ValidateCspFlags
private static void ValidateCspFlags(CspProviderFlags flags)
{
if ((flags & CspProviderFlags.UseExistingKey) != CspProviderFlags.NoFlags)
{
CspProviderFlags flags2 = CspProviderFlags.UseUserProtectedKey | CspProviderFlags.UseArchivableKey | CspProviderFlags.UseNonExportableKey;
if ((flags & flags2) != CspProviderFlags.NoFlags)
{
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"));
}
}
if ((flags & CspProviderFlags.UseUserProtectedKey) != CspProviderFlags.NoFlags)
{
if (!Environment.UserInteractive)
{
throw new InvalidOperationException(Environment.GetResourceString("Cryptography_NotInteractive"));
}
new UIPermission(UIPermissionWindow.SafeTopLevelWindows).Demand();
}
}
示例12: SaveCspParameters
/// <summary>
/// Helper method to save the CSP parameters.
/// </summary>
/// <param name="keyType">CSP algorithm type</param>
/// <param name="userParameters">CSP Parameters passed by user</param>
/// <param name="defaultFlags">flags </param>
/// <param name="randomKeyContainer">identifies if it is random key container</param>
/// <returns></returns>
internal static CspParameters SaveCspParameters(
CspAlgorithmType keyType,
CspParameters userParameters,
CspProviderFlags defaultFlags,
out bool randomKeyContainer)
{
CspParameters parameters;
if (userParameters == null)
{
parameters = new CspParameters(keyType == CspAlgorithmType.Dss ?
(int)ProviderType.PROV_DSS_DH : DefaultRsaProviderType,
null, null, defaultFlags);
}
else
{
ValidateCspFlags(userParameters.Flags);
parameters = new CspParameters(userParameters);
}
if (parameters.KeyNumber == -1)
{
parameters.KeyNumber = keyType == CapiHelper.CspAlgorithmType.Dss ? (int)KeyNumber.Signature : (int)KeyNumber.Exchange;
}
else if (parameters.KeyNumber == CALG_DSS_SIGN || parameters.KeyNumber == CALG_RSA_SIGN)
{
parameters.KeyNumber = (int)KeyNumber.Signature;
}
else if (parameters.KeyNumber == CALG_RSA_KEYX)
{
parameters.KeyNumber = (int)KeyNumber.Exchange;
}
// If no key container was specified and UseDefaultKeyContainer is not used, then use CRYPT_VERIFYCONTEXT
// to generate an ephemeral key
randomKeyContainer = IsFlagBitSet((uint)parameters.Flags, (uint)CspProviderFlags.CreateEphemeralKey);
if (parameters.KeyContainerName == null && !IsFlagBitSet((uint)parameters.Flags,
(uint)CspProviderFlags.UseDefaultKeyContainer))
{
parameters.Flags |= CspProviderFlags.CreateEphemeralKey;
randomKeyContainer = true;
}
return parameters;
}
示例13: CreateProviderParameters
private static CspParameters CreateProviderParameters(CspParameters providerParameters, CspProviderFlags defaultFlags, out bool randomKeyContainer)
{
CspParameters parameters;
if (providerParameters == null)
{
parameters = new CspParameters(GostCryptoConfig.ProviderType) { Flags = defaultFlags };
}
else
{
ValidateProviderParameters(providerParameters.Flags);
parameters = new CspParameters(providerParameters.ProviderType, providerParameters.ProviderName, providerParameters.KeyContainerName) { Flags = providerParameters.Flags, KeyNumber = providerParameters.KeyNumber };
}
// Установка типа ключа
if (parameters.KeyNumber == -1)
{
parameters.KeyNumber = (int)KeyNumber.Exchange;
}
else if (parameters.KeyNumber == Constants.CALG_GR3410EL)
{
parameters.KeyNumber = (int)KeyNumber.Signature;
}
else if (parameters.KeyNumber == Constants.CALG_DH_EL_SF)
{
parameters.KeyNumber = (int)KeyNumber.Exchange;
}
// Использовать автогенерированный контейнер
randomKeyContainer = ((parameters.KeyContainerName == null) && ((parameters.Flags & CspProviderFlags.UseDefaultKeyContainer) == CspProviderFlags.NoFlags));
if (randomKeyContainer)
{
parameters.KeyContainerName = Guid.NewGuid().ToString();
}
return parameters;
}
示例14: WriteToStore
/// <summary>
/// Writes a copy of this key into the local Csp store with the given options
/// </summary>
public void WriteToStore(string name, CspProviderFlags flags)
{
CspParameters cp = new CspParameters();
cp.KeyContainerName = name;
cp.Flags = flags;
RSACryptoServiceProvider csp = new RSACryptoServiceProvider(cp);
csp.ImportCspBlob(RSAKey.ExportCspBlob(IsPrivateKey));
csp.PersistKeyInCsp = true;
csp.Clear();
}
示例15: ValidateProviderParameters
private static void ValidateProviderParameters(CspProviderFlags flags)
{
// Ели информацию о провайдере нужно взять из текущего ключа
if ((flags & CspProviderFlags.UseExistingKey) != CspProviderFlags.NoFlags)
{
const CspProviderFlags notExpectedFlags = CspProviderFlags.UseUserProtectedKey
| CspProviderFlags.UseArchivableKey
| CspProviderFlags.UseNonExportableKey;
if ((flags & notExpectedFlags) != CspProviderFlags.NoFlags)
{
throw ExceptionUtility.Argument("flags", Resources.InvalidCspProviderFlags);
}
}
// Если пользователь должен сам выбрать ключ (например, в диалоге)
if ((flags & CspProviderFlags.UseUserProtectedKey) != CspProviderFlags.NoFlags)
{
if (!Environment.UserInteractive)
{
throw ExceptionUtility.CryptographicException(Resources.UserInteractiveNotSupported);
}
new UIPermission(UIPermissionWindow.SafeTopLevelWindows).Demand();
}
}