Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DSACng.cs
Go to the documentation of this file.
2using System.IO;
5
7
8public sealed class DSACng : DSA
9{
10 private CngAlgorithmCore _core = new CngAlgorithmCore("DSACng");
11
12 private readonly CngAlgorithm _dsnCng = new CngAlgorithm("DSA");
13
14 private static readonly KeySizes[] s_legalKeySizes = new KeySizes[1]
15 {
16 new KeySizes(512, 3072, 64)
17 };
18
19 private static readonly int s_defaultKeySize = (Supports2048KeySize() ? 2048 : 1024);
20
21 public CngKey Key
22 {
23 get
24 {
26 }
27 private set
28 {
29 if (value.AlgorithmGroup != CngAlgorithmGroup.Dsa)
30 {
32 }
34 ForceSetKeySize(value.KeySize);
35 }
36 }
37
38 public override KeySizes[] LegalKeySizes => base.LegalKeySizes;
39
40 public override string SignatureAlgorithm => "DSA";
41
42 public override string? KeyExchangeAlgorithm => null;
43
45 {
46 if (key == null)
47 {
48 throw new ArgumentNullException("key");
49 }
50 if (key.AlgorithmGroup != CngAlgorithmGroup.Dsa)
51 {
53 }
55 }
56
57 protected override void Dispose(bool disposing)
58 {
59 _core.Dispose();
60 }
61
62 private void ThrowIfDisposed()
63 {
65 }
66
67 private byte[] ExportKeyBlob(bool includePrivateParameters)
68 {
69 CngKeyBlobFormat format = (includePrivateParameters ? CngKeyBlobFormat.GenericPrivateBlob : CngKeyBlobFormat.GenericPublicBlob);
70 return Key.Export(format);
71 }
72
73 private void ImportKeyBlob(byte[] dsaBlob, bool includePrivate)
74 {
75 CngKeyBlobFormat format = (includePrivate ? CngKeyBlobFormat.GenericPrivateBlob : CngKeyBlobFormat.GenericPublicBlob);
76 CngKey cngKey = CngKey.Import(dsaBlob, format);
77 cngKey.ExportPolicy |= CngExportPolicies.AllowPlaintextExport;
78 Key = cngKey;
79 }
80
81 public override bool TryExportPkcs8PrivateKey(Span<byte> destination, out int bytesWritten)
82 {
83 return Key.TryExportKeyBlob("PKCS8_PRIVATEKEY", destination, out bytesWritten);
84 }
85
86 private byte[] ExportEncryptedPkcs8(ReadOnlySpan<char> pkcs8Password, int kdfCount)
87 {
88 return Key.ExportPkcs8KeyBlob(pkcs8Password, kdfCount);
89 }
90
91 private bool TryExportEncryptedPkcs8(ReadOnlySpan<char> pkcs8Password, int kdfCount, Span<byte> destination, out int bytesWritten)
92 {
93 return Key.TryExportPkcs8KeyBlob(pkcs8Password, kdfCount, destination, out bytesWritten);
94 }
95
97 {
98 return Key.Handle;
99 }
100
101 public DSACng()
102 : this(s_defaultKeySize)
103 {
104 }
105
106 public DSACng(int keySize)
107 {
109 KeySize = keySize;
110 }
111
112 protected override byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm)
113 {
114 return Internal.Cryptography.CngCommon.HashData(data, offset, count, hashAlgorithm);
115 }
116
117 protected override byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm)
118 {
119 return Internal.Cryptography.CngCommon.HashData(data, hashAlgorithm);
120 }
121
122 protected override bool TryHashData(ReadOnlySpan<byte> source, Span<byte> destination, HashAlgorithmName hashAlgorithm, out int bytesWritten)
123 {
124 return Internal.Cryptography.CngCommon.TryHashData(source, destination, hashAlgorithm, out bytesWritten);
125 }
126
127 private void ForceSetKeySize(int newKeySize)
128 {
129 KeySizeValue = newKeySize;
130 }
131
132 private static bool Supports2048KeySize()
133 {
134 Version version = Environment.OSVersion.Version;
135 return version.Major > 6 || (version.Major == 6 && version.Minor >= 2);
136 }
137
138 public override void ImportParameters(DSAParameters parameters)
139 {
140 if (parameters.P == null || parameters.Q == null || parameters.G == null || parameters.Y == null)
141 {
143 }
144 if (parameters.J != null && parameters.J.Length >= parameters.P.Length)
145 {
147 }
148 bool flag = parameters.X != null;
149 int num = parameters.P.Length;
150 int num2 = num * 8;
151 if (parameters.G.Length != num || parameters.Y.Length != num)
152 {
154 }
155 if (flag && parameters.X.Length != parameters.Q.Length)
156 {
158 }
159 byte[] blob;
160 if (num2 <= 1024)
161 {
162 GenerateV1DsaBlob(out blob, parameters, num, flag);
163 }
164 else
165 {
166 GenerateV2DsaBlob(out blob, parameters, num, flag);
167 }
168 ImportKeyBlob(blob, flag);
169 }
170
171 public override void ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<byte> passwordBytes, ReadOnlySpan<byte> source, out int bytesRead)
172 {
174 base.ImportEncryptedPkcs8PrivateKey(passwordBytes, source, out bytesRead);
175 }
176
177 public override void ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<char> password, ReadOnlySpan<byte> source, out int bytesRead)
178 {
180 base.ImportEncryptedPkcs8PrivateKey(password, source, out bytesRead);
181 }
182
183 public override byte[] ExportEncryptedPkcs8PrivateKey(ReadOnlySpan<byte> passwordBytes, PbeParameters pbeParameters)
184 {
185 if (pbeParameters == null)
186 {
187 throw new ArgumentNullException("pbeParameters");
188 }
189 return System.Security.Cryptography.CngPkcs8.ExportEncryptedPkcs8PrivateKey(this, passwordBytes, pbeParameters);
190 }
191
192 public override byte[] ExportEncryptedPkcs8PrivateKey(ReadOnlySpan<char> password, PbeParameters pbeParameters)
193 {
194 if (pbeParameters == null)
195 {
196 throw new ArgumentNullException("pbeParameters");
197 }
200 {
201 return ExportEncryptedPkcs8(password, pbeParameters.IterationCount);
202 }
203 return System.Security.Cryptography.CngPkcs8.ExportEncryptedPkcs8PrivateKey(this, password, pbeParameters);
204 }
205
206 public override bool TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<byte> passwordBytes, PbeParameters pbeParameters, Span<byte> destination, out int bytesWritten)
207 {
208 if (pbeParameters == null)
209 {
210 throw new ArgumentNullException("pbeParameters");
211 }
213 return System.Security.Cryptography.CngPkcs8.TryExportEncryptedPkcs8PrivateKey(this, passwordBytes, pbeParameters, destination, out bytesWritten);
214 }
215
216 public override bool TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<char> password, PbeParameters pbeParameters, Span<byte> destination, out int bytesWritten)
217 {
218 if (pbeParameters == null)
219 {
220 throw new ArgumentNullException("pbeParameters");
221 }
224 {
225 return TryExportEncryptedPkcs8(password, pbeParameters.IterationCount, destination, out bytesWritten);
226 }
227 return System.Security.Cryptography.CngPkcs8.TryExportEncryptedPkcs8PrivateKey(this, password, pbeParameters, destination, out bytesWritten);
228 }
229
230 private unsafe static void GenerateV1DsaBlob(out byte[] blob, DSAParameters parameters, int cbKey, bool includePrivate)
231 {
232 int num = sizeof(global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB) + cbKey + cbKey + cbKey;
233 if (includePrivate)
234 {
235 num += 20;
236 }
237 blob = new byte[num];
238 fixed (byte* ptr = &blob[0])
239 {
240 global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB* ptr2 = (global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB*)ptr;
241 ptr2->Magic = (includePrivate ? global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_DSA_PRIVATE_MAGIC : global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_DSA_PUBLIC_MAGIC);
242 ptr2->cbKey = cbKey;
243 int offset = 8;
244 if (parameters.Seed != null)
245 {
246 if (parameters.Seed.Length != 20)
247 {
249 }
250 global::Interop.BCrypt.EmitBigEndian(blob, ref offset, parameters.Counter);
251 global::Interop.BCrypt.Emit(blob, ref offset, parameters.Seed);
252 }
253 else
254 {
255 global::Interop.BCrypt.EmitByte(blob, ref offset, byte.MaxValue, 24);
256 }
257 if (parameters.Q.Length != 20)
258 {
260 }
261 global::Interop.BCrypt.Emit(blob, ref offset, parameters.Q);
262 global::Interop.BCrypt.Emit(blob, ref offset, parameters.P);
263 global::Interop.BCrypt.Emit(blob, ref offset, parameters.G);
264 global::Interop.BCrypt.Emit(blob, ref offset, parameters.Y);
265 if (includePrivate)
266 {
267 global::Interop.BCrypt.Emit(blob, ref offset, parameters.X);
268 }
269 }
270 }
271
272 private unsafe static void GenerateV2DsaBlob(out byte[] blob, DSAParameters parameters, int cbKey, bool includePrivateParameters)
273 {
274 int num = sizeof(global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB_V2) + ((parameters.Seed == null) ? parameters.Q.Length : parameters.Seed.Length) + parameters.Q.Length + parameters.P.Length + parameters.G.Length + parameters.Y.Length + (includePrivateParameters ? parameters.X.Length : 0);
275 blob = new byte[num];
276 fixed (byte* ptr = &blob[0])
277 {
278 global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB_V2* ptr2 = (global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB_V2*)ptr;
279 ptr2->Magic = (includePrivateParameters ? global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_DSA_PRIVATE_MAGIC_V2 : global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_DSA_PUBLIC_MAGIC_V2);
280 ptr2->cbKey = cbKey;
281 ptr2->hashAlgorithm = parameters.Q.Length switch
282 {
283 20 => global::Interop.BCrypt.HASHALGORITHM_ENUM.DSA_HASH_ALGORITHM_SHA1,
284 32 => global::Interop.BCrypt.HASHALGORITHM_ENUM.DSA_HASH_ALGORITHM_SHA256,
285 64 => global::Interop.BCrypt.HASHALGORITHM_ENUM.DSA_HASH_ALGORITHM_SHA512,
287 };
288 ptr2->standardVersion = global::Interop.BCrypt.DSAFIPSVERSION_ENUM.DSA_FIPS186_3;
289 int offset = sizeof(global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB_V2) - 4;
290 if (parameters.Seed != null)
291 {
292 global::Interop.BCrypt.EmitBigEndian(blob, ref offset, parameters.Counter);
293 ptr2->cbSeedLength = parameters.Seed.Length;
294 ptr2->cbGroupSize = parameters.Q.Length;
295 global::Interop.BCrypt.Emit(blob, ref offset, parameters.Seed);
296 }
297 else
298 {
299 global::Interop.BCrypt.EmitByte(blob, ref offset, byte.MaxValue, 4);
300 int count = (ptr2->cbSeedLength = parameters.Q.Length);
301 ptr2->cbGroupSize = parameters.Q.Length;
302 global::Interop.BCrypt.EmitByte(blob, ref offset, byte.MaxValue, count);
303 }
304 global::Interop.BCrypt.Emit(blob, ref offset, parameters.Q);
305 global::Interop.BCrypt.Emit(blob, ref offset, parameters.P);
306 global::Interop.BCrypt.Emit(blob, ref offset, parameters.G);
307 global::Interop.BCrypt.Emit(blob, ref offset, parameters.Y);
308 if (includePrivateParameters)
309 {
310 global::Interop.BCrypt.Emit(blob, ref offset, parameters.X);
311 }
312 }
313 }
314
315 public unsafe override DSAParameters ExportParameters(bool includePrivateParameters)
316 {
317 byte[] array = ExportKeyBlob(includePrivateParameters);
318 global::Interop.BCrypt.KeyBlobMagicNumber keyBlobMagicNumber = (global::Interop.BCrypt.KeyBlobMagicNumber)BitConverter.ToInt32(array, 0);
319 CheckMagicValueOfKey(keyBlobMagicNumber, includePrivateParameters);
320 DSAParameters result = default(DSAParameters);
321 fixed (byte* ptr = array)
322 {
323 if (keyBlobMagicNumber == global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_DSA_PUBLIC_MAGIC || keyBlobMagicNumber == global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_DSA_PRIVATE_MAGIC)
324 {
325 if (array.Length < sizeof(global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB))
326 {
327 throw global::Interop.NCrypt.ErrorCode.E_FAIL.ToCryptographicException();
328 }
329 global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB* ptr2 = (global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB*)ptr;
330 int offset = 8;
331 result.Counter = BinaryPrimitives.ReadInt32BigEndian(global::Interop.BCrypt.Consume(array, ref offset, 4));
332 result.Seed = global::Interop.BCrypt.Consume(array, ref offset, 20);
333 result.Q = global::Interop.BCrypt.Consume(array, ref offset, 20);
334 result.P = global::Interop.BCrypt.Consume(array, ref offset, ptr2->cbKey);
335 result.G = global::Interop.BCrypt.Consume(array, ref offset, ptr2->cbKey);
336 result.Y = global::Interop.BCrypt.Consume(array, ref offset, ptr2->cbKey);
337 if (includePrivateParameters)
338 {
339 result.X = global::Interop.BCrypt.Consume(array, ref offset, 20);
340 }
341 }
342 else
343 {
344 if (array.Length < sizeof(global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB_V2))
345 {
346 throw global::Interop.NCrypt.ErrorCode.E_FAIL.ToCryptographicException();
347 }
348 global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB_V2* ptr3 = (global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB_V2*)ptr;
349 int offset = sizeof(global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB_V2) - 4;
350 result.Counter = BinaryPrimitives.ReadInt32BigEndian(global::Interop.BCrypt.Consume(array, ref offset, 4));
351 result.Seed = global::Interop.BCrypt.Consume(array, ref offset, ptr3->cbSeedLength);
352 result.Q = global::Interop.BCrypt.Consume(array, ref offset, ptr3->cbGroupSize);
353 result.P = global::Interop.BCrypt.Consume(array, ref offset, ptr3->cbKey);
354 result.G = global::Interop.BCrypt.Consume(array, ref offset, ptr3->cbKey);
355 result.Y = global::Interop.BCrypt.Consume(array, ref offset, ptr3->cbKey);
356 if (includePrivateParameters)
357 {
358 result.X = global::Interop.BCrypt.Consume(array, ref offset, ptr3->cbGroupSize);
359 }
360 }
361 if (result.Counter == -1)
362 {
363 result.Counter = 0;
364 result.Seed = null;
365 }
366 return result;
367 }
368 }
369
370 private static void CheckMagicValueOfKey(global::Interop.BCrypt.KeyBlobMagicNumber magic, bool includePrivateParameters)
371 {
372 if (includePrivateParameters)
373 {
374 if (magic != global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_DSA_PRIVATE_MAGIC && magic != global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_DSA_PRIVATE_MAGIC_V2)
375 {
377 }
378 }
379 else if (magic != global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_DSA_PUBLIC_MAGIC && magic != global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_DSA_PUBLIC_MAGIC_V2)
380 {
382 }
383 }
384
385 public unsafe override byte[] CreateSignature(byte[] rgbHash)
386 {
387 if (rgbHash == null)
388 {
389 throw new ArgumentNullException("rgbHash");
390 }
391 Span<byte> stackBuf = stackalloc byte[32];
392 ReadOnlySpan<byte> hash = AdjustHashSizeIfNecessary(rgbHash, stackBuf);
394 return keyHandle.SignHash(hash, global::Interop.NCrypt.AsymmetricPaddingMode.None, null, hash.Length * 2);
395 }
396
397 public unsafe override bool TryCreateSignature(ReadOnlySpan<byte> hash, Span<byte> destination, out int bytesWritten)
398 {
399 Span<byte> stackBuf = stackalloc byte[32];
400 ReadOnlySpan<byte> hash2 = AdjustHashSizeIfNecessary(hash, stackBuf);
401 using (SafeNCryptKeyHandle keyHandle = GetDuplicatedKeyHandle())
402 {
403 if (!keyHandle.TrySignHash(hash2, destination, global::Interop.NCrypt.AsymmetricPaddingMode.None, null, out bytesWritten))
404 {
405 bytesWritten = 0;
406 return false;
407 }
408 }
409 return true;
410 }
411
412 public override bool VerifySignature(byte[] rgbHash, byte[] rgbSignature)
413 {
414 if (rgbHash == null)
415 {
416 throw new ArgumentNullException("rgbHash");
417 }
418 if (rgbSignature == null)
419 {
420 throw new ArgumentNullException("rgbSignature");
421 }
422 return VerifySignature((ReadOnlySpan<byte>)rgbHash, (ReadOnlySpan<byte>)rgbSignature);
423 }
424
425 public unsafe override bool VerifySignature(ReadOnlySpan<byte> hash, ReadOnlySpan<byte> signature)
426 {
427 Span<byte> stackBuf = stackalloc byte[32];
428 ReadOnlySpan<byte> hash2 = AdjustHashSizeIfNecessary(hash, stackBuf);
430 return keyHandle.VerifyHash(hash2, signature, global::Interop.NCrypt.AsymmetricPaddingMode.None, null);
431 }
432
434 {
435 int num = ComputeQLength();
436 if (num == hash.Length)
437 {
438 return hash;
439 }
440 if (num < hash.Length)
441 {
442 return hash.Slice(0, num);
443 }
444 int num2 = num - hash.Length;
445 stackBuf.Slice(0, num2).Clear();
446 hash.CopyTo(stackBuf.Slice(num2));
447 return stackBuf.Slice(0, num);
448 }
449
450 private unsafe int ComputeQLength()
451 {
452 byte[] array;
453 using (GetDuplicatedKeyHandle())
454 {
455 array = ExportKeyBlob(includePrivateParameters: false);
456 }
457 if (array.Length < sizeof(global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB_V2))
458 {
459 return 20;
460 }
461 fixed (byte* ptr = array)
462 {
463 global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB_V2* ptr2 = (global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB_V2*)ptr;
464 if (ptr2->Magic != global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_DSA_PUBLIC_MAGIC_V2 && ptr2->Magic != global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_DSA_PRIVATE_MAGIC_V2)
465 {
466 return 20;
467 }
468 return ptr2->cbGroupSize;
469 }
470 }
471}
static byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm)
Definition CngCommon.cs:10
static bool TryHashData(ReadOnlySpan< byte > source, Span< byte > destination, HashAlgorithmName hashAlgorithm, out int bytesWritten)
Definition CngCommon.cs:17
static int ToInt32(byte[] value, int startIndex)
static int ReadInt32BigEndian(ReadOnlySpan< byte > source)
static OperatingSystem OSVersion
static string Cryptography_InvalidDsaParameters_MismatchedPJ
Definition SR.cs:76
static string Cryptography_NotValidPrivateKey
Definition SR.cs:120
static string Cryptography_InvalidDsaParameters_QRestriction_ShortKey
Definition SR.cs:80
static string Cryptography_InvalidDsaParameters_QRestriction_LargeKey
Definition SR.cs:82
static string Cryptography_ArgDSARequiresDSAKey
Definition SR.cs:34
static string Cryptography_NotValidPublicOrPrivateKey
Definition SR.cs:122
static string Cryptography_InvalidDsaParameters_MismatchedQX
Definition SR.cs:74
static string Cryptography_InvalidDsaParameters_MismatchedPGY
Definition SR.cs:72
static string Cryptography_InvalidDsaParameters_MissingFields
Definition SR.cs:70
static string Cryptography_InvalidDsaParameters_SeedRestriction_ShortKey
Definition SR.cs:78
Definition SR.cs:7
bool TryExportKeyBlob(string blobType, Span< byte > destination, out int bytesWritten)
Definition CngKey.cs:643
byte[] Export(CngKeyBlobFormat format)
Definition CngKey.cs:622
byte[] ExportPkcs8KeyBlob(ReadOnlySpan< char > password, int kdfCount)
Definition CngKey.cs:665
static CngKey Import(ReadOnlySpan< byte > keyBlob, CngKeyBlobFormat format)
Definition CngKey.cs:525
bool TryExportPkcs8KeyBlob(ReadOnlySpan< char > password, int kdfCount, Span< byte > destination, out int bytesWritten)
Definition CngKey.cs:673
SafeNCryptKeyHandle Handle
Definition CngKey.cs:51
static bool IsPlatformScheme(PbeParameters pbeParameters)
Definition CngPkcs8.cs:44
static byte[] ExportEncryptedPkcs8PrivateKey(AsymmetricAlgorithm key, ReadOnlySpan< byte > passwordBytes, PbeParameters pbeParameters)
Definition CngPkcs8.cs:53
static bool TryExportEncryptedPkcs8PrivateKey(AsymmetricAlgorithm key, ReadOnlySpan< byte > passwordBytes, PbeParameters pbeParameters, Span< byte > destination, out int bytesWritten)
Definition CngPkcs8.cs:68
override? string KeyExchangeAlgorithm
Definition DSACng.cs:42
static readonly KeySizes[] s_legalKeySizes
Definition DSACng.cs:14
override byte[] ExportEncryptedPkcs8PrivateKey(ReadOnlySpan< byte > passwordBytes, PbeParameters pbeParameters)
Definition DSACng.cs:183
unsafe override byte[] CreateSignature(byte[] rgbHash)
Definition DSACng.cs:385
static unsafe void GenerateV2DsaBlob(out byte[] blob, DSAParameters parameters, int cbKey, bool includePrivateParameters)
Definition DSACng.cs:272
static readonly int s_defaultKeySize
Definition DSACng.cs:19
override void Dispose(bool disposing)
Definition DSACng.cs:57
override bool TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan< byte > passwordBytes, PbeParameters pbeParameters, Span< byte > destination, out int bytesWritten)
Definition DSACng.cs:206
bool TryExportEncryptedPkcs8(ReadOnlySpan< char > pkcs8Password, int kdfCount, Span< byte > destination, out int bytesWritten)
Definition DSACng.cs:91
override byte[] ExportEncryptedPkcs8PrivateKey(ReadOnlySpan< char > password, PbeParameters pbeParameters)
Definition DSACng.cs:192
override KeySizes[] LegalKeySizes
Definition DSACng.cs:38
override void ImportEncryptedPkcs8PrivateKey(ReadOnlySpan< byte > passwordBytes, ReadOnlySpan< byte > source, out int bytesRead)
Definition DSACng.cs:171
override void ImportParameters(DSAParameters parameters)
Definition DSACng.cs:138
static void CheckMagicValueOfKey(global::Interop.BCrypt.KeyBlobMagicNumber magic, bool includePrivateParameters)
Definition DSACng.cs:370
override string SignatureAlgorithm
Definition DSACng.cs:40
ReadOnlySpan< byte > AdjustHashSizeIfNecessary(ReadOnlySpan< byte > hash, Span< byte > stackBuf)
Definition DSACng.cs:433
override bool TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan< char > password, PbeParameters pbeParameters, Span< byte > destination, out int bytesWritten)
Definition DSACng.cs:216
unsafe override bool TryCreateSignature(ReadOnlySpan< byte > hash, Span< byte > destination, out int bytesWritten)
Definition DSACng.cs:397
void ForceSetKeySize(int newKeySize)
Definition DSACng.cs:127
override bool VerifySignature(byte[] rgbHash, byte[] rgbSignature)
Definition DSACng.cs:412
readonly CngAlgorithm _dsnCng
Definition DSACng.cs:12
SafeNCryptKeyHandle GetDuplicatedKeyHandle()
Definition DSACng.cs:96
byte[] ExportEncryptedPkcs8(ReadOnlySpan< char > pkcs8Password, int kdfCount)
Definition DSACng.cs:86
void ImportKeyBlob(byte[] dsaBlob, bool includePrivate)
Definition DSACng.cs:73
unsafe override DSAParameters ExportParameters(bool includePrivateParameters)
Definition DSACng.cs:315
override void ImportEncryptedPkcs8PrivateKey(ReadOnlySpan< char > password, ReadOnlySpan< byte > source, out int bytesRead)
Definition DSACng.cs:177
unsafe override bool VerifySignature(ReadOnlySpan< byte > hash, ReadOnlySpan< byte > signature)
Definition DSACng.cs:425
override bool TryHashData(ReadOnlySpan< byte > source, Span< byte > destination, HashAlgorithmName hashAlgorithm, out int bytesWritten)
Definition DSACng.cs:122
byte[] ExportKeyBlob(bool includePrivateParameters)
Definition DSACng.cs:67
override byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm)
Definition DSACng.cs:117
override byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm)
Definition DSACng.cs:112
static unsafe void GenerateV1DsaBlob(out byte[] blob, DSAParameters parameters, int cbKey, bool includePrivate)
Definition DSACng.cs:230
override bool TryExportPkcs8PrivateKey(Span< byte > destination, out int bytesWritten)
Definition DSACng.cs:81
static void ValidatePbeParameters(PbeParameters pbeParameters, ReadOnlySpan< char > password, ReadOnlySpan< byte > passwordBytes)
CngKey GetOrGenerateKey(int keySize, CngAlgorithm algorithm)
void CopyTo(Span< T > destination)
ReadOnlySpan< T > Slice(int start)
Span< T > Slice(int start)
Definition Span.cs:271