Skip to content

Commit 017acc9

Browse files
bartonjsThraka
authored andcommitted
Add missing asymmetric key import/export documentation (#2862)
* Add missing asymmetric key import/export documentation This includes both: * Overrides of AsymmetricAlgorithm methods * New algorithm-specific formats * Fix incorrect reference to pbeParameters on ImportEncrypted
1 parent cf7d85c commit 017acc9

File tree

4 files changed

+794
-214
lines changed

4 files changed

+794
-214
lines changed

xml/System.Security.Cryptography/DSA.xml

Lines changed: 166 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,42 @@
491491
<Parameter Name="bytesRead" Type="System.Int32" RefType="out" Index="2" FrameworkAlternate="netcore-3.0" />
492492
</Parameters>
493493
<Docs>
494-
<param name="passwordBytes">To be added.</param>
495-
<param name="source">To be added.</param>
496-
<param name="bytesRead">To be added.</param>
497-
<summary>To be added.</summary>
498-
<remarks>To be added.</remarks>
494+
<param name="passwordBytes">The bytes to use as a password when decrypting the key material.</param>
495+
<param name="source">The bytes of a PKCS#8 EncryptedPrivateKeyInfo structure in the ASN.1-BER encoding.</param>
496+
<param name="bytesRead">When this method returns, contains a value that indicates the number of bytes read from <paramref name="source"/>. This parameter is treated as uninitialized.</param>
497+
<summary>Imports the public/private keypair from a PKCS#8 EncryptedPrivateKeyInfo structure after decrypting with a byte-based password, replacing the keys for this object.</summary>
498+
<remarks>
499+
<format type="text/markdown"><![CDATA[
500+
501+
## Remarks
502+
The password bytes are passed directly into the Key Derivation Function (KDF) used by the algorithm indicated by the EncryptedPrivateKeyInfo contents.
503+
This enables compatibility with other systems which use a text encoding other than UTF-8 when processing passwords with PBKDF2 (Password-Based Key Derivation Function 2).
504+
This method only supports the binary (BER/CER/DER) encoding of EncryptedPrivateKeyInfo.
505+
If the value is Base64-encoded or in the PEM text format, the caller must Base64-decode the contents before calling this method.
506+
]]></format>
507+
</remarks>
508+
<exception cref="T:System.Security.Cryptography.CryptographicException">The password is incorrect.
509+
510+
-or-
511+
512+
The contents of <paramref name="source"/> indicate the Key Derivation Function (KDF) to apply is the legacy PKCS#12 KDF, which requires <see cref="T:System.Char"/>-based passwords.
513+
514+
-or-
515+
516+
The contents of <paramref name="source"/> do not represent an ASN.1-BER-encoded PKCS#8 EncryptedPrivateKeyInfo structure.
517+
518+
-or-
519+
520+
The contents of <paramref name="source"/> indicate the key is for an algorithm other than the algorithm represented by this instance.
521+
522+
-or-
523+
524+
The contents of <paramref name="source"/> represent the key in a format that is not supported.
525+
526+
-or-
527+
528+
The algorithm-specific key import failed.
529+
</exception>
499530
</Docs>
500531
</Member>
501532
<Member MemberName="ImportEncryptedPkcs8PrivateKey">
@@ -525,11 +556,37 @@
525556
<Parameter Name="bytesRead" Type="System.Int32" RefType="out" Index="2" FrameworkAlternate="netcore-3.0" />
526557
</Parameters>
527558
<Docs>
528-
<param name="password">To be added.</param>
529-
<param name="source">To be added.</param>
530-
<param name="bytesRead">To be added.</param>
531-
<summary>To be added.</summary>
532-
<remarks>To be added.</remarks>
559+
<param name="password">The password to use for decrypting the key material.</param>
560+
<param name="source">The bytes of a PKCS#8 EncryptedPrivateKeyInfo structure in the ASN.1-BER encoding.</param>
561+
<param name="bytesRead">When this method returns, contains a value that indicates the number of bytes read from <paramref name="source"/>. This parameter is treated as uninitialized.</param>
562+
<summary>Imports the public/private keypair from a PKCS#8 EncryptedPrivateKeyInfo structure after decrypting with a char-based password, replacing the keys for this object.</summary>
563+
<remarks>
564+
<format type="text/markdown"><![CDATA[
565+
566+
## Remarks
567+
When the contents of `source` indicate an algorithm that uses PBKDF1 (Password-Based Key Derivation Function 1) or PBKDF2 (Password-Based Key Derivation Function 2), the password is converted to bytes via the UTF-8 encoding.
568+
This method only supports the binary (BER/CER/DER) encoding of EncryptedPrivateKeyInfo.
569+
If the value is Base64-encoded or in the PEM text format, the caller must Base64-decode the contents before calling this method.
570+
]]></format>
571+
</remarks>
572+
<exception cref="T:System.Security.Cryptography.CryptographicException">The password is incorrect.
573+
574+
-or-
575+
576+
The contents of <paramref name="source"/> do not represent an ASN.1-BER-encoded PKCS#8 EncryptedPrivateKeyInfo structure.
577+
578+
-or-
579+
580+
The contents of <paramref name="source"/> indicate the key is for an algorithm other than the algorithm represented by this instance.
581+
582+
-or-
583+
584+
The contents of <paramref name="source"/> represent the key in a format that is not supported.
585+
586+
-or-
587+
588+
The algorithm-specific key import failed.
589+
</exception>
533590
</Docs>
534591
</Member>
535592
<Member MemberName="ImportParameters">
@@ -596,10 +653,31 @@
596653
<Parameter Name="bytesRead" Type="System.Int32" RefType="out" Index="1" FrameworkAlternate="netcore-3.0" />
597654
</Parameters>
598655
<Docs>
599-
<param name="source">To be added.</param>
600-
<param name="bytesRead">To be added.</param>
601-
<summary>To be added.</summary>
602-
<remarks>To be added.</remarks>
656+
<param name="source">The bytes of a PKCS#8 PrivateKeyInfo structure in the ASN.1-BER encoding.</param>
657+
<param name="bytesRead">When this method returns, contains a value that indicates the number of bytes read from <paramref name="source"/>. This parameter is treated as uninitialized.</param>
658+
<summary>Imports the public/private keypair from a PKCS#8 PrivateKeyInfo structure after decryption, replacing the keys for this object.</summary>
659+
<remarks>
660+
<format type="text/markdown"><![CDATA[
661+
662+
## Remarks
663+
This method only supports the binary (BER/CER/DER) encoding of PrivateKeyInfo.
664+
If the value is Base64-encoded or in the PEM text format, the caller must Base64-decode the contents before calling this method.
665+
]]></format>
666+
</remarks>
667+
<exception cref="T:System.Security.Cryptography.CryptographicException">The contents of <paramref name="source"/> do not represent an ASN.1-BER-encoded PKCS#8 PrivateKeyInfo structure.
668+
669+
-or-
670+
671+
The contents of <paramref name="source"/> indicate the key is for an algorithm other than the algorithm represented by this instance.
672+
673+
-or-
674+
675+
The contents of <paramref name="source"/> represent the key in a format that is not supported.
676+
677+
-or-
678+
679+
The algorithm-specific key import failed.
680+
</exception>
603681
</Docs>
604682
</Member>
605683
<Member MemberName="ImportSubjectPublicKeyInfo">
@@ -628,10 +706,31 @@
628706
<Parameter Name="bytesRead" Type="System.Int32" RefType="out" Index="1" FrameworkAlternate="netcore-3.0" />
629707
</Parameters>
630708
<Docs>
631-
<param name="source">To be added.</param>
632-
<param name="bytesRead">To be added.</param>
633-
<summary>To be added.</summary>
634-
<remarks>To be added.</remarks>
709+
<param name="source">The bytes of an X.509 SubjectPublicKeyInfo structure in the ASN.1-DER encoding.</param>
710+
<param name="bytesRead">When this method returns, contains a value that indicates the number of bytes read from <paramref name="source"/>. This parameter is treated as uninitialized.</param>
711+
<summary>Imports the public key from an X.509 SubjectPublicKeyInfo structure after decryption, replacing the keys for this object.</summary>
712+
<remarks>
713+
<format type="text/markdown"><![CDATA[
714+
715+
## Remarks
716+
This method only supports the binary (DER) encoding of SubjectPublicKeyInfo.
717+
If the value is Base64-encoded or in the PEM text format, the caller must Base64-decode the contents before calling this method.
718+
]]></format>
719+
</remarks>
720+
<exception cref="T:System.Security.Cryptography.CryptographicException">The contents of <paramref name="source"/> do not represent an ASN.1-DER-encoded X.509 SubjectPublicKeyInfo structure.
721+
722+
-or-
723+
724+
The contents of <paramref name="source"/> indicate the key is for an algorithm other than the algorithm represented by this instance.
725+
726+
-or-
727+
728+
The contents of <paramref name="source"/> represent the key in a format that is not supported.
729+
730+
-or-
731+
732+
The algorithm-specific key import failed.
733+
</exception>
635734
</Docs>
636735
</Member>
637736
<MemberGroup MemberName="SignData">
@@ -901,13 +1000,27 @@ Creating the signature otherwise failed.</exception>
9011000
<Parameter Name="bytesWritten" Type="System.Int32" RefType="out" Index="3" FrameworkAlternate="netcore-3.0" />
9021001
</Parameters>
9031002
<Docs>
904-
<param name="passwordBytes">To be added.</param>
905-
<param name="pbeParameters">To be added.</param>
906-
<param name="destination">To be added.</param>
907-
<param name="bytesWritten">To be added.</param>
908-
<summary>To be added.</summary>
909-
<returns>To be added.</returns>
910-
<remarks>To be added.</remarks>
1003+
<param name="passwordBytes">The bytes to use as a password when encrypting the key material.</param>
1004+
<param name="pbeParameters">The password-based encryption (PBE) parameters to use when encrypting the key material.</param>
1005+
<param name="destination">The byte span to receive the PKCS#8 EncryptedPrivateKeyInfo data.</param>
1006+
<param name="bytesWritten">When this method returns, contains a value that indicates the number of bytes written to <paramref name="destination"/>. This parameter is treated as uninitialized.</param>
1007+
<summary>Attempts to export the current key in the PKCS#8 EncryptedPrivateKeyInfo format into a provided buffer, using a byte-based password.</summary>
1008+
<returns><see langword="true"/> if <paramref name="destination"/> is big enough to receive the output; otherwise, <see langword="false"/>.</returns>
1009+
<remarks>
1010+
<format type="text/markdown"><![CDATA[
1011+
1012+
## Remarks
1013+
The password bytes are passed directly into the Key Derivation Function (KDF) used by the algorithm indicated by `pbeParameters`.
1014+
This enables compatibility with other systems which use a text encoding other than UTF-8 when processing passwords with PBKDF2 (Password-Based Key Derivation Function 2).
1015+
]]></format>
1016+
</remarks>
1017+
<exception cref="T:System.Security.Cryptography.CryptographicException">The key could not be exported.
1018+
1019+
-or-
1020+
1021+
<paramref name="pbeParameters"/> indicates that <see cref="F:System.Security.Cryptography.PbeEncryptionAlgorithm.TripleDes3KeyPkcs12"/> should be used, which requires <see cref="T:System.Char"/>-based passwords.
1022+
</exception>
1023+
<altmember cref="Overload:System.Security.Cryptography.AsymmetricAlgorithm.ExportEncryptedPkcs8PrivateKey" />
9111024
</Docs>
9121025
</Member>
9131026
<Member MemberName="TryExportEncryptedPkcs8PrivateKey">
@@ -937,13 +1050,21 @@ Creating the signature otherwise failed.</exception>
9371050
<Parameter Name="bytesWritten" Type="System.Int32" RefType="out" Index="3" FrameworkAlternate="netcore-3.0" />
9381051
</Parameters>
9391052
<Docs>
940-
<param name="password">To be added.</param>
941-
<param name="pbeParameters">To be added.</param>
942-
<param name="destination">To be added.</param>
943-
<param name="bytesWritten">To be added.</param>
944-
<summary>To be added.</summary>
945-
<returns>To be added.</returns>
946-
<remarks>To be added.</remarks>
1053+
<param name="password">The password to use when encrypting the key material.</param>
1054+
<param name="pbeParameters">The password-based encryption (PBE) parameters to use when encrypting the key material.</param>
1055+
<param name="destination">The byte span to receive the PKCS#8 EncryptedPrivateKeyInfo data.</param>
1056+
<param name="bytesWritten">When this method returns, contains a value that indicates the number of bytes written to <paramref name="destination"/>. This parameter is treated as uninitialized.</param>
1057+
<summary>Attempts to export the current key in the PKCS#8 EncryptedPrivateKeyInfo format into a provided buffer, using a char-based password.</summary>
1058+
<returns><see langword="true"/> if <paramref name="destination"/> is big enough to receive the output; otherwise, <see langword="false"/>.</returns>
1059+
<remarks>
1060+
<format type="text/markdown"><![CDATA[
1061+
1062+
## Remarks
1063+
When `pbeParameters` indicates an algorithm that uses PBKDF2 (Password-Based Key Derivation Function 2), the password is converted to bytes via the UTF-8 encoding.
1064+
]]></format>
1065+
</remarks>
1066+
<exception cref="T:System.Security.Cryptography.CryptographicException">The key could not be exported.</exception>
1067+
<altmember cref="Overload:System.Security.Cryptography.AsymmetricAlgorithm.ExportEncryptedPkcs8PrivateKey" />
9471068
</Docs>
9481069
</Member>
9491070
<Member MemberName="TryExportPkcs8PrivateKey">
@@ -972,11 +1093,13 @@ Creating the signature otherwise failed.</exception>
9721093
<Parameter Name="bytesWritten" Type="System.Int32" RefType="out" Index="1" FrameworkAlternate="netcore-3.0" />
9731094
</Parameters>
9741095
<Docs>
975-
<param name="destination">To be added.</param>
976-
<param name="bytesWritten">To be added.</param>
977-
<summary>To be added.</summary>
978-
<returns>To be added.</returns>
1096+
<param name="destination">The byte span to receive the PKCS#8 PrivateKeyInfo data.</param>
1097+
<param name="bytesWritten">When this method returns, contains a value that indicates the number of bytes written to <paramref name="destination"/>. This parameter is treated as uninitialized.</param>
1098+
<summary>Attempts to export the current key in the PKCS#8 PrivateKeyInfo format into a provided buffer.</summary>
1099+
<returns><see langword="true"/> if <paramref name="destination"/> is big enough to receive the output; otherwise, <see langword="false"/>.</returns>
9791100
<remarks>To be added.</remarks>
1101+
<exception cref="T:System.Security.Cryptography.CryptographicException">The key could not be exported.</exception>
1102+
<altmember cref="Overload:System.Security.Cryptography.AsymmetricAlgorithm.ExportPkcs8PrivateKey" />
9801103
</Docs>
9811104
</Member>
9821105
<Member MemberName="TryExportSubjectPublicKeyInfo">
@@ -1005,11 +1128,13 @@ Creating the signature otherwise failed.</exception>
10051128
<Parameter Name="bytesWritten" Type="System.Int32" RefType="out" Index="1" FrameworkAlternate="netcore-3.0" />
10061129
</Parameters>
10071130
<Docs>
1008-
<param name="destination">To be added.</param>
1009-
<param name="bytesWritten">To be added.</param>
1010-
<summary>To be added.</summary>
1011-
<returns>To be added.</returns>
1131+
<param name="destination">The byte span to receive the X.509 SubjectPublicKeyInfo data.</param>
1132+
<param name="bytesWritten">When this method returns, contains a value that indicates the number of bytes written to <paramref name="destination"/>. This parameter is treated as uninitialized.</param>
1133+
<summary>Attempts to export the current key in the X.509 SubjectPublicKeyInfo format into a provided buffer.</summary>
1134+
<returns><see langword="true"/> if <paramref name="destination"/> is big enough to receive the output; otherwise, <see langword="false"/>.</returns>
10121135
<remarks>To be added.</remarks>
1136+
<exception cref="T:System.Security.Cryptography.CryptographicException">The key could not be exported.</exception>
1137+
<altmember cref="Overload:System.Security.Cryptography.AsymmetricAlgorithm.ExportSubjectPublicKeyInfo" />
10131138
</Docs>
10141139
</Member>
10151140
<Member MemberName="TryHashData">
@@ -1419,4 +1544,4 @@ Verifying the signature otherwise failed.</exception>
14191544
</Docs>
14201545
</Member>
14211546
</Members>
1422-
</Type>
1547+
</Type>

0 commit comments

Comments
 (0)