{
}
- internal HashProviderCng(string hashAlgId, ReadOnlySpan<byte> key, bool isHmac)
+ internal HashProviderCng(string? hashAlgId, ReadOnlySpan<byte> key, bool isHmac)
{
BCryptOpenAlgorithmProviderFlags dwFlags = BCryptOpenAlgorithmProviderFlags.None;
if (isHmac)
/// <summary>
/// Return a SafeBCryptAlgorithmHandle of the desired algorithm and flags. This is a shared handle so do not dispose it!
/// </summary>
- public static SafeBCryptAlgorithmHandle GetCachedBCryptAlgorithmHandle(string hashAlgorithmId, BCryptOpenAlgorithmProviderFlags flags)
+ public static SafeBCryptAlgorithmHandle GetCachedBCryptAlgorithmHandle(string? hashAlgorithmId, BCryptOpenAlgorithmProviderFlags flags)
{
// There aren't that many hash algorithms around so rather than use a LowLevelDictionary and guard it with a lock,
// we'll use a simple list. To avoid locking, we'll recreate the entire list each time an entry is added and replace it atomically.
private struct Entry
{
- public Entry(string hashAlgorithmId, BCryptOpenAlgorithmProviderFlags flags, SafeBCryptAlgorithmHandle handle)
+ public Entry(string? hashAlgorithmId, BCryptOpenAlgorithmProviderFlags flags, SafeBCryptAlgorithmHandle handle)
: this()
{
HashAlgorithmId = hashAlgorithmId;
Handle = handle;
}
- public string HashAlgorithmId { get; private set; }
+ public string? HashAlgorithmId { get; private set; }
public BCryptOpenAlgorithmProviderFlags Flags { get; private set; }
public SafeBCryptAlgorithmHandle Handle { get; private set; }
}
internal partial class BCrypt
{
[DllImport(Libraries.BCrypt, CharSet = CharSet.Unicode)]
- internal static extern NTSTATUS BCryptOpenAlgorithmProvider(out SafeBCryptAlgorithmHandle phAlgorithm, string pszAlgId, string? pszImplementation, BCryptOpenAlgorithmProviderFlags dwFlags);
+ internal static extern NTSTATUS BCryptOpenAlgorithmProvider(out SafeBCryptAlgorithmHandle phAlgorithm, string? pszAlgId, string? pszImplementation, BCryptOpenAlgorithmProviderFlags dwFlags);
[Flags]
internal enum BCryptOpenAlgorithmProviderFlags : int
/// </summary>
internal static Interop.BCrypt.ECC_CURVE_ALG_ID_ENUM GetHashAlgorithmId(HashAlgorithmName? name)
{
- if (name.HasValue == false || string.IsNullOrEmpty(name!.Value.Name))
+ if (name is null || string.IsNullOrEmpty(name.Value.Name))
{
return Interop.BCrypt.ECC_CURVE_ALG_ID_ENUM.BCRYPT_NO_CURVE_GENERATION_ALG_ID;
}
return Interop.NCrypt.DeriveKeyMaterialHmac(
secretAgreement,
hashAlgorithm.Name,
- hmacKey,
+ hmacKey!,
secretPrepend,
secretAppend,
flags);
#nullable enable
using System.Buffers;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Cryptography.Asn1;
ReadOnlySpan<byte> passwordBytes,
KeyReader<TRet> keyReader,
out int bytesRead,
- out TRet ret)
+ [MaybeNull] out TRet ret)
{
AsnValueReader reader = new AsnValueReader(source.Span, AsnEncodingRules.BER);
int read = reader.PeekEncodedValue().Length;
}
}
+ Debug.Assert(pwdTmpBytes != null);
+
fixed (byte* pkcs8RentPin = sourceRent)
fixed (byte* pwdTmpBytesPtr = pwdTmpBytes)
{
public override byte[] Key { get { throw null; } set { } }
public override int KeySize { get { throw null; } set { } }
public override System.Security.Cryptography.ICryptoTransform CreateDecryptor() { throw null; }
- public override System.Security.Cryptography.ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV) { throw null; }
+ public override System.Security.Cryptography.ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[]? rgbIV) { throw null; }
public override System.Security.Cryptography.ICryptoTransform CreateEncryptor() { throw null; }
- public override System.Security.Cryptography.ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV) { throw null; }
+ public override System.Security.Cryptography.ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[]? rgbIV) { throw null; }
protected override void Dispose(bool disposing) { }
public override void GenerateIV() { }
public override void GenerateKey() { }
public static System.Security.Cryptography.CngAlgorithm Sha256 { get { throw null; } }
public static System.Security.Cryptography.CngAlgorithm Sha384 { get { throw null; } }
public static System.Security.Cryptography.CngAlgorithm Sha512 { get { throw null; } }
- public override bool Equals(object obj) { throw null; }
- public bool Equals(System.Security.Cryptography.CngAlgorithm other) { throw null; }
+ public override bool Equals(object? obj) { throw null; }
+ public bool Equals(System.Security.Cryptography.CngAlgorithm? other) { throw null; }
public override int GetHashCode() { throw null; }
- public static bool operator ==(System.Security.Cryptography.CngAlgorithm left, System.Security.Cryptography.CngAlgorithm right) { throw null; }
- public static bool operator !=(System.Security.Cryptography.CngAlgorithm left, System.Security.Cryptography.CngAlgorithm right) { throw null; }
+ public static bool operator ==(System.Security.Cryptography.CngAlgorithm? left, System.Security.Cryptography.CngAlgorithm? right) { throw null; }
+ public static bool operator !=(System.Security.Cryptography.CngAlgorithm? left, System.Security.Cryptography.CngAlgorithm? right) { throw null; }
public override string ToString() { throw null; }
}
public sealed partial class CngAlgorithmGroup : System.IEquatable<System.Security.Cryptography.CngAlgorithmGroup>
public static System.Security.Cryptography.CngAlgorithmGroup ECDiffieHellman { get { throw null; } }
public static System.Security.Cryptography.CngAlgorithmGroup ECDsa { get { throw null; } }
public static System.Security.Cryptography.CngAlgorithmGroup Rsa { get { throw null; } }
- public override bool Equals(object obj) { throw null; }
- public bool Equals(System.Security.Cryptography.CngAlgorithmGroup other) { throw null; }
+ public override bool Equals(object? obj) { throw null; }
+ public bool Equals(System.Security.Cryptography.CngAlgorithmGroup? other) { throw null; }
public override int GetHashCode() { throw null; }
- public static bool operator ==(System.Security.Cryptography.CngAlgorithmGroup left, System.Security.Cryptography.CngAlgorithmGroup right) { throw null; }
- public static bool operator !=(System.Security.Cryptography.CngAlgorithmGroup left, System.Security.Cryptography.CngAlgorithmGroup right) { throw null; }
+ public static bool operator ==(System.Security.Cryptography.CngAlgorithmGroup? left, System.Security.Cryptography.CngAlgorithmGroup? right) { throw null; }
+ public static bool operator !=(System.Security.Cryptography.CngAlgorithmGroup? left, System.Security.Cryptography.CngAlgorithmGroup? right) { throw null; }
public override string ToString() { throw null; }
}
[System.FlagsAttribute]
{
internal CngKey() { }
public System.Security.Cryptography.CngAlgorithm Algorithm { get { throw null; } }
- public System.Security.Cryptography.CngAlgorithmGroup AlgorithmGroup { get { throw null; } }
+ public System.Security.Cryptography.CngAlgorithmGroup? AlgorithmGroup { get { throw null; } }
public System.Security.Cryptography.CngExportPolicies ExportPolicy { get { throw null; } }
public Microsoft.Win32.SafeHandles.SafeNCryptKeyHandle Handle { get { throw null; } }
public bool IsEphemeral { get { throw null; } }
public bool IsMachineKey { get { throw null; } }
- public string KeyName { get { throw null; } }
+ public string? KeyName { get { throw null; } }
public int KeySize { get { throw null; } }
public System.Security.Cryptography.CngKeyUsages KeyUsage { get { throw null; } }
public System.IntPtr ParentWindowHandle { get { throw null; } set { } }
- public System.Security.Cryptography.CngProvider Provider { get { throw null; } }
+ public System.Security.Cryptography.CngProvider? Provider { get { throw null; } }
public Microsoft.Win32.SafeHandles.SafeNCryptProviderHandle ProviderHandle { get { throw null; } }
public System.Security.Cryptography.CngUIPolicy UIPolicy { get { throw null; } }
- public string UniqueName { get { throw null; } }
+ public string? UniqueName { get { throw null; } }
public static System.Security.Cryptography.CngKey Create(System.Security.Cryptography.CngAlgorithm algorithm) { throw null; }
- public static System.Security.Cryptography.CngKey Create(System.Security.Cryptography.CngAlgorithm algorithm, string keyName) { throw null; }
- public static System.Security.Cryptography.CngKey Create(System.Security.Cryptography.CngAlgorithm algorithm, string keyName, System.Security.Cryptography.CngKeyCreationParameters creationParameters) { throw null; }
+ public static System.Security.Cryptography.CngKey Create(System.Security.Cryptography.CngAlgorithm algorithm, string? keyName) { throw null; }
+ public static System.Security.Cryptography.CngKey Create(System.Security.Cryptography.CngAlgorithm algorithm, string? keyName, System.Security.Cryptography.CngKeyCreationParameters? creationParameters) { throw null; }
public void Delete() { }
public void Dispose() { }
public static bool Exists(string keyName) { throw null; }
public static System.Security.Cryptography.CngKeyBlobFormat GenericPublicBlob { get { throw null; } }
public static System.Security.Cryptography.CngKeyBlobFormat OpaqueTransportBlob { get { throw null; } }
public static System.Security.Cryptography.CngKeyBlobFormat Pkcs8PrivateBlob { get { throw null; } }
- public override bool Equals(object obj) { throw null; }
- public bool Equals(System.Security.Cryptography.CngKeyBlobFormat other) { throw null; }
+ public override bool Equals(object? obj) { throw null; }
+ public bool Equals(System.Security.Cryptography.CngKeyBlobFormat? other) { throw null; }
public override int GetHashCode() { throw null; }
- public static bool operator ==(System.Security.Cryptography.CngKeyBlobFormat left, System.Security.Cryptography.CngKeyBlobFormat right) { throw null; }
- public static bool operator !=(System.Security.Cryptography.CngKeyBlobFormat left, System.Security.Cryptography.CngKeyBlobFormat right) { throw null; }
+ public static bool operator ==(System.Security.Cryptography.CngKeyBlobFormat? left, System.Security.Cryptography.CngKeyBlobFormat? right) { throw null; }
+ public static bool operator !=(System.Security.Cryptography.CngKeyBlobFormat? left, System.Security.Cryptography.CngKeyBlobFormat? right) { throw null; }
public override string ToString() { throw null; }
}
[System.FlagsAttribute]
public System.Security.Cryptography.CngKeyUsages? KeyUsage { get { throw null; } set { } }
public System.Security.Cryptography.CngPropertyCollection Parameters { get { throw null; } }
public System.IntPtr ParentWindowHandle { get { throw null; } set { } }
+ [System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
public System.Security.Cryptography.CngProvider Provider { get { throw null; } set { } }
- public System.Security.Cryptography.CngUIPolicy UIPolicy { get { throw null; } set { } }
+ public System.Security.Cryptography.CngUIPolicy? UIPolicy { get { throw null; } set { } }
}
[System.FlagsAttribute]
public enum CngKeyHandleOpenOptions
{
private object _dummy;
private int _dummyPrimitive;
- public CngProperty(string name, byte[] value, System.Security.Cryptography.CngPropertyOptions options) { throw null; }
+ public CngProperty(string name, byte[]? value, System.Security.Cryptography.CngPropertyOptions options) { throw null; }
public readonly string Name { get { throw null; } }
- public readonly System.Security.Cryptography.CngPropertyOptions Options { get { throw null; } }
- public override bool Equals(object obj) { throw null; }
+ public readonly System.Security.Cryptography.CngPropertyOptions Options { get { throw null; } }
+ public override bool Equals(object? obj) { throw null; }
public bool Equals(System.Security.Cryptography.CngProperty other) { throw null; }
public override int GetHashCode() { throw null; }
- public byte[] GetValue() { throw null; }
+ public byte[]? GetValue() { throw null; }
public static bool operator ==(System.Security.Cryptography.CngProperty left, System.Security.Cryptography.CngProperty right) { throw null; }
public static bool operator !=(System.Security.Cryptography.CngProperty left, System.Security.Cryptography.CngProperty right) { throw null; }
}
public static System.Security.Cryptography.CngProvider MicrosoftSmartCardKeyStorageProvider { get { throw null; } }
public static System.Security.Cryptography.CngProvider MicrosoftSoftwareKeyStorageProvider { get { throw null; } }
public string Provider { get { throw null; } }
- public override bool Equals(object obj) { throw null; }
- public bool Equals(System.Security.Cryptography.CngProvider other) { throw null; }
+ public override bool Equals(object? obj) { throw null; }
+ public bool Equals(System.Security.Cryptography.CngProvider? other) { throw null; }
public override int GetHashCode() { throw null; }
- public static bool operator ==(System.Security.Cryptography.CngProvider left, System.Security.Cryptography.CngProvider right) { throw null; }
- public static bool operator !=(System.Security.Cryptography.CngProvider left, System.Security.Cryptography.CngProvider right) { throw null; }
+ public static bool operator ==(System.Security.Cryptography.CngProvider? left, System.Security.Cryptography.CngProvider? right) { throw null; }
+ public static bool operator !=(System.Security.Cryptography.CngProvider? left, System.Security.Cryptography.CngProvider? right) { throw null; }
public override string ToString() { throw null; }
}
public sealed partial class CngUIPolicy
{
public CngUIPolicy(System.Security.Cryptography.CngUIProtectionLevels protectionLevel) { }
- public CngUIPolicy(System.Security.Cryptography.CngUIProtectionLevels protectionLevel, string friendlyName) { }
- public CngUIPolicy(System.Security.Cryptography.CngUIProtectionLevels protectionLevel, string friendlyName, string description) { }
- public CngUIPolicy(System.Security.Cryptography.CngUIProtectionLevels protectionLevel, string friendlyName, string description, string useContext) { }
- public CngUIPolicy(System.Security.Cryptography.CngUIProtectionLevels protectionLevel, string friendlyName, string description, string useContext, string creationTitle) { }
- public string CreationTitle { get { throw null; } }
- public string Description { get { throw null; } }
- public string FriendlyName { get { throw null; } }
+ public CngUIPolicy(System.Security.Cryptography.CngUIProtectionLevels protectionLevel, string? friendlyName) { }
+ public CngUIPolicy(System.Security.Cryptography.CngUIProtectionLevels protectionLevel, string? friendlyName, string? description) { }
+ public CngUIPolicy(System.Security.Cryptography.CngUIProtectionLevels protectionLevel, string? friendlyName, string? description, string? useContext) { }
+ public CngUIPolicy(System.Security.Cryptography.CngUIProtectionLevels protectionLevel, string? friendlyName, string? description, string? useContext, string? creationTitle) { }
+ public string? CreationTitle { get { throw null; } }
+ public string? Description { get { throw null; } }
+ public string? FriendlyName { get { throw null; } }
public System.Security.Cryptography.CngUIProtectionLevels ProtectionLevel { get { throw null; } }
- public string UseContext { get { throw null; } }
+ public string? UseContext { get { throw null; } }
}
[System.FlagsAttribute]
public enum CngUIProtectionLevels
public DSACng(int keySize) { }
public DSACng(System.Security.Cryptography.CngKey key) { }
public System.Security.Cryptography.CngKey Key { get { throw null; } }
- public override string KeyExchangeAlgorithm { get { throw null; } }
+ public override string? KeyExchangeAlgorithm { get { throw null; } }
public override System.Security.Cryptography.KeySizes[] LegalKeySizes { get { throw null; } }
public override string SignatureAlgorithm { get { throw null; } }
public override byte[] CreateSignature(byte[] rgbHash) { throw null; }
public ECDiffieHellmanCng(System.Security.Cryptography.ECCurve curve) { }
#endif
public System.Security.Cryptography.CngAlgorithm HashAlgorithm { get { throw null; } set { } }
- public byte[] HmacKey { get { throw null; } set { } }
+ public byte[]? HmacKey { get { throw null; } set { } }
public System.Security.Cryptography.CngKey Key { get { throw null; } }
public System.Security.Cryptography.ECDiffieHellmanKeyDerivationFunction KeyDerivationFunction { get { throw null; } set { } }
public override int KeySize { get { throw null; } set { } }
- public byte[] Label { get { throw null; } set { } }
+ public byte[]? Label { get { throw null; } set { } }
public override System.Security.Cryptography.ECDiffieHellmanPublicKey PublicKey { get { throw null; } }
- public byte[] SecretAppend { get { throw null; } set { } }
- public byte[] SecretPrepend { get { throw null; } set { } }
- public byte[] Seed { get { throw null; } set { } }
+ public byte[]? SecretAppend { get { throw null; } set { } }
+ public byte[]? SecretPrepend { get { throw null; } set { } }
+ public byte[]? Seed { get { throw null; } set { } }
public bool UseSecretAgreementAsHmacKey { get { throw null; } }
#if FEATURE_ECDH_DERIVEFROM
public override byte[] DeriveKeyFromHash(System.Security.Cryptography.ECDiffieHellmanPublicKey otherPartyPublicKey, System.Security.Cryptography.HashAlgorithmName hashAlgorithm, byte[] secretPrepend, byte[] secretAppend) { throw null; }
public override byte[] Key { get { throw null; } set { } }
public override int KeySize { get { throw null; } set { } }
public override System.Security.Cryptography.ICryptoTransform CreateDecryptor() { throw null; }
- public override System.Security.Cryptography.ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV) { throw null; }
+ public override System.Security.Cryptography.ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[]? rgbIV) { throw null; }
public override System.Security.Cryptography.ICryptoTransform CreateEncryptor() { throw null; }
- public override System.Security.Cryptography.ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV) { throw null; }
+ public override System.Security.Cryptography.ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[]? rgbIV) { throw null; }
protected override void Dispose(bool disposing) { }
public override void GenerateIV() { }
public override void GenerateKey() { }
<TargetFrameworks>netcoreapp3.0;netstandard2.1;net461;net462;net47;$(NetCoreAppCurrent);$(NetFrameworkCurrent)</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
<ExcludeCurrentFullFrameworkFromPackage>true</ExcludeCurrentFullFrameworkFromPackage>
+ <Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="System.Security.Cryptography.Cng.cs" />
int numBytesWritten;
ErrorCode errorCode;
- using (SafeNCryptKeyHandle keyHandle = _cngKey.Handle)
+ using (SafeNCryptKeyHandle keyHandle = _cngKey!.Handle)
{
var inputSpan = new ReadOnlySpan<byte>(input, inputOffset, count);
var outputSpan = new Span<byte>(output, outputOffset, count);
if (IV != null)
{
CngProperty prop = new CngProperty(Interop.NCrypt.NCRYPT_INITIALIZATION_VECTOR, IV, CngPropertyOptions.None);
- _cngKey.SetProperty(prop);
+ _cngKey!.SetProperty(prop);
}
}
- private CngKey _cngKey;
+ private CngKey? _cngKey;
private readonly bool _encrypting;
private static readonly CngProperty s_ECBMode =
{
private readonly string _disposedName;
public CngAlgorithm DefaultKeyType;
- private CngKey _lazyKey;
+ private CngKey? _lazyKey;
private bool _disposed;
public CngAlgorithmCore(string disposedName) : this()
return CreateCryptoTransform(encrypting: false);
}
- public ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV)
+ public ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[]? rgbIV)
{
return CreateCryptoTransform(rgbKey, rgbIV, encrypting: true);
}
- public ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV)
+ public ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[]? rgbIV)
{
return CreateCryptoTransform(rgbKey, rgbIV, encrypting: false);
}
return CreatePersistedCryptoTransformCore(ProduceCngKey, _outer.IV, encrypting);
}
- private ICryptoTransform CreateCryptoTransform(byte[] rgbKey, byte[] rgbIV, bool encrypting)
+ private ICryptoTransform CreateCryptoTransform(byte[] rgbKey, byte[]? rgbIV, bool encrypting)
{
if (rgbKey == null)
throw new ArgumentNullException(nameof(rgbKey));
// CloneByteArray is null-preserving. So even when GetCipherIv returns null the iv variable
// is correct, and detached from the input parameter.
- byte[] iv = _outer.Mode.GetCipherIv(rgbIV).CloneByteArray();
+ byte[]? iv = _outer.Mode.GetCipherIv(rgbIV).CloneByteArray();
key = _outer.PreprocessKey(key);
return CreateEphemeralCryptoTransformCore(key, iv, encrypting);
}
- private ICryptoTransform CreateEphemeralCryptoTransformCore(byte[] key, byte[] iv, bool encrypting)
+ private ICryptoTransform CreateEphemeralCryptoTransformCore(byte[] key, byte[]? iv, bool encrypting)
{
int blockSizeInBytes = _outer.BlockSize.BitSizeToByteSize();
SafeAlgorithmHandle algorithmModeHandle = _outer.GetEphemeralModeHandle();
{
Debug.Assert(!KeyInPlainText);
- return CngKey.Open(_keyName, _provider, _optionOptions);
+ return CngKey.Open(_keyName!, _provider!, _optionOptions);
}
private bool KeyInPlainText
private readonly ICngSymmetricAlgorithm _outer;
// If using a stored CNG key, these fields provide the CngKey.Open() parameters. If using a plaintext key, _keyName is set to null.
- private string _keyName;
- private readonly CngProvider _provider;
+ private string? _keyName;
+ private readonly CngProvider? _provider;
private readonly CngKeyOpenOptions _optionOptions;
private const int BitsPerByte = 8;
return cipherMode != CipherMode.ECB;
}
- public static byte[] GetCipherIv(this CipherMode cipherMode, byte[] iv)
+ public static byte[]? GetCipherIv(this CipherMode cipherMode, byte[]? iv)
{
if (cipherMode.UsesIv())
{
//
// which always sets "p" to a non-NULL pointer for a non-null byte array.
//
- public static byte[] MapZeroLengthArrayToNonNullPointer(this byte[] src)
+ public static byte[]? MapZeroLengthArrayToNonNullPointer(this byte[]? src)
{
if (src != null && src.Length == 0)
return new byte[1];
/// null - if property not defined on key.
/// throws - for any other type of error.
/// </returns>
- public static byte[] GetProperty(this SafeNCryptHandle ncryptHandle, string propertyName, CngPropertyOptions options)
+ public static byte[]? GetProperty(this SafeNCryptHandle ncryptHandle, string propertyName, CngPropertyOptions options)
{
unsafe
{
/// Retrieve a well-known CNG string property. (Note: .NET Framework compat: this helper likes to return special values rather than throw exceptions for missing
/// or ill-formatted property values. Only use it for well-known properties that are unlikely to be ill-formatted.)
/// </summary>
- public static string GetPropertyAsString(this SafeNCryptHandle ncryptHandle, string propertyName, CngPropertyOptions options)
+ public static string? GetPropertyAsString(this SafeNCryptHandle ncryptHandle, string propertyName, CngPropertyOptions options)
{
- byte[] value = ncryptHandle.GetProperty(propertyName, options);
+ byte[]? value = ncryptHandle.GetProperty(propertyName, options);
if (value == null)
return null; // .NET Framework compat: return null if key not present.
if (value.Length == 0)
{
fixed (byte* pValue = &value[0])
{
- string valueAsString = Marshal.PtrToStringUni((IntPtr)pValue);
+ string? valueAsString = Marshal.PtrToStringUni((IntPtr)pValue);
return valueAsString;
}
}
/// </summary>
public static int GetPropertyAsDword(this SafeNCryptHandle ncryptHandle, string propertyName, CngPropertyOptions options)
{
- byte[] value = ncryptHandle.GetProperty(propertyName, options);
+ byte[]? value = ncryptHandle.GetProperty(propertyName, options);
if (value == null)
return 0; // .NET Framework compat: return 0 if key not present.
return BitConverter.ToInt32(value, 0);
using System;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using ErrorCode = Interop.NCrypt.ErrorCode;
/// <summary>
/// If the handle is a Duplicate, this points at the safe handle which actually owns the native handle.
/// </summary>
- private SafeNCryptHandle _holder;
+ private SafeNCryptHandle? _holder;
- private SafeHandle _parentHandle;
+ private SafeHandle? _parentHandle;
protected SafeNCryptHandle() : base(true)
{
/// <summary>
/// Wrapper for the _holder field which ensures that we're in a consistent state
/// </summary>
+ [MaybeNull]
private SafeNCryptHandle Holder
{
get
{
if (acquiredHolder)
{
- Holder.DangerousRelease();
+ Holder!.DangerousRelease();
}
}
bool addedRef = false;
T duplicate = new T();
- Holder.DangerousAddRef(ref addedRef);
+ Holder!.DangerousAddRef(ref addedRef);
duplicate.SetHandle(Holder.DangerousGetHandle());
duplicate.Holder = Holder; // Transitions to OwnershipState.Duplicate
{
if (_ownershipState == OwnershipState.Duplicate)
{
- Holder.DangerousRelease();
+ Holder!.DangerousRelease();
return true;
}
else if (_parentHandle != null)
<TargetFrameworks>netstandard2.0;netstandard2.1;net461-Windows_NT;netcoreapp3.0-Windows_NT;netcoreapp3.0;net462-Windows_NT;net47-Windows_NT;$(NetCoreAppCurrent)-Windows_NT;$(NetCoreAppCurrent);$(NetFrameworkCurrent)-Windows_NT</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
<ExcludeCurrentFullFrameworkFromPackage>true</ExcludeCurrentFullFrameworkFromPackage>
+ <Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetsWindows)' != 'true'">
<GeneratePlatformNotSupportedAssemblyMessage>SR.PlatformNotSupported_CryptographyCng</GeneratePlatformNotSupportedAssemblyMessage>
return _core.CreateDecryptor();
}
- public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV)
+ public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[]? rgbIV)
{
return _core.CreateDecryptor(rgbKey, rgbIV);
}
return _core.CreateEncryptor();
}
- public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV)
+ public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[]? rgbIV)
{
return _core.CreateEncryptor(rgbKey, rgbIV);
}
}
}
- public static bool operator ==(CngAlgorithm left, CngAlgorithm right)
+ public static bool operator ==(CngAlgorithm? left, CngAlgorithm? right)
{
if (object.ReferenceEquals(left, null))
{
return left.Equals(right);
}
- public static bool operator !=(CngAlgorithm left, CngAlgorithm right)
+ public static bool operator !=(CngAlgorithm? left, CngAlgorithm? right)
{
if (object.ReferenceEquals(left, null))
{
return !left.Equals(right);
}
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
Debug.Assert(_algorithm != null);
return Equals(obj as CngAlgorithm);
}
- public bool Equals(CngAlgorithm other)
+ public bool Equals(CngAlgorithm? other)
{
if (object.ReferenceEquals(other, null))
{
}
}
- private static CngAlgorithm s_ecdh;
- private static CngAlgorithm s_ecdhp256;
- private static CngAlgorithm s_ecdhp384;
- private static CngAlgorithm s_ecdhp521;
- private static CngAlgorithm s_ecdsa;
- private static CngAlgorithm s_ecdsap256;
- private static CngAlgorithm s_ecdsap384;
- private static CngAlgorithm s_ecdsap521;
- private static CngAlgorithm s_md5;
- private static CngAlgorithm s_sha1;
- private static CngAlgorithm s_sha256;
- private static CngAlgorithm s_sha384;
- private static CngAlgorithm s_sha512;
- private static CngAlgorithm s_rsa;
+ private static CngAlgorithm? s_ecdh;
+ private static CngAlgorithm? s_ecdhp256;
+ private static CngAlgorithm? s_ecdhp384;
+ private static CngAlgorithm? s_ecdhp521;
+ private static CngAlgorithm? s_ecdsa;
+ private static CngAlgorithm? s_ecdsap256;
+ private static CngAlgorithm? s_ecdsap384;
+ private static CngAlgorithm? s_ecdsap521;
+ private static CngAlgorithm? s_md5;
+ private static CngAlgorithm? s_sha1;
+ private static CngAlgorithm? s_sha256;
+ private static CngAlgorithm? s_sha384;
+ private static CngAlgorithm? s_sha512;
+ private static CngAlgorithm? s_rsa;
private readonly string _algorithm;
}
}
}
- public static bool operator ==(CngAlgorithmGroup left, CngAlgorithmGroup right)
+ public static bool operator ==(CngAlgorithmGroup? left, CngAlgorithmGroup? right)
{
if (object.ReferenceEquals(left, null))
{
return left.Equals(right);
}
- public static bool operator !=(CngAlgorithmGroup left, CngAlgorithmGroup right)
+ public static bool operator !=(CngAlgorithmGroup? left, CngAlgorithmGroup? right)
{
if (object.ReferenceEquals(left, null))
{
return !left.Equals(right);
}
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
Debug.Assert(_algorithmGroup != null);
return Equals(obj as CngAlgorithmGroup);
}
- public bool Equals(CngAlgorithmGroup other)
+ public bool Equals(CngAlgorithmGroup? other)
{
if (object.ReferenceEquals(other, null))
{
}
}
- private static CngAlgorithmGroup s_dh;
- private static CngAlgorithmGroup s_dsa;
- private static CngAlgorithmGroup s_ecdh;
- private static CngAlgorithmGroup s_ecdsa;
- private static CngAlgorithmGroup s_rsa;
+ private static CngAlgorithmGroup? s_dh;
+ private static CngAlgorithmGroup? s_dsa;
+ private static CngAlgorithmGroup? s_ecdh;
+ private static CngAlgorithmGroup? s_ecdsa;
+ private static CngAlgorithmGroup? s_rsa;
private readonly string _algorithmGroup;
}
return Create(algorithm, keyName: null);
}
- public static CngKey Create(CngAlgorithm algorithm, string keyName)
+ public static CngKey Create(CngAlgorithm algorithm, string? keyName)
{
return Create(algorithm, keyName, creationParameters: null);
}
- public static CngKey Create(CngAlgorithm algorithm, string keyName, CngKeyCreationParameters creationParameters)
+ public static CngKey Create(CngAlgorithm algorithm, string? keyName, CngKeyCreationParameters? creationParameters)
{
if (algorithm == null)
throw new ArgumentNullException(nameof(algorithm));
if (creationParameters == null)
creationParameters = new CngKeyCreationParameters();
- SafeNCryptProviderHandle providerHandle = creationParameters.Provider.OpenStorageProvider();
+ SafeNCryptProviderHandle providerHandle = creationParameters.Provider!.OpenStorageProvider();
SafeNCryptKeyHandle keyHandle;
ErrorCode errorCode = Interop.NCrypt.NCryptCreatePersistedKey(providerHandle, out keyHandle, algorithm.Algorithm, keyName, 0, creationParameters.KeyCreationOptions);
if (errorCode != ErrorCode.ERROR_SUCCESS)
throw errorCode.ToCryptographicException();
}
- CngUIPolicy uiPolicy = creationParameters.UIPolicy;
+ CngUIPolicy? uiPolicy = creationParameters.UIPolicy;
if (uiPolicy != null)
{
InitializeKeyUiPolicyProperties(keyHandle, uiPolicy);
// Iterate over the custom properties, setting those as well.
foreach (CngProperty property in creationParameters.Parameters)
{
- byte[] value = property.GetValueWithoutCopying();
+ byte[]? value = property.GetValueWithoutCopying();
int valueLength = (value == null) ? 0 : value.Length;
fixed (byte* pValue = value.MapZeroLengthArrayToNonNullPointer())
{
throw errorCode.ToCryptographicException();
}
- string useContext = uiPolicy.UseContext;
+ string? useContext = uiPolicy.UseContext;
if (useContext != null)
{
int useContextByteLength = checked((useContext.Length + 1) * sizeof(char));
algorithm == CngAlgorithm.ECDsa.Algorithm);
}
- internal string GetCurveName(out string oidValue)
+ internal string? GetCurveName(out string? oidValue)
{
if (IsECNamedCurve())
{
/// </summary>
internal static CngProperty GetPropertyFromNamedCurve(ECCurve curve)
{
- string curveName = curve.Oid.FriendlyName;
+ string curveName = curve.Oid.FriendlyName!;
unsafe
{
byte[] curveNameBytes = new byte[(curveName.Length + 1) * sizeof(char)]; // +1 to add trailing null
return CngAlgorithm.ECDiffieHellman;
}
- internal static CngKey Create(ECCurve curve, Func<string, CngAlgorithm> algorithmResolver)
+ internal static CngKey Create(ECCurve curve, Func<string?, CngAlgorithm> algorithmResolver)
{
System.Diagnostics.Debug.Assert(algorithmResolver != null);
if (errorCode == Interop.NCrypt.ErrorCode.NTE_INVALID_PARAMETER ||
errorCode == Interop.NCrypt.ErrorCode.NTE_NOT_SUPPORTED)
{
- string target = curve.IsNamed ? curve.Oid.FriendlyName : curve.CurveType.ToString();
+ string? target = curve.IsNamed ? curve.Oid.FriendlyName : curve.CurveType.ToString();
throw new PlatformNotSupportedException(SR.Format(SR.Cryptography_CurveNotSupported, target), e);
}
using (SafeNCryptProviderHandle providerHandle = provider.OpenStorageProvider())
{
- SafeNCryptKeyHandle keyHandle = null;
+ SafeNCryptKeyHandle? keyHandle = null;
try
{
ErrorCode errorCode = Interop.NCrypt.NCryptOpenKey(providerHandle, out keyHandle, keyName, 0, options);
int kdfCount)
{
bool ret = ExportPkcs8KeyBlob(
- true,
+ allocate: true,
_keyHandle,
password,
kdfCount,
Span<byte>.Empty,
out _,
- out byte[] allocated);
+ out byte[]? allocated);
Debug.Assert(ret);
+ Debug.Assert(allocated != null); // on account of allocate parameter being true
return allocated;
}
int kdfCount,
Span<byte> destination,
out int bytesWritten,
- out byte[] allocated)
+ out byte[]? allocated)
{
using (SafeUnicodeStringHandle stringHandle = new SafeUnicodeStringHandle(password))
{
{
byte[] trimmed = new byte[numBytesNeeded];
destination.Slice(0, numBytesNeeded).CopyTo(trimmed);
- Array.Clear(allocated, 0, numBytesNeeded);
+ Array.Clear(allocated!, 0, numBytesNeeded);
allocated = trimmed;
}
return Import(keyBlob, format, provider: CngProvider.MicrosoftSoftwareKeyStorageProvider);
}
- internal static CngKey Import(byte[] keyBlob, string curveName, CngKeyBlobFormat format)
+ internal static CngKey Import(byte[] keyBlob, string? curveName, CngKeyBlobFormat format)
{
return Import(keyBlob, curveName, format, provider: CngProvider.MicrosoftSoftwareKeyStorageProvider);
}
internal static CngKey Import(
byte[] keyBlob,
- string curveName,
+ string? curveName,
CngKeyBlobFormat format,
CngProvider provider)
{
internal static CngKey Import(
ReadOnlySpan<byte> keyBlob,
- string curveName,
+ string? curveName,
CngKeyBlobFormat format,
CngProvider provider)
{
throw new ArgumentNullException(nameof(provider));
SafeNCryptProviderHandle providerHandle = provider.OpenStorageProvider();
- SafeNCryptKeyHandle keyHandle = null;
+ SafeNCryptKeyHandle? keyHandle = null;
ErrorCode errorCode;
if (curveName == null)
providerHandle.SetHandleValue(rawProviderHandle);
// Set up a key object wrapping the handle
- CngKey key = null;
+ CngKey? key = null;
try
{
key = new CngKey(providerHandle, keyHandleCopy);
if (name == null)
throw new ArgumentNullException(nameof(name));
- byte[] value = _keyHandle.GetProperty(name, options);
+ byte[]? value = _keyHandle.GetProperty(name, options);
if (value == null)
throw ErrorCode.NTE_NOT_FOUND.ToCryptographicException();
{
unsafe
{
- byte[] propertyValue = property.GetValueWithoutCopying();
+ byte[]? propertyValue = property.GetValueWithoutCopying();
// .NET Framework compat. It would have nicer to throw an ArgumentNull exception or something...
if (propertyValue == null)
{
get
{
- string algorithm = _keyHandle.GetPropertyAsString(KeyPropertyName.Algorithm, CngPropertyOptions.None);
+ string algorithm = _keyHandle.GetPropertyAsString(KeyPropertyName.Algorithm, CngPropertyOptions.None)!;
// .NET Framework compat: Don't check for null. Just let CngAlgorithm handle it.
return new CngAlgorithm(algorithm);
}
/// <summary>
/// Name of the algorithm this key can be used with
/// </summary>
- public CngAlgorithmGroup AlgorithmGroup
+ public CngAlgorithmGroup? AlgorithmGroup
{
get
{
- string algorithmGroup = _keyHandle.GetPropertyAsString(KeyPropertyName.AlgorithmGroup, CngPropertyOptions.None);
+ string? algorithmGroup = _keyHandle.GetPropertyAsString(KeyPropertyName.AlgorithmGroup, CngPropertyOptions.None);
if (algorithmGroup == null)
return null;
return new CngAlgorithmGroup(algorithmGroup);
/// the CLR. Other ephemeral keys, such as those imported by handle, will get a CryptographicException
/// if they read this property.
/// </summary>
- public string KeyName
+ public string? KeyName
{
get
{
if (IsEphemeral)
return null;
- string keyName = _keyHandle.GetPropertyAsString(KeyPropertyName.Name, CngPropertyOptions.None);
+ string? keyName = _keyHandle.GetPropertyAsString(KeyPropertyName.Name, CngPropertyOptions.None);
return keyName;
}
}
/// <summary>
/// KSP which holds this key
/// </summary>
- public CngProvider Provider
+ public CngProvider? Provider
{
get
{
- string provider = _providerHandle.GetPropertyAsString(ProviderPropertyName.Name, CngPropertyOptions.None);
+ string? provider = _providerHandle.GetPropertyAsString(ProviderPropertyName.Name, CngPropertyOptions.None);
if (provider == null)
return null;
return new CngProvider(provider);
get
{
CngUIProtectionLevels uiProtectionLevel;
- string friendlyName;
- string description;
- string creationTitle;
+ string? friendlyName;
+ string? description;
+ string? creationTitle;
unsafe
{
int numBytesNeeded;
}
}
- string useContext = _keyHandle.GetPropertyAsString(KeyPropertyName.UseContext, CngPropertyOptions.None);
+ string? useContext = _keyHandle.GetPropertyAsString(KeyPropertyName.UseContext, CngPropertyOptions.None);
return new CngUIPolicy(uiProtectionLevel, friendlyName, description, useContext, creationTitle);
}
/// Unique name of the key, null if it is ephemeral. See the comments on the Name property for
/// details about names of ephemeral keys.
/// </summary>
- public string UniqueName
+ public string? UniqueName
{
get
{
if (IsEphemeral)
return null;
- string uniqueName = _keyHandle.GetPropertyAsString(KeyPropertyName.UniqueName, CngPropertyOptions.None);
+ string? uniqueName = _keyHandle.GetPropertyAsString(KeyPropertyName.UniqueName, CngPropertyOptions.None);
return uniqueName;
}
}
}
}
- public static bool operator ==(CngKeyBlobFormat left, CngKeyBlobFormat right)
+ public static bool operator ==(CngKeyBlobFormat? left, CngKeyBlobFormat? right)
{
if (object.ReferenceEquals(left, null))
{
return left.Equals(right);
}
- public static bool operator !=(CngKeyBlobFormat left, CngKeyBlobFormat right)
+ public static bool operator !=(CngKeyBlobFormat? left, CngKeyBlobFormat? right)
{
if (object.ReferenceEquals(left, null))
{
return !left.Equals(right);
}
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
Debug.Assert(_format != null);
return Equals(obj as CngKeyBlobFormat);
}
- public bool Equals(CngKeyBlobFormat other)
+ public bool Equals(CngKeyBlobFormat? other)
{
if (object.ReferenceEquals(other, null))
{
}
- private static CngKeyBlobFormat s_eccPrivate;
- private static CngKeyBlobFormat s_eccPublic;
- private static CngKeyBlobFormat s_eccFullPrivate;
- private static CngKeyBlobFormat s_eccFullPublic;
- private static CngKeyBlobFormat s_genericPrivate;
- private static CngKeyBlobFormat s_genericPublic;
- private static CngKeyBlobFormat s_opaqueTransport;
- private static CngKeyBlobFormat s_pkcs8Private;
+ private static CngKeyBlobFormat? s_eccPrivate;
+ private static CngKeyBlobFormat? s_eccPublic;
+ private static CngKeyBlobFormat? s_eccFullPrivate;
+ private static CngKeyBlobFormat? s_eccFullPublic;
+ private static CngKeyBlobFormat? s_genericPrivate;
+ private static CngKeyBlobFormat? s_genericPublic;
+ private static CngKeyBlobFormat? s_opaqueTransport;
+ private static CngKeyBlobFormat? s_pkcs8Private;
private readonly string _format;
}
using System;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
namespace System.Security.Cryptography
{
/// <summary>
/// KSP to create the key in
/// </summary>
+ [MaybeNull]
public CngProvider Provider
{
get
/// <summary>
/// Settings for UI shown on access to the key
/// </summary>
- public CngUIPolicy UIPolicy { get; set; }
+ public CngUIPolicy? UIPolicy { get; set; }
- private CngProvider _provider;
+ private CngProvider? _provider;
}
}
internal string GetAlgorithmGroup()
{
- return Key.AlgorithmGroup.AlgorithmGroup;
+ return Key.AlgorithmGroup!.AlgorithmGroup;
}
internal void FreeKey()
[StructLayout(LayoutKind.Sequential)] // The [StructLayout] is here to prevent a spurious ApiReviewer alert. We do not actually depend on the layout of this struct.
public struct CngProperty : IEquatable<CngProperty>
{
- public CngProperty(string name, byte[] value, CngPropertyOptions options)
+ public CngProperty(string name, byte[]? value, CngPropertyOptions options)
: this()
{
if (name == null)
/// Contents of the property
/// </summary>
/// <returns></returns>
- public byte[] GetValue()
+ public byte[]? GetValue()
{
return (_value == null) ? null : _value.CloneByteArray();
}
/// </summary>
public CngPropertyOptions Options { get; private set; }
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
return obj is CngProperty && Equals((CngProperty)obj);
}
return !left.Equals(right);
}
- internal byte[] GetValueWithoutCopying()
+ internal byte[]? GetValueWithoutCopying()
{
return _value;
}
- private readonly byte[] _value;
+ private readonly byte[]? _value;
private int? _lazyHashCode;
}
}
}
}
- public static bool operator ==(CngProvider left, CngProvider right)
+ public static bool operator ==(CngProvider? left, CngProvider? right)
{
if (object.ReferenceEquals(left, null))
return object.ReferenceEquals(right, null);
return left.Equals(right);
}
- public static bool operator !=(CngProvider left, CngProvider right)
+ public static bool operator !=(CngProvider? left, CngProvider? right)
{
if (object.ReferenceEquals(left, null))
{
return !left.Equals(right);
}
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
Debug.Assert(_provider != null);
return Equals(obj as CngProvider);
}
- public bool Equals(CngProvider other)
+ public bool Equals(CngProvider? other)
{
if (object.ReferenceEquals(other, null))
{
}
}
- private static CngProvider s_msSmartCardKsp;
- private static CngProvider s_msSoftwareKsp;
+ private static CngProvider? s_msSmartCardKsp;
+ private static CngProvider? s_msSoftwareKsp;
private readonly string _provider;
}
{
}
- public CngUIPolicy(CngUIProtectionLevels protectionLevel, string friendlyName)
+ public CngUIPolicy(CngUIProtectionLevels protectionLevel, string? friendlyName)
: this(protectionLevel, friendlyName, description: null)
{
}
- public CngUIPolicy(CngUIProtectionLevels protectionLevel, string friendlyName, string description)
+ public CngUIPolicy(CngUIProtectionLevels protectionLevel, string? friendlyName, string? description)
: this(protectionLevel, friendlyName, description, useContext: null)
{
}
- public CngUIPolicy(CngUIProtectionLevels protectionLevel, string friendlyName, string description, string useContext)
+ public CngUIPolicy(CngUIProtectionLevels protectionLevel, string? friendlyName, string? description, string? useContext)
: this(protectionLevel, friendlyName, description, useContext, creationTitle: null)
{
}
- public CngUIPolicy(CngUIProtectionLevels protectionLevel, string friendlyName, string description, string useContext, string creationTitle)
+ public CngUIPolicy(CngUIProtectionLevels protectionLevel, string? friendlyName, string? description, string? useContext, string? creationTitle)
{
ProtectionLevel = protectionLevel;
FriendlyName = friendlyName;
/// Friendly name to describe the key with in the dialog box that appears when the key is accessed,
/// null for default name
/// </summary>
- public string FriendlyName { get; private set; }
+ public string? FriendlyName { get; private set; }
/// <summary>
/// Description text displayed in the dialog box when the key is accessed, null for the default text
/// </summary>
- public string Description { get; private set; }
+ public string? Description { get; private set; }
/// <summary>
/// Description of how the key will be used
/// </summary>
- public string UseContext { get; private set; }
+ public string? UseContext { get; private set; }
/// <summary>
/// Title of the dialog box displayed when a newly created key is finalized, null for the default title
/// </summary>
- public string CreationTitle { get; private set; }
+ public string? CreationTitle { get; private set; }
}
}
CngKey key,
bool includePrivateParameters,
out CngKeyBlobFormat format,
- out string curveName)
+ out string? curveName)
{
curveName = key.GetCurveName(out _);
bool forceGenericBlob = false;
private CngKey GetKey()
{
- CngKey key = null;
+ CngKey? key = null;
if (_core.IsKeyGeneratedNamedCurve())
{
}
else
{
- CngAlgorithm algorithm = null;
+ CngAlgorithm? algorithm = null;
int keySize = 0;
// Map the current key size to a CNG algorithm name
private CngAlgorithmCore _core = new CngAlgorithmCore(nameof(ECDiffieHellmanCng)) { DefaultKeyType = CngAlgorithm.ECDiffieHellman };
private CngAlgorithm _hashAlgorithm = CngAlgorithm.Sha256;
private ECDiffieHellmanKeyDerivationFunction _kdf = ECDiffieHellmanKeyDerivationFunction.Hash;
- private byte[] _hmacKey;
- private byte[] _label;
- private byte[] _secretAppend;
- private byte[] _secretPrepend;
- private byte[] _seed;
+ private byte[]? _hmacKey;
+ private byte[]? _label;
+ private byte[]? _secretAppend;
+ private byte[]? _secretPrepend;
+ private byte[]? _seed;
public ECDiffieHellmanCng(CngKey key)
{
/// <summary>
/// Key used with the HMAC KDF
/// </summary>
- public byte[] HmacKey
+ public byte[]? HmacKey
{
get { return _hmacKey; }
set { _hmacKey = value; }
/// <summary>
/// Label bytes used for the TLS KDF
/// </summary>
- public byte[] Label
+ public byte[]? Label
{
get { return _label; }
set { _label = value; }
/// <summary>
/// Bytes to append to the raw secret agreement before processing by the KDF
/// </summary>
- public byte[] SecretAppend
+ public byte[]? SecretAppend
{
get { return _secretAppend; }
set { _secretAppend = value; }
/// <summary>
/// Bytes to prepend to the raw secret agreement before processing by the KDF
/// </summary>
- public byte[] SecretPrepend
+ public byte[]? SecretPrepend
{
get { return _secretPrepend; }
set { _secretPrepend = value; }
/// <summary>
/// Seed bytes used for the TLS KDF
/// </summary>
- public byte[] Seed
+ public byte[]? Seed
{
get { return _seed; }
set { _seed = value; }
_core.DisposeKey();
}
- internal string GetCurveName(out string oidValue)
+ internal string? GetCurveName(out string? oidValue)
{
return Key.GetCurveName(out oidValue);
}
public sealed partial class ECDiffieHellmanCngPublicKey : ECDiffieHellmanPublicKey
{
private readonly CngKeyBlobFormat _format;
- private readonly string _curveName;
+ private readonly string? _curveName;
private bool _disposed;
/// <summary>
/// Wrap a CNG key
/// </summary>
- internal ECDiffieHellmanCngPublicKey(byte[] keyBlob, string curveName, CngKeyBlobFormat format) : base(keyBlob)
+ internal ECDiffieHellmanCngPublicKey(byte[] keyBlob, string? curveName, CngKeyBlobFormat format) : base(keyBlob)
{
_format = format;
// Can be null for P256, P384, P521, or an explicit blob
internal static ECDiffieHellmanCngPublicKey FromKey(CngKey key)
{
CngKeyBlobFormat format;
- string curveName;
+ string? curveName;
byte[] blob = ECCng.ExportKeyBlob(key, false, out format, out curveName);
return new ECDiffieHellmanCngPublicKey(blob, curveName, format);
}
using (CngKey key = Import())
{
ECParameters ecparams = default;
- string curveName = key.GetCurveName(out _);
+ string? curveName = key.GetCurveName(out _);
if (string.IsNullOrEmpty(curveName))
{
private CngKey GetKey()
{
- CngKey key = null;
+ CngKey? key = null;
if (_core.IsKeyGeneratedNamedCurve())
{
}
else
{
- CngAlgorithm algorithm = null;
+ CngAlgorithm? algorithm = null;
int keySize = 0;
// Map the current key size to a CNG algorithm name
_core.DisposeKey();
}
- private static bool IsEccAlgorithmGroup(CngAlgorithmGroup algorithmGroup)
+ private static bool IsEccAlgorithmGroup(CngAlgorithmGroup? algorithmGroup)
{
// Sometimes, when reading from certificates, ECDSA keys get identified as ECDH.
// Windows allows the ECDH keys to perform both key exchange (ECDH) and signing (ECDSA),
return algorithmGroup == CngAlgorithmGroup.ECDsa || algorithmGroup == CngAlgorithmGroup.ECDiffieHellman;
}
- internal string GetCurveName(out string oidValue)
+ internal string? GetCurveName(out string? oidValue)
{
return Key.GetCurveName(out oidValue);
}
return _core.CreateDecryptor();
}
- public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV)
+ public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[]? rgbIV)
{
return _core.CreateDecryptor(rgbKey, rgbIV);
}
return _core.CreateEncryptor();
}
- public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV)
+ public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[]? rgbIV)
{
return _core.CreateEncryptor(rgbKey, rgbIV);
}