15 private uint m_aiPubKey;
17 private byte[] m_cspBlobData;
21 internal uint AlgorithmId
33 private byte[] CspBlobData
37 if (m_cspBlobData ==
null)
39 DecodePublicKeyObject(AlgorithmId, m_encodedKeyValue.RawData, m_encodedParameters.
RawData, out m_cspBlobData);
61 m_key = rSACryptoServiceProvider;
68 m_key = dSACryptoServiceProvider;
101 m_oid =
new Oid(oid);
108 m_oid =
new Oid(publicKey.m_oid);
109 m_encodedParameters =
new AsnEncodedData(publicKey.m_encodedParameters);
110 m_encodedKeyValue =
new AsnEncodedData(publicKey.m_encodedKeyValue);
113 private static void DecodePublicKeyObject(uint aiPubKey,
byte[] encodedKeyValue,
byte[] encodedParameters, out
byte[] decodedData)
132 SafeLocalAllocHandle decodedValue =
null;
133 uint cbDecodedValue = 0u;
134 if (!CAPI.DecodeObject(zero, encodedKeyValue, out decodedValue, out cbDecodedValue))
140 decodedData =
new byte[cbDecodedValue];
141 Marshal.
Copy(decodedValue.DangerousGetHandle(), decodedData, 0, decodedData.Length);
143 else if ((
int)zero == 38)
145 SafeLocalAllocHandle decodedValue2 =
null;
146 uint cbDecodedValue2 = 0u;
147 if (!CAPI.DecodeObject(
new IntPtr(39L), encodedParameters, out decodedValue2, out cbDecodedValue2))
151 decodedData = ConstructDSSPubKeyCspBlob(decodedValue, decodedValue2);
152 decodedValue2.Dispose();
154 decodedValue.Dispose();
157 private static byte[] ConstructDSSPubKeyCspBlob(SafeLocalAllocHandle decodedKeyValue, SafeLocalAllocHandle decodedParameters)
159 CAPIBase.CRYPTOAPI_BLOB cRYPTOAPI_BLOB = (CAPIBase.CRYPTOAPI_BLOB)
Marshal.
PtrToStructure(decodedKeyValue.DangerousGetHandle(), typeof(CAPIBase.CRYPTOAPI_BLOB));
160 CAPIBase.CERT_DSS_PARAMETERS cERT_DSS_PARAMETERS = (CAPIBase.CERT_DSS_PARAMETERS)
Marshal.
PtrToStructure(decodedParameters.DangerousGetHandle(), typeof(CAPIBase.CERT_DSS_PARAMETERS));
161 uint cbData = cERT_DSS_PARAMETERS.p.cbData;
164 throw new CryptographicException(-2146893803);
166 uint capacity = 16 + cbData + 20 + cbData + cbData + 24;
169 binaryWriter.
Write((
byte)6);
170 binaryWriter.
Write((
byte)2);
171 binaryWriter.
Write((
short)0);
172 binaryWriter.
Write(8704u);
173 binaryWriter.
Write(827544388u);
174 binaryWriter.
Write(cbData * 8);
175 byte[] array =
new byte[cERT_DSS_PARAMETERS.p.cbData];
176 Marshal.
Copy(cERT_DSS_PARAMETERS.p.pbData, array, 0, array.Length);
177 binaryWriter.
Write(array);
178 uint cbData2 = cERT_DSS_PARAMETERS.q.cbData;
179 if (cbData2 == 0 || cbData2 > 20)
181 throw new CryptographicException(-2146893803);
183 byte[] array2 =
new byte[cERT_DSS_PARAMETERS.q.cbData];
184 Marshal.
Copy(cERT_DSS_PARAMETERS.q.pbData, array2, 0, array2.Length);
185 binaryWriter.
Write(array2);
188 binaryWriter.
Write(
new byte[20 - cbData2]);
190 cbData2 = cERT_DSS_PARAMETERS.g.cbData;
191 if (cbData2 == 0 || cbData2 > cbData)
193 throw new CryptographicException(-2146893803);
195 byte[] array3 =
new byte[cERT_DSS_PARAMETERS.g.cbData];
196 Marshal.
Copy(cERT_DSS_PARAMETERS.g.pbData, array3, 0, array3.Length);
197 binaryWriter.
Write(array3);
198 if (cbData > cbData2)
200 binaryWriter.
Write(
new byte[cbData - cbData2]);
202 cbData2 = cRYPTOAPI_BLOB.cbData;
203 if (cbData2 == 0 || cbData2 > cbData)
205 throw new CryptographicException(-2146893803);
207 byte[] array4 =
new byte[cRYPTOAPI_BLOB.cbData];
208 Marshal.
Copy(cRYPTOAPI_BLOB.pbData, array4, 0, array4.Length);
209 binaryWriter.
Write(array4);
210 if (cbData > cbData2)
212 binaryWriter.
Write(
new byte[cbData - cbData2]);
214 binaryWriter.
Write(uint.MaxValue);
215 binaryWriter.
Write(
new byte[20]);
Performs asymmetric encryption and decryption using the implementation of the T:System....
Represents Abstract Syntax Notation One (ASN.1)-encoded data.
void ImportCspBlob(byte[] keyBlob)
Imports a blob that represents RSA key information.
Represents a cryptographic object identifier. This class cannot be inherited.
AsnEncodedData EncodedParameters
Gets the ASN.1-encoded representation of the public key parameters.
string Value
Gets or sets the dotted number of the identifier.
Represents a certificate's public key information. This class cannot be inherited.
Oid Oid
Gets an object identifier (OID) object of the public key.
static void Copy(int[] source, int startIndex, IntPtr destination, int length)
Copies data from a one-dimensional, managed 32-bit signed integer array to an unmanaged memory pointe...
Creates a stream whose backing store is memory.To browse the .NET Framework source code for this type...
virtual byte [] ToArray()
Writes the stream contents to a byte array, regardless of the P:System.IO.MemoryStream....
byte [] RawData
Gets or sets the Abstract Syntax Notation One (ASN.1)-encoded data represented in a byte array.
A platform-specific type that is used to represent a pointer or a handle.
Represents the abstract base class from which all implementations of asymmetric algorithms must inher...
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
virtual void Write(bool value)
Writes a one-byte Boolean value to the current stream, with 0 representing false and 1 representing t...
void ImportCspBlob(byte[] keyBlob)
Imports a blob that represents DSA key information.
Defines a wrapper object to access the cryptographic service provider (CSP) implementation of the T:S...
static void PtrToStructure(IntPtr ptr, object structure)
Marshals data from an unmanaged block of memory to a managed object.
PublicKey(Oid oid, AsnEncodedData parameters, AsnEncodedData keyValue)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
static readonly IntPtr Zero
A read-only field that represents a pointer or handle that has been initialized to zero.
AsymmetricAlgorithm Key
Gets an T:System.Security.Cryptography.RSACryptoServiceProvider or T:System.Security....
AsnEncodedData EncodedKeyValue
Gets the ASN.1-encoded representation of the public key value.
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
static int GetLastWin32Error()
Returns the error code returned by the last unmanaged function that was called using platform invoke ...
Writes primitive types in binary to a stream and supports writing strings in a specific encoding.