877 references to CAPI
System.Security (877)
system\security\cryptography\cryptoapi.cs (25)
2298
CAPI
.CRYPTOAPI_BLOB blob = (
CAPI
.CRYPTOAPI_BLOB) Marshal.PtrToStructure(pBlob, typeof(
CAPI
.CRYPTOAPI_BLOB));
2305
internal static byte[] BlobToByteArray(
CAPI
.CRYPTOAPI_BLOB blob) {
2336
ptr =
CAPI
.LocalAlloc(
CAPI
.LMEM_FIXED, new IntPtr(cbDecoded));
2376
pbDecoded =
CAPI
.LocalAlloc(
CAPI
.LMEM_FIXED, new IntPtr(cbDecoded));
2411
pbEncoded =
CAPI
.LocalAlloc(
CAPI
.LMEM_FIXED, new IntPtr(cbEncoded));
2445
pbEncoded =
CAPI
.LocalAlloc(
CAPI
.LMEM_FIXED, new IntPtr(cbEncoded));
2493
parameters.Flags = (CspProviderFlags) ((dwFlags &
CAPI
.CRYPT_MACHINE_KEYSET) ==
CAPI
.CRYPT_MACHINE_KEYSET ? CspProviderFlags.UseMachineKeyStore : 0);
2506
if (!rc && Marshal.GetLastWin32Error() ==
CAPI
.NTE_BAD_KEYSET) {
2511
dwFlags |
CAPI
.CRYPT_NEWKEYSET);
2559
pOIDInfo = (CRYPT_OID_INFO) Marshal.PtrToStructure(pv, typeof(
CAPI
.CRYPT_OID_INFO));
2581
pOIDInfo = (CRYPT_OID_INFO) Marshal.PtrToStructure(pv, typeof(
CAPI
.CRYPT_OID_INFO));
2932
[DllImport(
CAPI
.KERNEL32, SetLastError = true),
2964
[DllImport(
CAPI
.KERNEL32, SetLastError=true),
3024
[DllImport(
CAPI
.ADVAPI32, SetLastError=true),
3080
[DllImport(
CAPI
.CRYPT32, SetLastError=true),
3111
[DllImport(
CAPI
.CRYPT32, SetLastError=true),
3141
[DllImport(
CAPI
.CRYPT32, SetLastError=true),
3171
[DllImport(
CAPI
.CRYPT32, SetLastError=true),
system\security\cryptography\cryptographicattribute.cs (9)
33
internal CryptographicAttributeObject (IntPtr pAttribute) : this((
CAPI
.CRYPT_ATTRIBUTE) Marshal.PtrToStructure(pAttribute, typeof(
CAPI
.CRYPT_ATTRIBUTE))) {}
36
internal CryptographicAttributeObject(
CAPI
.CRYPT_ATTRIBUTE cryptAttribute) :
41
internal CryptographicAttributeObject (
CAPI
.CRYPT_ATTRIBUTE_TYPE_VALUE cryptAttribute) :
88
private CryptographicAttributeObjectCollection (IntPtr pCryptAttributes) : this((
CAPI
.CRYPT_ATTRIBUTES) Marshal.PtrToStructure(pCryptAttributes, typeof(
CAPI
.CRYPT_ATTRIBUTES))) {}
94
internal CryptographicAttributeObjectCollection (
CAPI
.CRYPT_ATTRIBUTES cryptAttributes) {
97
IntPtr pCryptAttribute = new IntPtr((long)cryptAttributes.rgAttr + (index * Marshal.SizeOf(typeof(
CAPI
.CRYPT_ATTRIBUTE))));
165
if (String.Compare(szOid1,
CAPI
.szOID_RSA_signingTime, StringComparison.OrdinalIgnoreCase) == 0)
system\security\cryptography\dataprotection.cs (29)
48
CAPI
.CRYPTOAPI_BLOB blob = new
CAPI
.CRYPTOAPI_BLOB();
53
CAPI
.CRYPTOAPI_BLOB dataIn = new
CAPI
.CRYPTOAPI_BLOB();
56
CAPI
.CRYPTOAPI_BLOB entropy = new
CAPI
.CRYPTOAPI_BLOB();
62
uint dwFlags =
CAPI
.CRYPTPROTECT_UI_FORBIDDEN;
64
dwFlags |=
CAPI
.CRYPTPROTECT_LOCAL_MACHINE;
66
if (!
CAPI
.CryptProtectData(new IntPtr(&dataIn),
79
if (
CAPI
.ErrorMayBeCausedByUnloadedProfile(lastWin32Error)) {
106
CAPI
.CAPISafe.ZeroMemory(blob.pbData, blob.cbData);
107
CAPI
.CAPISafe.LocalFree(blob.pbData);
123
CAPI
.CRYPTOAPI_BLOB userData = new
CAPI
.CRYPTOAPI_BLOB();
128
CAPI
.CRYPTOAPI_BLOB dataIn = new
CAPI
.CRYPTOAPI_BLOB();
131
CAPI
.CRYPTOAPI_BLOB entropy = new
CAPI
.CRYPTOAPI_BLOB();
137
uint dwFlags =
CAPI
.CRYPTPROTECT_UI_FORBIDDEN;
139
dwFlags |=
CAPI
.CRYPTPROTECT_LOCAL_MACHINE;
141
if (!
CAPI
.CryptUnprotectData(new IntPtr(&dataIn),
169
CAPI
.CAPISafe.ZeroMemory(userData.pbData, userData.cbData);
170
CAPI
.CAPISafe.LocalFree(userData.pbData);
192
if ((userData.Length == 0) || (userData.Length %
CAPI
.CRYPTPROTECTMEMORY_BLOCK_SIZE != 0))
198
int status =
CAPI
.SystemFunction040(userData,
202
throw new CryptographicException(
CAPI
.CAPISafe.LsaNtStatusToWinError(status));
223
if ((encryptedData.Length == 0) || (encryptedData.Length %
CAPI
.CRYPTPROTECTMEMORY_BLOCK_SIZE != 0))
229
int status =
CAPI
.SystemFunction041(encryptedData,
233
throw new CryptographicException(
CAPI
.CAPISafe.LsaNtStatusToWinError(status));
system\security\cryptography\pkcs\envelopedpkcs7.cs (222)
70
CAPI
.szOID_RSA_DES_EDE3_CBC :
71
CAPI
.szOID_NIST_AES256_CBC;
78
new ContentInfo(Oid.FromOidValue(
CAPI
.szOID_RSA_data, OidGroup.ExtensionOrAttribute), new byte[0]),
256
int hr =
CAPI
.CRYPT_E_RECIPIENT_NOT_FOUND;
268
if (hr2 ==
CAPI
.S_OK) {
284
CAPI
.CMSG_CTRL_DECRYPT_PARA ctrlDecryptPara = new
CAPI
.CMSG_CTRL_DECRYPT_PARA(Marshal.SizeOf(typeof(
CAPI
.CMSG_CTRL_DECRYPT_PARA)));
289
if (!
CAPI
.CryptMsgControl(m_safeCryptMsgHandle,
291
CAPI
.CMSG_CTRL_DECRYPT,
301
CAPI
.CMSG_CMS_RECIPIENT_INFO cmsRecipientInfo = (
CAPI
.CMSG_CMS_RECIPIENT_INFO) Marshal.PtrToStructure(keyAgree.pCmsgRecipientInfo.DangerousGetHandle(), typeof(
CAPI
.CMSG_CMS_RECIPIENT_INFO));
303
CAPI
.CMSG_CTRL_KEY_AGREE_DECRYPT_PARA keyAgreeDecryptPara = new
CAPI
.CMSG_CTRL_KEY_AGREE_DECRYPT_PARA(Marshal.SizeOf(typeof(
CAPI
.CMSG_CTRL_KEY_AGREE_DECRYPT_PARA)));
311
CAPI
.CMSG_KEY_AGREE_CERT_ID_RECIPIENT_INFO certIdKeyAgree = (
CAPI
.CMSG_KEY_AGREE_CERT_ID_RECIPIENT_INFO) keyAgree.CmsgRecipientInfo;
314
pOriginatorCert =
CAPI
.CertFindCertificateInStore(hCertStore,
315
CAPI
.X509_ASN_ENCODING |
CAPI
.PKCS_7_ASN_ENCODING,
317
CAPI
.CERT_FIND_CERT_ID,
321
hr2 =
CAPI
.CRYPT_E_NOT_FOUND;
325
CAPI
.CERT_CONTEXT pCertContext = (
CAPI
.CERT_CONTEXT) Marshal.PtrToStructure(pOriginatorCert.DangerousGetHandle(), typeof(
CAPI
.CERT_CONTEXT));
326
CAPI
.CERT_INFO certInfo = (
CAPI
.CERT_INFO) Marshal.PtrToStructure(pCertContext.pCertInfo, typeof(
CAPI
.CERT_INFO));
330
CAPI
.CMSG_KEY_AGREE_PUBLIC_KEY_RECIPIENT_INFO publicKeyAgree = (
CAPI
.CMSG_KEY_AGREE_PUBLIC_KEY_RECIPIENT_INFO) keyAgree.CmsgRecipientInfo;
334
if (!
CAPI
.CryptMsgControl(m_safeCryptMsgHandle,
336
CAPI
.CMSG_CTRL_KEY_AGREE_DECRYPT,
345
throw new CryptographicException(
CAPI
.E_NOTIMPL);
352
if (hr2 ==
CAPI
.S_OK) {
357
PkcsUtils.GetParam(m_safeCryptMsgHandle,
CAPI
.CMSG_CONTENT_PARAM, 0, out pbContent, out cbContent);
369
hr =
CAPI
.S_OK;
378
if (hr !=
CAPI
.S_OK)
389
throw new CryptographicException(
CAPI
.CRYPT_E_RECIPIENT_NOT_FOUND);
410
CAPI
.CMSG_ENVELOPED_ENCODE_INFO encodeInfo = new
CAPI
.CMSG_ENVELOPED_ENCODE_INFO(Marshal.SizeOf(typeof(
CAPI
.CMSG_ENVELOPED_ENCODE_INFO)));
411
SafeLocalAllocHandle ceei =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(Marshal.SizeOf(typeof(
CAPI
.CMSG_ENVELOPED_ENCODE_INFO))));
443
SafeCryptMsgHandle safeCryptMsgHandle =
CAPI
.CryptMsgOpenToEncode(
CAPI
.X509_ASN_ENCODING |
CAPI
.PKCS_7_ASN_ENCODING,
445
CAPI
.CMSG_ENVELOPED,
459
Marshal.DestroyStructure(ceei.DangerousGetHandle(), typeof(
CAPI
.CMSG_ENVELOPED_ENCODE_INFO));
464
if (String.Compare(this.ContentInfo.ContentType.Value,
CAPI
.szOID_RSA_data, StringComparison.OrdinalIgnoreCase) == 0) {
467
CAPI
.CRYPTOAPI_BLOB dataBlob = new
CAPI
.CRYPTOAPI_BLOB();
470
if (!
CAPI
.EncodeObject(new IntPtr(
CAPI
.X509_OCTET_STRING), new IntPtr(&dataBlob), out encodedContent))
478
if (!
CAPI
.CAPISafe.CryptMsgUpdate(m_safeCryptMsgHandle, encodedContent, (uint) encodedContent.Length, true))
497
safeCryptMsgHandle =
CAPI
.CAPISafe.CryptMsgOpenToDecode(
CAPI
.X509_ASN_ENCODING |
CAPI
.PKCS_7_ASN_ENCODING,
507
if (!
CAPI
.CAPISafe.CryptMsgUpdate(safeCryptMsgHandle, encodedMessage, (uint) encodedMessage.Length, true))
511
if (
CAPI
.CMSG_ENVELOPED != PkcsUtils.GetMessageType(safeCryptMsgHandle))
512
throw new CryptographicException(
CAPI
.CRYPT_E_INVALID_MSG_TYPE);
523
int hr =
CAPI
.CRYPT_E_RECIPIENT_NOT_FOUND;
530
safeCertContextHandle =
CAPI
.CertFindCertificateInStore(safeCertStoreHandle,
531
CAPI
.X509_ASN_ENCODING |
CAPI
.PKCS_7_ASN_ENCODING,
533
CAPI
.CERT_FIND_SUBJECT_CERT,
538
CAPI
.CMSG_KEY_TRANS_RECIPIENT_INFO keyTrans = (
CAPI
.CMSG_KEY_TRANS_RECIPIENT_INFO) recipientInfo.CmsgRecipientInfo;
539
safeCertContextHandle =
CAPI
.CertFindCertificateInStore(safeCertStoreHandle,
540
CAPI
.X509_ASN_ENCODING |
CAPI
.PKCS_7_ASN_ENCODING,
542
CAPI
.CERT_FIND_CERT_ID,
550
CAPI
.CERT_ID recipientId = keyAgree.RecipientId;
551
safeCertContextHandle =
CAPI
.CertFindCertificateInStore(safeCertStoreHandle,
552
CAPI
.X509_ASN_ENCODING |
CAPI
.PKCS_7_ASN_ENCODING,
554
CAPI
.CERT_FIND_CERT_ID,
560
hr =
CAPI
.E_NOTIMPL;
598
if (!
CAPI
.CryptAcquireContext(ref hCryptProv, IntPtr.Zero, IntPtr.Zero,
CAPI
.PROV_RSA_FULL,
CAPI
.CRYPT_VERIFYCONTEXT)) {
603
if (algId ==
CAPI
.CALG_RC2 || algId ==
CAPI
.CALG_RC4) {
604
CAPI
.CMSG_RC2_AUX_INFO auxInfo = new
CAPI
.CMSG_RC2_AUX_INFO(Marshal.SizeOf(typeof(
CAPI
.CMSG_RC2_AUX_INFO)));
610
SafeLocalAllocHandle pvAuxInfo =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(Marshal.SizeOf(typeof(
CAPI
.CMSG_RC2_AUX_INFO))));
631
int reiSize = recipients.Count * Marshal.SizeOf(typeof(
CAPI
.CMSG_RECIPIENT_ENCODE_INFO));
637
if (recipientInfoTypes[index] ==
CAPI
.CMSG_KEY_TRANS_RECIPIENT) {
638
totalSize += Marshal.SizeOf(typeof(
CAPI
.CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO));
640
else if (recipientInfoTypes[index] ==
CAPI
.CMSG_KEY_AGREE_RECIPIENT) {
642
totalSize += Marshal.SizeOf(typeof(
CAPI
.CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO));
645
throw new CryptographicException(
CAPI
.CRYPT_E_UNKNOWN_ALGO);
649
encryptParam.rgpRecipients =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(totalSize));
667
encryptParam.rgCertEncoded =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(certificates.Count * Marshal.SizeOf(typeof(
CAPI
.CRYPTOAPI_BLOB))));
669
CAPI
.CERT_CONTEXT pCertContext = (
CAPI
.CERT_CONTEXT) Marshal.PtrToStructure(X509Utils.GetCertContext(certificates[index]).DangerousGetHandle(), typeof(
CAPI
.CERT_CONTEXT));
670
CAPI
.CRYPTOAPI_BLOB * pBlob = (
CAPI
.CRYPTOAPI_BLOB *) new IntPtr((long) encryptParam.rgCertEncoded.DangerousGetHandle() +
671
(index * Marshal.SizeOf(typeof(
CAPI
.CRYPTOAPI_BLOB))));
688
CAPI
.CERT_CONTEXT pCertContext = (
CAPI
.CERT_CONTEXT) Marshal.PtrToStructure(X509Utils.GetCertContext(certificate).DangerousGetHandle(), typeof(
CAPI
.CERT_CONTEXT));
689
CAPI
.CERT_INFO certInfo = (
CAPI
.CERT_INFO) Marshal.PtrToStructure(pCertContext.pCertInfo, typeof(
CAPI
.CERT_INFO));
691
CAPI
.CMSG_RECIPIENT_ENCODE_INFO * pEncodeInfo = (
CAPI
.CMSG_RECIPIENT_ENCODE_INFO *) new IntPtr((long) encryptParam.rgpRecipients.DangerousGetHandle() +
692
(index * Marshal.SizeOf(typeof(
CAPI
.CMSG_RECIPIENT_ENCODE_INFO))));
699
if (recipientInfoTypes[index] ==
CAPI
.CMSG_KEY_TRANS_RECIPIENT) {
703
IntPtr pcbSize = new IntPtr((long) pKeyInfo + (long) Marshal.OffsetOf(typeof(
CAPI
.CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO), "cbSize"));
704
Marshal.WriteInt32(pcbSize, Marshal.SizeOf(typeof(
CAPI
.CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO)));
707
IntPtr pKeyEncryptionAlgorithm = new IntPtr((long) pKeyInfo + (long) Marshal.OffsetOf(typeof(
CAPI
.CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO), "KeyEncryptionAlgorithm"));
710
encryptParam.rgszObjId[index] =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(objId.Length + 1));
714
IntPtr pszObjId = new IntPtr((long) pKeyEncryptionAlgorithm + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPT_ALGORITHM_IDENTIFIER), "pszObjId"));
718
IntPtr pParameters = new IntPtr((long) pKeyEncryptionAlgorithm + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPT_ALGORITHM_IDENTIFIER), "Parameters"));
721
IntPtr pcbData = new IntPtr((long) pParameters + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPTOAPI_BLOB), "cbData"));
725
IntPtr ppbData = new IntPtr((long) pParameters + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPTOAPI_BLOB), "pbData"));
732
IntPtr pRecipientPublicKey = new IntPtr((long) pKeyInfo + (long) Marshal.OffsetOf(typeof(
CAPI
.CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO), "RecipientPublicKey"));
735
pcbData = new IntPtr((long) pRecipientPublicKey + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPT_BIT_BLOB), "cbData"));
739
ppbData = new IntPtr((long) pRecipientPublicKey + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPT_BIT_BLOB), "pbData"));
743
IntPtr pcUnusedBIts = new IntPtr((long) pRecipientPublicKey + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPT_BIT_BLOB), "cUnusedBits"));
747
IntPtr pRecipientId = new IntPtr((long) pKeyInfo + (long) Marshal.OffsetOf(typeof(
CAPI
.CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO), "RecipientId"));
751
if (!
CAPI
.CAPISafe.CertGetCertificateContextProperty(X509Utils.GetCertContext(certificate),
752
CAPI
.CERT_KEY_IDENTIFIER_PROP_ID,
757
pbData =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(cbData));
759
if (!
CAPI
.CAPISafe.CertGetCertificateContextProperty(X509Utils.GetCertContext(certificate),
760
CAPI
.CERT_KEY_IDENTIFIER_PROP_ID,
768
IntPtr pdwIdChoice = new IntPtr((long) pRecipientId + (long) Marshal.OffsetOf(typeof(
CAPI
.CERT_ID), "dwIdChoice"));
769
Marshal.WriteInt32(pdwIdChoice, (int)
CAPI
.CERT_ID_KEY_IDENTIFIER);
772
IntPtr pKeyId = new IntPtr((long) pRecipientId + (long) Marshal.OffsetOf(typeof(
CAPI
.CERT_ID), "Value"));
775
pcbData = new IntPtr((long) pKeyId + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPTOAPI_BLOB), "cbData"));
779
ppbData = new IntPtr((long) pKeyId + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPTOAPI_BLOB), "pbData"));
784
IntPtr pdwIdChoice = new IntPtr((long) pRecipientId + (long) Marshal.OffsetOf(typeof(
CAPI
.CERT_ID), "dwIdChoice"));
785
Marshal.WriteInt32(pdwIdChoice, (int)
CAPI
.CERT_ID_ISSUER_SERIAL_NUMBER);
788
IntPtr pIssuerSerialNumber = new IntPtr((long) pRecipientId + (long) Marshal.OffsetOf(typeof(
CAPI
.CERT_ID), "Value"));
791
IntPtr pIssuer = new IntPtr((long) pIssuerSerialNumber + (long) Marshal.OffsetOf(typeof(
CAPI
.CERT_ISSUER_SERIAL_NUMBER), "Issuer"));
794
pcbData = new IntPtr((long) pIssuer + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPTOAPI_BLOB), "cbData"));
798
ppbData = new IntPtr((long) pIssuer + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPTOAPI_BLOB), "pbData"));
802
IntPtr pSerialNumber = new IntPtr((long) pIssuerSerialNumber + (long) Marshal.OffsetOf(typeof(
CAPI
.CERT_ISSUER_SERIAL_NUMBER), "SerialNumber"));
805
pcbData = new IntPtr((long) pSerialNumber + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPTOAPI_BLOB), "cbData"));
809
ppbData = new IntPtr((long) pSerialNumber + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPTOAPI_BLOB), "pbData"));
812
pKeyInfo = new IntPtr((long) pKeyInfo + Marshal.SizeOf(typeof(
CAPI
.CMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO)));
814
else if (recipientInfoTypes[index] ==
CAPI
.CMSG_KEY_AGREE_RECIPIENT) {
818
IntPtr pcbSize = new IntPtr((long) pKeyInfo + (long) Marshal.OffsetOf(typeof(
CAPI
.CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO), "cbSize"));
819
Marshal.WriteInt32(pcbSize, Marshal.SizeOf(typeof(
CAPI
.CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO)));
822
IntPtr pKeyEncryptionAlgorithm = new IntPtr((long) pKeyInfo + (long) Marshal.OffsetOf(typeof(
CAPI
.CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO), "KeyEncryptionAlgorithm"));
824
byte[] objId = Encoding.ASCII.GetBytes(
CAPI
.szOID_RSA_SMIMEalgESDH);
825
encryptParam.rgszObjId[index] =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(objId.Length + 1));
829
IntPtr pszObjId = new IntPtr((long) pKeyEncryptionAlgorithm + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPT_ALGORITHM_IDENTIFIER), "pszObjId"));
836
IntPtr pKeyWrapAlgorithm = new IntPtr((long) pKeyInfo + (long) Marshal.OffsetOf(typeof(
CAPI
.CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO), "KeyWrapAlgorithm"));
839
if (algId ==
CAPI
.CALG_RC2) {
840
objId = Encoding.ASCII.GetBytes(
CAPI
.szOID_RSA_SMIMEalgCMSRC2wrap);
843
objId = Encoding.ASCII.GetBytes(
CAPI
.szOID_RSA_SMIMEalgCMS3DESwrap);
845
encryptParam.rgszKeyWrapObjId[cKeyAgree] =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(objId.Length + 1));
849
pszObjId = new IntPtr((long) pKeyWrapAlgorithm + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPT_ALGORITHM_IDENTIFIER), "pszObjId"));
855
if (algId ==
CAPI
.CALG_RC2) {
856
IntPtr pKeyWrapAuxInfo = new IntPtr((long) pKeyInfo + (long) Marshal.OffsetOf(typeof(
CAPI
.CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO), "pvKeyWrapAuxInfo"));
864
IntPtr pdwKeyChoice = new IntPtr((long) pKeyInfo + (long) Marshal.OffsetOf(typeof(
CAPI
.CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO), "dwKeyChoice"));
865
Marshal.WriteInt32(pdwKeyChoice, (int)
CAPI
.CMSG_KEY_AGREE_EPHEMERAL_KEY_CHOICE);
868
IntPtr pEphemeralAlgorithm = new IntPtr((long) pKeyInfo + (long) Marshal.OffsetOf(typeof(
CAPI
.CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO), "pEphemeralAlgorithmOrSenderId"));
869
encryptParam.rgEphemeralIdentifier[cKeyAgree] =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(Marshal.SizeOf(typeof(
CAPI
.CRYPT_ALGORITHM_IDENTIFIER))));
874
encryptParam.rgszEphemeralObjId[cKeyAgree] =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(objId.Length + 1));
877
pszObjId = new IntPtr((long) encryptParam.rgEphemeralIdentifier[cKeyAgree].DangerousGetHandle() + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPT_ALGORITHM_IDENTIFIER), "pszObjId"));
881
IntPtr pParameters = new IntPtr((long) encryptParam.rgEphemeralIdentifier[cKeyAgree].DangerousGetHandle() + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPT_ALGORITHM_IDENTIFIER), "Parameters"));
884
IntPtr pcbData = new IntPtr((long) pParameters + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPTOAPI_BLOB), "cbData"));
888
IntPtr ppbData = new IntPtr((long) pParameters + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPTOAPI_BLOB), "pbData"));
894
IntPtr pcRecipientEncryptedKeys = new IntPtr((long) pKeyInfo + (long) Marshal.OffsetOf(typeof(
CAPI
.CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO), "cRecipientEncryptedKeys"));
898
encryptParam.prgpEncryptedKey[cKeyAgree] =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(Marshal.SizeOf(typeof(IntPtr))));
899
IntPtr prgpRecipientEncryptedKeys = new IntPtr((long) pKeyInfo + (long) Marshal.OffsetOf(typeof(
CAPI
.CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO), "rgpRecipientEncryptedKeys"));
901
encryptParam.rgpEncryptedKey[cKeyAgree] =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(Marshal.SizeOf(typeof(
CAPI
.CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO))));
905
pcbSize = new IntPtr((long) encryptParam.rgpEncryptedKey[cKeyAgree].DangerousGetHandle() + (long) Marshal.OffsetOf(typeof(
CAPI
.CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO), "cbSize"));
906
Marshal.WriteInt32(pcbSize, Marshal.SizeOf(typeof(
CAPI
.CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO)));
909
IntPtr pRecipientPublicKey = new IntPtr((long) encryptParam.rgpEncryptedKey[cKeyAgree].DangerousGetHandle() + (long) Marshal.OffsetOf(typeof(
CAPI
.CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO), "RecipientPublicKey"));
912
pcbData = new IntPtr((long) pRecipientPublicKey + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPT_BIT_BLOB), "cbData"));
916
ppbData = new IntPtr((long) pRecipientPublicKey + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPT_BIT_BLOB), "pbData"));
920
IntPtr pcUnusedBits = new IntPtr((long) pRecipientPublicKey + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPT_BIT_BLOB), "cUnusedBits"));
924
IntPtr pRecipientId = new IntPtr((long) encryptParam.rgpEncryptedKey[cKeyAgree].DangerousGetHandle() + (long) Marshal.OffsetOf(typeof(
CAPI
.CMSG_RECIPIENT_ENCRYPTED_KEY_ENCODE_INFO), "RecipientId"));
927
IntPtr pdwIdChoice = new IntPtr((long) pRecipientId + (long) Marshal.OffsetOf(typeof(
CAPI
.CERT_ID), "dwIdChoice"));
930
Marshal.WriteInt32(pdwIdChoice, (int)
CAPI
.CERT_ID_KEY_IDENTIFIER);
933
IntPtr pKeyId = new IntPtr((long) pRecipientId + (long) Marshal.OffsetOf(typeof(
CAPI
.CERT_ID), "Value"));
937
if (!
CAPI
.CAPISafe.CertGetCertificateContextProperty(X509Utils.GetCertContext(certificate),
938
CAPI
.CERT_KEY_IDENTIFIER_PROP_ID,
943
pbKeyId =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(cbKeyId));
944
if (!
CAPI
.CAPISafe.CertGetCertificateContextProperty(X509Utils.GetCertContext(certificate),
945
CAPI
.CERT_KEY_IDENTIFIER_PROP_ID,
953
pcbData = new IntPtr((long) pKeyId + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPTOAPI_BLOB), "cbData"));
957
ppbData = new IntPtr((long) pKeyId + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPTOAPI_BLOB), "pbData"));
961
Marshal.WriteInt32(pdwIdChoice, (int)
CAPI
.CERT_ID_ISSUER_SERIAL_NUMBER);
964
IntPtr pIssuerSerial = new IntPtr((long) pRecipientId + (long) Marshal.OffsetOf(typeof(
CAPI
.CERT_ID), "Value"));
967
IntPtr pIssuer = new IntPtr((long) pIssuerSerial + (long) Marshal.OffsetOf(typeof(
CAPI
.CERT_ISSUER_SERIAL_NUMBER), "Issuer"));
970
pcbData = new IntPtr((long) pIssuer + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPTOAPI_BLOB), "cbData"));
974
ppbData = new IntPtr((long) pIssuer + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPTOAPI_BLOB), "pbData"));
978
IntPtr pSerialNumber = new IntPtr((long) pIssuerSerial + (long) Marshal.OffsetOf(typeof(
CAPI
.CERT_ISSUER_SERIAL_NUMBER), "SerialNumber"));
981
pcbData = new IntPtr((long) pSerialNumber + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPTOAPI_BLOB), "cbData"));
985
ppbData = new IntPtr((long) pSerialNumber + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPTOAPI_BLOB), "pbData"));
991
pKeyInfo = new IntPtr((long) pKeyInfo + Marshal.SizeOf(typeof(
CAPI
.CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO)));
1023
encryptParam.rgpRecipients =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(totalSize));
1031
CAPI
.CERT_CONTEXT pCertContext = (
CAPI
.CERT_CONTEXT) Marshal.PtrToStructure(dangerousCertContextHandle, typeof(
CAPI
.CERT_CONTEXT));
1066
throw new CryptographicException(
CAPI
.CRYPT_E_RECIPIENT_NOT_FOUND);
1119
throw new CryptographicException(
CAPI
.CRYPT_E_NOT_FOUND);
system\security\cryptography\pkcs\pkcs7signer.cs (1)
69
string oidValue = LocalAppContextSwitches.CmsUseInsecureHashAlgorithms ?
CAPI
.szOID_OIWSEC_sha1 : Sha256Oid;
system\security\cryptography\pkcs\pkcs9attribute.cs (21)
77
public Pkcs9SigningTime(DateTime signingTime) : base(
CAPI
.szOID_RSA_signingTime, Encode(signingTime)) {
82
public Pkcs9SigningTime(byte[] encodedSigningTime) : base(
CAPI
.szOID_RSA_signingTime, encodedSigningTime) {}
110
if (!
CAPI
.DecodeObject(new IntPtr(
CAPI
.PKCS_UTC_TIME),
127
SafeLocalAllocHandle pbSigningTime =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(Marshal.SizeOf(typeof(Int64))));
131
if (!
CAPI
.EncodeObject(
CAPI
.szOID_RSA_signingTime, pbSigningTime.DangerousGetHandle(), out encodedSigningTime))
150
base(new Oid(
CAPI
.szOID_CAPICOM_documentName)) {
156
base(
CAPI
.szOID_CAPICOM_documentName, Encode(documentName)) {
162
base(
CAPI
.szOID_CAPICOM_documentName, encodedDocumentName) {}
207
base (new Oid(
CAPI
.szOID_CAPICOM_documentDescription)) {
213
base(
CAPI
.szOID_CAPICOM_documentDescription, Encode(documentDescription)) {
219
base(
CAPI
.szOID_CAPICOM_documentDescription, encodedDocumentDescription) {}
264
base(Oid.FromOidValue(
CAPI
.szOID_RSA_contentType, OidGroup.ExtensionOrAttribute), encodedContentType) {
268
base(Oid.FromOidValue(
CAPI
.szOID_RSA_contentType, OidGroup.ExtensionOrAttribute)) {
294
throw new CryptographicException(
CAPI
.CRYPT_E_BAD_ENCODE);
296
if (RawData[0] !=
CAPI
.ASN_TAG_OBJID)
297
throw new CryptographicException(
CAPI
.CRYPT_E_ASN1_BADTAG);
314
base(Oid.FromOidValue(
CAPI
.szOID_RSA_messageDigest, OidGroup.ExtensionOrAttribute), encodedMessageDigest) {
318
base(Oid.FromOidValue(
CAPI
.szOID_RSA_messageDigest, OidGroup.ExtensionOrAttribute)) {
system\security\cryptography\pkcs\pkcsmisc.cs (79)
41
internal SubjectIdentifier (
CAPI
.CERT_INFO certInfo) : this(certInfo.Issuer, certInfo.SerialNumber) {}
43
internal SubjectIdentifier (
CAPI
.CMSG_SIGNER_INFO signerInfo) : this(signerInfo.Issuer, signerInfo.SerialNumber) {}
50
internal unsafe SubjectIdentifier (
CAPI
.CRYPTOAPI_BLOB issuer,
CAPI
.CRYPTOAPI_BLOB serialNumber) {
65
if (String.Compare(
CAPI
.DummySignerCommonName, dummyName.Name, StringComparison.OrdinalIgnoreCase) == 0) {
82
if (
CAPI
.DecodeObject(new IntPtr(
CAPI
.X509_NAME),
89
CAPI
.CERT_NAME_INFO certNameInfo = (
CAPI
.CERT_NAME_INFO) Marshal.PtrToStructure(pbCertNameInfo.DangerousGetHandle(), typeof(
CAPI
.CERT_NAME_INFO));
91
CAPI
.CERT_RDN certRdn = (
CAPI
.CERT_RDN) Marshal.PtrToStructure(new IntPtr((long) certNameInfo.rgRDN + (long) (i * Marshal.SizeOf(typeof(
CAPI
.CERT_RDN)))), typeof(
CAPI
.CERT_RDN));
95
CAPI
.CERT_RDN_ATTR certRdnAttr = (
CAPI
.CERT_RDN_ATTR)Marshal.PtrToStructure(new IntPtr((long)certRdn.rgRDNAttr + (long)(j * Marshal.SizeOf(typeof(
CAPI
.CERT_RDN_ATTR)))), typeof(
CAPI
.CERT_RDN_ATTR));
97
if (String.Compare(
CAPI
.szOID_KEYID_RDN, certRdnAttr.pszObjId, StringComparison.OrdinalIgnoreCase) == 0)
99
if (certRdnAttr.dwValueType ==
CAPI
.CERT_RDN_OCTET_STRING)
114
CAPI
.CERT_ISSUER_SERIAL_NUMBER IssuerAndSerial;
122
internal SubjectIdentifier (
CAPI
.CERT_ID certId) {
124
case
CAPI
.CERT_ID_ISSUER_SERIAL_NUMBER:
128
case
CAPI
.CERT_ID_KEY_IDENTIFIER:
196
internal PublicKeyInfo (
CAPI
.CERT_PUBLIC_KEY_INFO keyInfo) {
229
internal SubjectIdentifierOrKey (
CAPI
.CERT_ID certId) {
231
case
CAPI
.CERT_ID_ISSUER_SERIAL_NUMBER:
235
case
CAPI
.CERT_ID_KEY_IDENTIFIER:
246
internal SubjectIdentifierOrKey (
CAPI
.CERT_PUBLIC_KEY_INFO publicKeyInfo) {
308
Reset(Oid.FromOidValue(
CAPI
.szOID_RSA_DES_EDE3_CBC, OidGroup.EncryptionAlgorithm), 0, new byte[0]);
320
internal AlgorithmIdentifier (
CAPI
.CERT_PUBLIC_KEY_INFO keyInfo) {
321
SafeLocalAllocHandle pKeyInfo =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(Marshal.SizeOf(typeof(
CAPI
.CERT_PUBLIC_KEY_INFO))));
323
int keyLength = (int)
CAPI
.CAPISafe.CertGetPublicKeyLength(
CAPI
.X509_ASN_ENCODING |
CAPI
.PKCS_7_ASN_ENCODING, pKeyInfo.DangerousGetHandle());
328
Marshal.DestroyStructure(pKeyInfo.DangerousGetHandle(), typeof(
CAPI
.CERT_PUBLIC_KEY_INFO));
334
internal AlgorithmIdentifier (
CAPI
.CRYPT_ALGORITHM_IDENTIFIER algorithmIdentifier) {
342
if (algId ==
CAPI
.CALG_RC2) {
344
if (!
CAPI
.DecodeObject(new IntPtr(
CAPI
.PKCS_RC2_CBC_PARAMETERS),
351
CAPI
.CRYPT_RC2_CBC_PARAMETERS rc2Parameters = (
CAPI
.CRYPT_RC2_CBC_PARAMETERS) Marshal.PtrToStructure(pbParameters.DangerousGetHandle(), typeof(
CAPI
.CRYPT_RC2_CBC_PARAMETERS));
353
case
CAPI
.CRYPT_RC2_40BIT_VERSION:
356
case
CAPI
.CRYPT_RC2_56BIT_VERSION:
359
case
CAPI
.CRYPT_RC2_128BIT_VERSION:
369
else if (algId ==
CAPI
.CALG_RC4 || algId ==
CAPI
.CALG_DES || algId ==
CAPI
.CALG_3DES) {
374
if (!
CAPI
.DecodeObject(new IntPtr(
CAPI
.X509_OCTET_STRING),
381
if (cbParameters > Marshal.SizeOf(typeof(
CAPI
.CRYPTOAPI_BLOB))) {
382
CAPI
.CRYPTOAPI_BLOB blob = (
CAPI
.CRYPTOAPI_BLOB)Marshal.PtrToStructure(pbParameters.DangerousGetHandle(), typeof(
CAPI
.CRYPTOAPI_BLOB));
384
if (algId ==
CAPI
.CALG_RC4) {
407
if (algId ==
CAPI
.CALG_RC4) {
411
else if (algId ==
CAPI
.CALG_DES) {
481
this(Oid.FromOidValue(
CAPI
.szOID_RSA_data, OidGroup.ExtensionOrAttribute), new byte[0]) {
485
this(Oid.FromOidValue(
CAPI
.szOID_RSA_data, OidGroup.ExtensionOrAttribute), content) {
537
SafeCryptMsgHandle safeCryptMsgHandle =
CAPI
.CAPISafe.CryptMsgOpenToDecode(
538
CAPI
.X509_ASN_ENCODING |
CAPI
.PKCS_7_ASN_ENCODING,
547
if (!
CAPI
.CAPISafe.CryptMsgUpdate(safeCryptMsgHandle, encodedMessage, (uint) encodedMessage.Length, true))
552
case
CAPI
.CMSG_DATA:
553
contentType = Oid.FromOidValue(
CAPI
.szOID_RSA_data, OidGroup.ExtensionOrAttribute);
555
case
CAPI
.CMSG_SIGNED:
556
contentType = Oid.FromOidValue(
CAPI
.szOID_RSA_signedData, OidGroup.ExtensionOrAttribute);
558
case
CAPI
.CMSG_ENVELOPED:
559
contentType = Oid.FromOidValue(
CAPI
.szOID_RSA_envelopedData, OidGroup.ExtensionOrAttribute);
561
case
CAPI
.CMSG_SIGNED_AND_ENVELOPED:
562
contentType = Oid.FromOidValue(
CAPI
.szOID_RSA_signEnvData, OidGroup.ExtensionOrAttribute);
564
case
CAPI
.CMSG_HASHED:
565
contentType = Oid.FromOidValue(
CAPI
.szOID_RSA_hashedData, OidGroup.ExtensionOrAttribute);
567
case
CAPI
.CMSG_ENCRYPTED:
568
contentType = Oid.FromOidValue(
CAPI
.szOID_RSA_encryptedData, OidGroup.ExtensionOrAttribute);
571
throw new CryptographicException(
CAPI
.CRYPT_E_INVALID_MSG_TYPE);
system\security\cryptography\pkcs\pkcsutils.cs (191)
42
using(SafeLibraryHandle hModule =
CAPI
.CAPISafe.LoadLibrary("Crypt32.dll")) {
44
IntPtr pFunc =
CAPI
.CAPISafe.GetProcAddress(hModule, "CryptMsgVerifyCountersignatureEncodedEx");
58
CAPI
.CERT_CONTEXT pCertContext = (
CAPI
.CERT_CONTEXT) Marshal.PtrToStructure(X509Utils.GetCertContext(certificate).DangerousGetHandle(), typeof(
CAPI
.CERT_CONTEXT));
59
CAPI
.CERT_INFO certInfo = (
CAPI
.CERT_INFO) Marshal.PtrToStructure(pCertContext.pCertInfo, typeof(
CAPI
.CERT_INFO));
62
if (algId ==
CAPI
.CALG_RSA_KEYX)
64
else if (algId ==
CAPI
.CALG_DH_SF || algId ==
CAPI
.CALG_DH_EPHEM)
75
uint enumFlag =
CAPI
.CRYPT_FIRST;
76
uint cbPeex = (uint) Marshal.SizeOf(typeof(
CAPI
.PROV_ENUMALGS_EX));
77
SafeLocalAllocHandle pPeex =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(Marshal.SizeOf(typeof(
CAPI
.PROV_ENUMALGS_EX))));
80
while (
CAPI
.CAPISafe.CryptGetProvParam(safeCryptProvHandle,
CAPI
.PP_ENUMALGS_EX, pPeex.DangerousGetHandle(), new IntPtr(&cbPeex), enumFlag)) {
81
CAPI
.PROV_ENUMALGS_EX peex = (
CAPI
.PROV_ENUMALGS_EX) Marshal.PtrToStructure(pPeex.DangerousGetHandle(), typeof(
CAPI
.PROV_ENUMALGS_EX));
90
throw new CryptographicException(
CAPI
.CRYPT_E_UNKNOWN_ALGO);
97
if (!
CAPI
.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle,
98
CAPI
.CMSG_VERSION_PARAM,
111
if (!
CAPI
.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle,
112
CAPI
.CMSG_TYPE_PARAM,
126
if (!
CAPI
.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle,
127
CAPI
.CMSG_ENVELOPE_ALGORITHM_PARAM,
134
SafeLocalAllocHandle pbAlgorithm =
CAPI
.LocalAlloc(
CAPI
.LMEM_FIXED, new IntPtr(cbAlgorithm));
135
if (!
CAPI
.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle,
136
CAPI
.CMSG_ENVELOPE_ALGORITHM_PARAM,
142
CAPI
.CRYPT_ALGORITHM_IDENTIFIER cryptAlgorithmIdentifier = (
CAPI
.CRYPT_ALGORITHM_IDENTIFIER) Marshal.PtrToStructure(pbAlgorithm.DangerousGetHandle(), typeof(
CAPI
.CRYPT_ALGORITHM_IDENTIFIER));
160
if (!
CAPI
.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle,
168
pvData =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(cbData));
170
if (!
CAPI
.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle,
190
if (!
CAPI
.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle,
201
if (!
CAPI
.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle,
218
if (!
CAPI
.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle,
219
CAPI
.CMSG_CERT_COUNT_PARAM,
229
GetParam(safeCryptMsgHandle,
CAPI
.CMSG_CERT_PARAM, index, out pbEncoded, out cbEncoded);
231
SafeCertContextHandle safeCertContextHandle =
CAPI
.CAPISafe.CertCreateCertificateContext(
CAPI
.X509_ASN_ENCODING |
CAPI
.PKCS_7_ASN_ENCODING,
250
GetParam(safeCryptMsgHandle,
CAPI
.CMSG_CONTENT_PARAM, 0, out content, out cbContent);
260
GetParam(safeCryptMsgHandle,
CAPI
.CMSG_INNER_CONTENT_TYPE_PARAM, 0, out contentType, out cbContentType);
274
GetParam(safeCryptMsgHandle,
CAPI
.CMSG_ENCODED_MESSAGE, 0, out message, out cbMessage);
283
if (!
CAPI
.CAPISafe.CryptMsgGetParam(safeCrytpMsgHandle,
284
CAPI
.CMSG_SIGNER_COUNT_PARAM,
293
if (!
CAPI
.CAPISafe.CryptMsgGetParam(safeCrytpMsgHandle,
294
CAPI
.CMSG_SIGNER_INFO_PARAM,
301
SafeLocalAllocHandle pbCmsgSignerInfo =
CAPI
.LocalAlloc(
CAPI
.LMEM_FIXED, new IntPtr(cbCmsgSignerInfo));
303
if (!
CAPI
.CAPISafe.CryptMsgGetParam(safeCrytpMsgHandle,
304
CAPI
.CMSG_SIGNER_INFO_PARAM,
310
CAPI
.CMSG_SIGNER_INFO cmsgSignerInfo1 = signerInfo.GetCmsgSignerInfo();
311
CAPI
.CMSG_SIGNER_INFO cmsgSignerInfo2 = (
CAPI
.CMSG_SIGNER_INFO) Marshal.PtrToStructure(pbCmsgSignerInfo.DangerousGetHandle(), typeof(
CAPI
.CMSG_SIGNER_INFO));
329
throw new CryptographicException(
CAPI
.CRYPT_E_SIGNER_NOT_FOUND);
337
if (!
CAPI
.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle,
338
CAPI
.CMSG_UNPROTECTED_ATTR_PARAM,
343
if (lastWin32Error !=
CAPI
.CRYPT_E_ATTRIBUTES_MISSING)
348
using (pbUnprotectedAttr =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(cbUnprotectedAttr))) {
349
if (!
CAPI
.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle,
350
CAPI
.CMSG_UNPROTECTED_ATTR_PARAM,
363
internal unsafe static X509IssuerSerial DecodeIssuerSerial (
CAPI
.CERT_ISSUER_SERIAL_NUMBER pIssuerAndSerial) {
365
uint cbSize =
CAPI
.CAPISafe.CertNameToStrW(
CAPI
.X509_ASN_ENCODING |
CAPI
.PKCS_7_ASN_ENCODING,
367
CAPI
.CERT_X500_NAME_STR |
CAPI
.CERT_NAME_STR_REVERSE_FLAG,
373
ptr =
CAPI
.LocalAlloc(
CAPI
.LMEM_FIXED, new IntPtr(checked(2 * cbSize)));
374
cbSize =
CAPI
.CAPISafe.CertNameToStrW(
CAPI
.X509_ASN_ENCODING |
CAPI
.PKCS_7_ASN_ENCODING,
376
CAPI
.CERT_X500_NAME_STR |
CAPI
.CERT_NAME_STR_REVERSE_FLAG,
397
if (!
CAPI
.DecodeObject(new IntPtr(
CAPI
.X509_OCTET_STRING),
406
CAPI
.CRYPTOAPI_BLOB decodedBlob = (
CAPI
.CRYPTOAPI_BLOB) Marshal.PtrToStructure(pbDecoded.DangerousGetHandle(), typeof(
CAPI
.CRYPTOAPI_BLOB));
420
if (!
CAPI
.DecodeObject(new IntPtr(
CAPI
.X509_OCTET_STRING),
430
return
CAPI
.BlobToByteArray(pbDecoded.DangerousGetHandle());
444
CAPI
.CRYPTOAPI_BLOB octetsBlob = new
CAPI
.CRYPTOAPI_BLOB();
450
if (!
CAPI
.EncodeObject(new IntPtr((long)
CAPI
.X509_OCTET_STRING),
482
throw new CryptographicException(
CAPI
.CRYPT_E_BAD_ENCODE);
499
if (String.Compare(extension.Oid.Value,
CAPI
.szOID_KEY_USAGE, StringComparison.OrdinalIgnoreCase) == 0) {
517
throw new CryptographicException(
CAPI
.CRYPT_E_RECIPIENT_NOT_FOUND);
521
throw new CryptographicException(
CAPI
.ERROR_CANCELLED);
536
if (String.Compare(extension.Oid.Value,
CAPI
.szOID_KEY_USAGE, StringComparison.OrdinalIgnoreCase) == 0) {
554
throw new CryptographicException(
CAPI
.CRYPT_E_SIGNER_NOT_FOUND);
558
throw new CryptographicException(
CAPI
.ERROR_CANCELLED);
566
internal static AsnEncodedDataCollection GetAsnEncodedDataCollection (
CAPI
.CRYPT_ATTRIBUTE cryptAttribute) {
573
IntPtr pAttributeBlob = new IntPtr((long)cryptAttribute.rgValue + (index * Marshal.SizeOf(typeof(
CAPI
.CRYPTOAPI_BLOB))));
574
Pkcs9AttributeObject attribute = new Pkcs9AttributeObject(oid,
CAPI
.BlobToByteArray(pAttributeBlob));
587
internal static AsnEncodedDataCollection GetAsnEncodedDataCollection (
CAPI
.CRYPT_ATTRIBUTE_TYPE_VALUE cryptAttribute) {
589
list.Add(new Pkcs9AttributeObject(new Oid(cryptAttribute.pszObjId),
CAPI
.BlobToByteArray(cryptAttribute.Value)));
627
uint cryptBlobSize = AlignedLength((uint) Marshal.SizeOf(typeof(
CAPI
.CRYPTOAPI_BLOB)));
646
SafeLocalAllocHandle pCryptAttributes =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(totalLength));
655
CAPI
.CRYPTOAPI_BLOB * pDataBlob = (
CAPI
.CRYPTOAPI_BLOB *) (pszObjId + AlignedLength((uint) objId.Length));
706
internal static
CAPI
.CMSG_SIGNER_ENCODE_INFO CreateSignerEncodeInfo (CmsSigner signer, out SafeCryptProvHandle hProv) {
713
internal static unsafe
CAPI
.CMSG_SIGNER_ENCODE_INFO CreateSignerEncodeInfo (CmsSigner signer, bool silent, out SafeCryptProvHandle hProv) {
714
CAPI
.CMSG_SIGNER_ENCODE_INFO cmsSignerEncodeInfo = new
CAPI
.CMSG_SIGNER_ENCODE_INFO(Marshal.SizeOf(typeof(
CAPI
.CMSG_SIGNER_ENCODE_INFO)));
723
CAPI
.szOID_X957_DSA,
726
cmsSignerEncodeInfo.HashEncryptionAlgorithm.pszObjId =
CAPI
.szOID_X957_sha1DSA;
736
cmsSignerEncodeInfo.HashEncryptionAlgorithm.pszObjId =
CAPI
.szOID_PKIX_NO_SIGNATURE;
744
if (!
CAPI
.CryptAcquireContext(ref safeCryptProvHandle,
747
CAPI
.PROV_RSA_FULL,
748
CAPI
.CRYPT_VERIFYCONTEXT)) {
757
cmsSignerEncodeInfo.SignerId.dwIdChoice =
CAPI
.CERT_ID_ISSUER_SERIAL_NUMBER;
760
X500DistinguishedName dummyName = new X500DistinguishedName(
CAPI
.DummySignerCommonName);
761
dummyName.Oid = Oid.FromOidValue(
CAPI
.szOID_RDN_DUMMY_SIGNER, OidGroup.ExtensionOrAttribute);
764
CAPI
.LocalAlloc(
CAPI
.LPTR,
773
CAPI
.LocalAlloc(
CAPI
.LPTR,
787
if (hr !=
CAPI
.S_OK)
794
CAPI
.CERT_CONTEXT pCertContext = *((
CAPI
.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle());
801
if (!
CAPI
.CAPISafe.CertGetCertificateContextProperty(safeCertContextHandle,
802
CAPI
.CERT_KEY_IDENTIFIER_PROP_ID,
808
pbData =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(cbData));
810
if (!
CAPI
.CAPISafe.CertGetCertificateContextProperty(safeCertContextHandle,
811
CAPI
.CERT_KEY_IDENTIFIER_PROP_ID,
816
cmsSignerEncodeInfo.SignerId.dwIdChoice =
CAPI
.CERT_ID_KEY_IDENTIFIER;
837
if (
CAPI
.CAPISafe.CertGetCertificateContextProperty(
839
CAPI
.CERT_NCRYPT_KEY_HANDLE_PROP_ID,
845
return
CAPI
.S_OK;
855
if (String.Compare(parameters.ProviderName,
CAPI
.MS_DEF_PROV, StringComparison.OrdinalIgnoreCase) == 0)
859
if (
CAPI
.CryptAcquireContext(ref provHandle, parameters.KeyContainerName,
CAPI
.MS_ENHANCED_PROV,
CAPI
.PROV_RSA_FULL, 0) ||
860
CAPI
.CryptAcquireContext(ref provHandle, parameters.KeyContainerName,
CAPI
.MS_STRONG_PROV,
CAPI
.PROV_RSA_FULL, 0))
867
int hr =
CAPI
.S_OK;
869
uint flags =
CAPI
.CRYPT_ACQUIRE_COMPARE_KEY_FLAG |
CAPI
.CRYPT_ACQUIRE_USE_PROV_INFO_FLAG;
879
flags |=
CAPI
.CRYPT_ACQUIRE_PREFER_NCRYPT_KEY_FLAG;
886
if (
CAPI
.CAPISafe.CryptAcquireCertificatePrivateKey(safeCertContextHandle,
930
throw new CryptographicException(
CAPI
.CERT_E_CHAINING);
959
certBlob =
CAPI
.LocalAlloc(
CAPI
.LMEM_FIXED, new IntPtr(certificates.Count * Marshal.SizeOf(typeof(
CAPI
.CRYPTOAPI_BLOB))));
960
CAPI
.CRYPTOAPI_BLOB * pCertBlob = (
CAPI
.CRYPTOAPI_BLOB * ) certBlob.DangerousGetHandle();
964
CAPI
.CERT_CONTEXT pCertContext = *((
CAPI
.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle());
985
CAPI
.CERT_CONTEXT pCertContext = *((
CAPI
.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle());
987
CAPI
.CRYPTOAPI_BLOB certBlob = new
CAPI
.CRYPTOAPI_BLOB();
991
if (!
CAPI
.CryptMsgControl(safeCryptMsgHandle,
993
CAPI
.CMSG_CTRL_ADD_CERT,
1030
if (
CAPI
.CRYPT_E_INVALID_MSG_TYPE != err)
1046
dwFlags |=
CAPI
.CRYPT_MACHINE_KEYSET;
1050
dwFlags |=
CAPI
.CRYPT_VERIFYCONTEXT;
1054
dwFlags |=
CAPI
.CRYPT_SILENT;
1056
bool rc =
CAPI
.CryptAcquireContext(ref hProv,
1065
CAPI
.CRYPT_KEY_PROV_INFO KeyProvInfo = new
CAPI
.CRYPT_KEY_PROV_INFO();
1070
KeyProvInfo.dwFlags = (uint)((parameters.Flags & CspProviderFlags.UseMachineKeyStore) == CspProviderFlags.UseMachineKeyStore ?
CAPI
.CRYPT_MACHINE_KEYSET : 0);
1072
SafeLocalAllocHandle pKeyProvInfo =
CAPI
.LocalAlloc(
CAPI
.LPTR,
1073
new IntPtr(Marshal.SizeOf(typeof(
CAPI
.CRYPT_KEY_PROV_INFO))));
1077
CAPI
.CRYPT_ALGORITHM_IDENTIFIER SignatureAlgorithm = new
CAPI
.CRYPT_ALGORITHM_IDENTIFIER();
1078
SignatureAlgorithm.pszObjId =
CAPI
.szOID_OIWSEC_sha1RSASign;
1080
SafeLocalAllocHandle pSignatureAlgorithm =
CAPI
.LocalAlloc(
CAPI
.LPTR,
1081
new IntPtr( Marshal.SizeOf(typeof(
CAPI
.CRYPT_ALGORITHM_IDENTIFIER))));
1087
CAPI
.CRYPTOAPI_BLOB SubjectIssuerBlob = new
CAPI
.CRYPTOAPI_BLOB();
1091
handle =
CAPI
.CAPIUnsafe.CertCreateSelfSignCertificate(hProv,
1101
Marshal.DestroyStructure(pKeyProvInfo.DangerousGetHandle(), typeof(
CAPI
.CRYPT_KEY_PROV_INFO));
1103
Marshal.DestroyStructure(pSignatureAlgorithm.DangerousGetHandle(), typeof(
CAPI
.CRYPT_ALGORITHM_IDENTIFIER));
system\security\cryptography\pkcs\recipientinfo.cs (67)
112
internal unsafe KeyTransRecipientInfo (SafeLocalAllocHandle pRecipientInfo,
CAPI
.CERT_INFO certInfo, uint index) : base(RecipientInfoType.KeyTransport, RecipientSubType.Pkcs7KeyTransport, pRecipientInfo, certInfo, index) {
127
internal KeyTransRecipientInfo (SafeLocalAllocHandle pRecipientInfo,
CAPI
.CMSG_KEY_TRANS_RECIPIENT_INFO keyTrans, uint index) : base(RecipientInfoType.KeyTransport, RecipientSubType.CmsKeyTransport, pRecipientInfo, keyTrans, index) {
142
CAPI
.CMSG_KEY_TRANS_RECIPIENT_INFO keyTrans = (
CAPI
.CMSG_KEY_TRANS_RECIPIENT_INFO) CmsgRecipientInfo;
146
CAPI
.CERT_INFO certInfo = (
CAPI
.CERT_INFO) CmsgRecipientInfo;
160
CAPI
.CMSG_KEY_TRANS_RECIPIENT_INFO keyTrans = (
CAPI
.CMSG_KEY_TRANS_RECIPIENT_INFO) CmsgRecipientInfo;
164
CAPI
.CERT_INFO certInfo = (
CAPI
.CERT_INFO) CmsgRecipientInfo;
179
CAPI
.CMSG_KEY_TRANS_RECIPIENT_INFO keyTrans = (
CAPI
.CMSG_KEY_TRANS_RECIPIENT_INFO) CmsgRecipientInfo;
205
private
CAPI
.CMSG_RECIPIENT_ENCRYPTED_KEY_INFO m_encryptedKeyInfo;
220
internal KeyAgreeRecipientInfo (SafeLocalAllocHandle pRecipientInfo,
CAPI
.CMSG_KEY_AGREE_CERT_ID_RECIPIENT_INFO certIdRecipient, uint index, uint subIndex) : base(RecipientInfoType.KeyAgreement, RecipientSubType.CertIdKeyAgreement, pRecipientInfo, certIdRecipient, index) {
223
CAPI
.CMSG_RECIPIENT_ENCRYPTED_KEY_INFO encryptedKeyInfo = (
CAPI
.CMSG_RECIPIENT_ENCRYPTED_KEY_INFO) Marshal.PtrToStructure(pEncryptedKeyInfo, typeof(
CAPI
.CMSG_RECIPIENT_ENCRYPTED_KEY_INFO));
224
Reset(
CAPI
.CMSG_KEY_AGREE_ORIGINATOR_CERT, certIdRecipient.dwVersion, encryptedKeyInfo, subIndex);
229
internal KeyAgreeRecipientInfo (SafeLocalAllocHandle pRecipientInfo,
CAPI
.CMSG_KEY_AGREE_PUBLIC_KEY_RECIPIENT_INFO publicKeyRecipient, uint index, uint subIndex) : base(RecipientInfoType.KeyAgreement, RecipientSubType.PublicKeyAgreement, pRecipientInfo, publicKeyRecipient, index) {
232
CAPI
.CMSG_RECIPIENT_ENCRYPTED_KEY_INFO encryptedKeyInfo = (
CAPI
.CMSG_RECIPIENT_ENCRYPTED_KEY_INFO) Marshal.PtrToStructure(pEncryptedKeyInfo, typeof(
CAPI
.CMSG_RECIPIENT_ENCRYPTED_KEY_INFO));
233
Reset(
CAPI
.CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY, publicKeyRecipient.dwVersion, encryptedKeyInfo, subIndex);
247
if (m_originatorChoice ==
CAPI
.CMSG_KEY_AGREE_ORIGINATOR_CERT) {
248
CAPI
.CMSG_KEY_AGREE_CERT_ID_RECIPIENT_INFO recipientInfo = (
CAPI
.CMSG_KEY_AGREE_CERT_ID_RECIPIENT_INFO) CmsgRecipientInfo;
252
CAPI
.CMSG_KEY_AGREE_PUBLIC_KEY_RECIPIENT_INFO recipientInfo = (
CAPI
.CMSG_KEY_AGREE_PUBLIC_KEY_RECIPIENT_INFO) CmsgRecipientInfo;
293
CAPI
.CRYPT_ATTRIBUTE_TYPE_VALUE otherKeyAttribute = (
CAPI
.CRYPT_ATTRIBUTE_TYPE_VALUE) Marshal.PtrToStructure(m_encryptedKeyInfo.pOtherAttr, typeof(
CAPI
.CRYPT_ATTRIBUTE_TYPE_VALUE));
306
if (m_originatorChoice ==
CAPI
.CMSG_KEY_AGREE_ORIGINATOR_CERT) {
307
CAPI
.CMSG_KEY_AGREE_CERT_ID_RECIPIENT_INFO recipientInfo = (
CAPI
.CMSG_KEY_AGREE_CERT_ID_RECIPIENT_INFO) CmsgRecipientInfo;
311
CAPI
.CMSG_KEY_AGREE_PUBLIC_KEY_RECIPIENT_INFO recipientInfo = (
CAPI
.CMSG_KEY_AGREE_PUBLIC_KEY_RECIPIENT_INFO) CmsgRecipientInfo;
338
internal
CAPI
.CERT_ID RecipientId {
354
private void Reset (uint originatorChoice, uint version,
CAPI
.CMSG_RECIPIENT_ENCRYPTED_KEY_INFO encryptedKeyInfo, uint subIndex) {
397
if (!
CAPI
.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle,
398
CAPI
.CMSG_CMS_RECIPIENT_COUNT_PARAM,
406
if (!
CAPI
.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle,
407
CAPI
.CMSG_RECIPIENT_COUNT_PARAM,
421
PkcsUtils.GetParam(safeCryptMsgHandle,
CAPI
.CMSG_CMS_RECIPIENT_INFO_PARAM, index, out pbCmsRecipientInfo, out cbCmsRecipientInfo);
422
CAPI
.CMSG_CMS_RECIPIENT_INFO cmsRecipientInfo = (
CAPI
.CMSG_CMS_RECIPIENT_INFO) Marshal.PtrToStructure(pbCmsRecipientInfo.DangerousGetHandle(), typeof(
CAPI
.CMSG_CMS_RECIPIENT_INFO));
425
case
CAPI
.CMSG_KEY_TRANS_RECIPIENT:
426
CAPI
.CMSG_KEY_TRANS_RECIPIENT_INFO keyTrans = (
CAPI
.CMSG_KEY_TRANS_RECIPIENT_INFO) Marshal.PtrToStructure(cmsRecipientInfo.pRecipientInfo, typeof(
CAPI
.CMSG_KEY_TRANS_RECIPIENT_INFO));
429
case
CAPI
.CMSG_KEY_AGREE_RECIPIENT:
430
CAPI
.CMSG_KEY_AGREE_RECIPIENT_INFO keyAgree = (
CAPI
.CMSG_KEY_AGREE_RECIPIENT_INFO) Marshal.PtrToStructure(cmsRecipientInfo.pRecipientInfo, typeof(
CAPI
.CMSG_KEY_AGREE_RECIPIENT_INFO));
432
case
CAPI
.CMSG_KEY_AGREE_ORIGINATOR_CERT:
433
CAPI
.CMSG_KEY_AGREE_CERT_ID_RECIPIENT_INFO certIdRecipient = (
CAPI
.CMSG_KEY_AGREE_CERT_ID_RECIPIENT_INFO) Marshal.PtrToStructure(cmsRecipientInfo.pRecipientInfo, typeof(
CAPI
.CMSG_KEY_AGREE_CERT_ID_RECIPIENT_INFO));
438
case
CAPI
.CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY:
439
CAPI
.CMSG_KEY_AGREE_PUBLIC_KEY_RECIPIENT_INFO publicKeyRecipient = (
CAPI
.CMSG_KEY_AGREE_PUBLIC_KEY_RECIPIENT_INFO) Marshal.PtrToStructure(cmsRecipientInfo.pRecipientInfo, typeof(
CAPI
.CMSG_KEY_AGREE_PUBLIC_KEY_RECIPIENT_INFO));
449
throw new CryptographicException(
CAPI
.E_NOTIMPL);
456
PkcsUtils.GetParam(safeCryptMsgHandle,
CAPI
.CMSG_RECIPIENT_INFO_PARAM, index, out pbCertInfo, out cbCertInfo);
457
CAPI
.CERT_INFO certInfo = (
CAPI
.CERT_INFO) Marshal.PtrToStructure(pbCertInfo.DangerousGetHandle(), typeof(
CAPI
.CERT_INFO));
system\security\cryptography\pkcs\signedpkcs7.cs (44)
38
new ContentInfo(Oid.FromOidValue(
CAPI
.szOID_RSA_data, OidGroup.ExtensionOrAttribute), new byte[0]),
44
new ContentInfo(Oid.FromOidValue(
CAPI
.szOID_RSA_data, OidGroup.ExtensionOrAttribute), new byte[0]),
189
throw new CryptographicException(
CAPI
.NTE_NO_KEY);
224
if (!
CAPI
.CAPISafe.CryptMsgGetParam(m_safeCryptMsgHandle,
225
CAPI
.CMSG_SIGNER_COUNT_PARAM,
234
if (!
CAPI
.CryptMsgControl(m_safeCryptMsgHandle,
236
CAPI
.CMSG_CTRL_DEL_SIGNER,
297
CAPI
.CMSG_SIGNED_ENCODE_INFO signedEncodeInfo = new
CAPI
.CMSG_SIGNED_ENCODE_INFO(Marshal.SizeOf(typeof(
CAPI
.CMSG_SIGNED_ENCODE_INFO)));
299
CAPI
.CMSG_SIGNER_ENCODE_INFO signerEncodeInfo = PkcsUtils.CreateSignerEncodeInfo(signer, silent, out safeCryptProvHandle);
303
SafeLocalAllocHandle pSignerEncodeInfo =
CAPI
.LocalAlloc(
CAPI
.LMEM_FIXED, new IntPtr(Marshal.SizeOf(typeof(
CAPI
.CMSG_SIGNER_ENCODE_INFO))));
318
if (String.Compare(this.ContentInfo.ContentType.Value,
CAPI
.szOID_RSA_data, StringComparison.OrdinalIgnoreCase) == 0) {
319
safeCryptMsgHandle =
CAPI
.CryptMsgOpenToEncode(
CAPI
.X509_ASN_ENCODING |
CAPI
.PKCS_7_ASN_ENCODING,
320
Detached ?
CAPI
.CMSG_DETACHED_FLAG : 0,
321
CAPI
.CMSG_SIGNED,
327
safeCryptMsgHandle =
CAPI
.CryptMsgOpenToEncode(
CAPI
.X509_ASN_ENCODING |
CAPI
.PKCS_7_ASN_ENCODING,
328
Detached ?
CAPI
.CMSG_DETACHED_FLAG : 0,
329
CAPI
.CMSG_SIGNED,
340
if (!
CAPI
.CAPISafe.CryptMsgUpdate(safeCryptMsgHandle, this.ContentInfo.pContent, (uint) this.ContentInfo.Content.Length, true))
351
Marshal.DestroyStructure(pSignerEncodeInfo.DangerousGetHandle(), typeof(
CAPI
.CMSG_SIGNER_ENCODE_INFO));
373
CAPI
.CMSG_SIGNER_ENCODE_INFO signerEncodeInfo = PkcsUtils.CreateSignerEncodeInfo(signer, silent, out safeCryptProvHandle);
376
SafeLocalAllocHandle pSignerEncodeInfo =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(Marshal.SizeOf(typeof(
CAPI
.CMSG_SIGNER_ENCODE_INFO))));
383
if (!
CAPI
.CryptMsgControl(m_safeCryptMsgHandle,
385
CAPI
.CMSG_CTRL_ADD_SIGNER,
390
Marshal.DestroyStructure(pSignerEncodeInfo.DangerousGetHandle(), typeof(
CAPI
.CMSG_SIGNER_ENCODE_INFO));
412
SafeCryptMsgHandle safeCryptMsgHandle =
CAPI
.CAPISafe.CryptMsgOpenToDecode(
413
CAPI
.X509_ASN_ENCODING |
CAPI
.PKCS_7_ASN_ENCODING,
414
detached ?
CAPI
.CMSG_DETACHED_FLAG : 0,
423
if (!
CAPI
.CAPISafe.CryptMsgUpdate(safeCryptMsgHandle, encodedMessage, (uint) encodedMessage.Length, true))
427
if (
CAPI
.CMSG_SIGNED != PkcsUtils.GetMessageType(safeCryptMsgHandle))
428
throw new CryptographicException(
CAPI
.CRYPT_E_INVALID_MSG_TYPE);
435
if (!
CAPI
.CAPISafe.CryptMsgUpdate(safeCryptMsgHandle, content, (uint) content.Length, true))
447
throw new CryptographicException(
CAPI
.CRYPT_E_NO_SIGNER);
458
throw new CryptographicException(
CAPI
.CRYPT_E_NO_SIGNER);
system\security\cryptography\pkcs\signerinfo.cs (116)
34
private
CAPI
.CMSG_SIGNER_INFO m_cmsgSignerInfo;
53
m_cmsgSignerInfo = (
CAPI
.CMSG_SIGNER_INFO) Marshal.PtrToStructure(pbCmsgSignerInfo.DangerousGetHandle(), typeof(
CAPI
.CMSG_SIGNER_INFO));
67
if (!
CAPI
.DecodeObject(new IntPtr(
CAPI
.PKCS7_SIGNER_INFO),
79
m_cmsgSignerInfo = (
CAPI
.CMSG_SIGNER_INFO) Marshal.PtrToStructure(pbCmsgSignerInfo.DangerousGetHandle(), typeof(
CAPI
.CMSG_SIGNER_INFO));
155
throw new CryptographicException(
CAPI
.E_NOTIMPL);
163
throw new CryptographicException(
CAPI
.NTE_NO_KEY);
172
throw new CryptographicException(
CAPI
.E_NOTIMPL);
183
throw new CryptographicException(
CAPI
.E_NOTIMPL);
188
if (String.Compare(attribute.Oid.Value,
CAPI
.szOID_RSA_counterSign, StringComparison.OrdinalIgnoreCase) == 0) {
218
throw new CryptographicException(
CAPI
.CRYPT_E_SIGNER_NOT_FOUND);
233
throw new CryptographicException(
CAPI
.CRYPT_E_SIGNER_NOT_FOUND);
242
int cvseSize = Marshal.SizeOf(typeof(
CAPI
.CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA));
243
CAPI
.CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA cvse = new
CAPI
.CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA(cvseSize);
244
cvse.dwSignerType =
CAPI
.CMSG_VERIFY_SIGNER_NULL;
248
if (!
CAPI
.CryptMsgControl(m_signedCms.GetCryptMsgHandle(),
250
CAPI
.CMSG_CTRL_VERIFY_SIGNATURE_EX,
274
internal
CAPI
.CMSG_SIGNER_INFO GetCmsgSignerInfo () {
303
SafeLocalAllocHandle pSignerEncodeInfo =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(Marshal.SizeOf(typeof(
CAPI
.CMSG_SIGNER_ENCODE_INFO))));
305
CAPI
.CMSG_SIGNER_ENCODE_INFO signerEncodeInfo = PkcsUtils.CreateSignerEncodeInfo(signer, out safeCryptProvHandle);
312
if (!
CAPI
.CryptMsgCountersign(m_signedCms.GetCryptMsgHandle(),
324
Marshal.DestroyStructure(pSignerEncodeInfo.DangerousGetHandle(), typeof(
CAPI
.CMSG_SIGNER_ENCODE_INFO));
349
CAPI
.CERT_CONTEXT pCertContext = (
CAPI
.CERT_CONTEXT) Marshal.PtrToStructure(X509Utils.GetCertContext(certificate).DangerousGetHandle(), typeof(
CAPI
.CERT_CONTEXT));
352
IntPtr pSubjectPublicKeyInfo = new IntPtr((long) pCertContext.pCertInfo + (long) Marshal.OffsetOf(typeof(
CAPI
.CERT_INFO), "SubjectPublicKeyInfo"));
355
IntPtr pAlgorithm = new IntPtr((long) pSubjectPublicKeyInfo + (long) Marshal.OffsetOf(typeof(
CAPI
.CERT_PUBLIC_KEY_INFO), "Algorithm"));
358
IntPtr pParameters = new IntPtr((long) pAlgorithm + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPT_ALGORITHM_IDENTIFIER), "Parameters"));
364
CAPI
.CRYPT_OID_INFO pOIDInfo =
CAPI
.CryptFindOIDInfo(
CAPI
.CRYPT_OID_INFO_OID_KEY, pObjId,
CAPI
.CRYPT_PUBKEY_ALG_OID_GROUP_ID);
367
if (pOIDInfo.Algid ==
CAPI
.CALG_DSS_SIGN) {
371
IntPtr pcbData = new IntPtr((long) pParameters + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPTOAPI_BLOB), "cbData"));
372
IntPtr ppbData = new IntPtr((long) pParameters + (long) Marshal.OffsetOf(typeof(
CAPI
.CRYPTOAPI_BLOB), "pbData"));
383
if ((uint) Marshal.ReadInt32(pbData) ==
CAPI
.ASN_TAG_NULL) {
394
X509Utils.BuildChain(new IntPtr(
CAPI
.HCCE_CURRENT_USER),
410
if (!
CAPI
.CAPISafe.CertGetCertificateContextProperty(X509Utils.GetCertContext(certificate),
411
CAPI
.CERT_PUBKEY_ALG_PARA_PROP_ID,
417
pbParameters =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(cbParameters));
418
if (!
CAPI
.CAPISafe.CertGetCertificateContextProperty(X509Utils.GetCertContext(certificate),
419
CAPI
.CERT_PUBKEY_ALG_PARA_PROP_ID,
433
if (!
CAPI
.CryptMsgControl(m_signedCms.GetCryptMsgHandle(),
435
CAPI
.CMSG_CTRL_VERIFY_SIGNATURE,
469
CAPI
.CMSG_ENCODED_SIGNER,
476
lastWin32Error =
CAPI
.CRYPT_E_NO_SIGNER;
481
if (!
CAPI
.CAPISafe.CryptMsgVerifyCountersignatureEncoded(IntPtr.Zero,
482
CAPI
.X509_ASN_ENCODING |
CAPI
.PKCS_7_ASN_ENCODING,
505
if (hr !=
CAPI
.S_OK)
535
CAPI
.CMSG_CMS_SIGNER_INFO_PARAM,
540
CAPI
.CMSG_CMS_SIGNER_INFO cmsgCmsSignerInfo = (
CAPI
.CMSG_CMS_SIGNER_INFO) Marshal.PtrToStructure(pbCmsgCmsSignerInfo.DangerousGetHandle(), typeof(
CAPI
.CMSG_CMS_SIGNER_INFO));
546
CAPI
.CMSG_SIGNER_INFO_PARAM,
551
CAPI
.CMSG_SIGNER_INFO cmsgSignerInfo = (
CAPI
.CMSG_SIGNER_INFO) Marshal.PtrToStructure(pbCmsgSignerInfo.DangerousGetHandle(), typeof(
CAPI
.CMSG_SIGNER_INFO));
563
CAPI
.CRYPT_ATTRIBUTE attr = (
CAPI
.CRYPT_ATTRIBUTE) Marshal.PtrToStructure(pAttr, typeof(
CAPI
.CRYPT_ATTRIBUTE));
564
if (String.Compare(attr.pszObjId,
CAPI
.szOID_RSA_counterSign, StringComparison.OrdinalIgnoreCase) == 0) {
572
CAPI
.CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA delPara = new
CAPI
.CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA(Marshal.SizeOf(typeof(
CAPI
.CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA)));
576
if (!
CAPI
.CryptMsgControl(hMsg,
578
CAPI
.CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR,
588
uint cbCounterSignatureValue = (uint) ((attr.cValue - 1) * Marshal.SizeOf(typeof(
CAPI
.CRYPTOAPI_BLOB)));
589
SafeLocalAllocHandle pbCounterSignatureValue =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(cbCounterSignatureValue));
592
CAPI
.CRYPTOAPI_BLOB * pOldValue = (
CAPI
.CRYPTOAPI_BLOB *) attr.rgValue;
593
CAPI
.CRYPTOAPI_BLOB * pNewValue = (
CAPI
.CRYPTOAPI_BLOB *) pbCounterSignatureValue.DangerousGetHandle();
603
CAPI
.CRYPT_ATTRIBUTE newAttr = new
CAPI
.CRYPT_ATTRIBUTE();
608
SafeLocalAllocHandle pNewAttr =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr(Marshal.SizeOf(typeof(
CAPI
.CRYPT_ATTRIBUTE))));
612
if (!
CAPI
.EncodeObject(new IntPtr(
CAPI
.PKCS_ATTRIBUTE),
618
Marshal.DestroyStructure(pNewAttr.DangerousGetHandle(), typeof(
CAPI
.CRYPT_ATTRIBUTE));
624
CAPI
.CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA addPara = new
CAPI
.CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA(Marshal.SizeOf(typeof(
CAPI
.CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA)));
629
if (!
CAPI
.CryptMsgControl(hMsg,
631
CAPI
.CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR,
642
if (
CAPI
.EncodeObject(new IntPtr(
CAPI
.PKCS_ATTRIBUTE),
646
CAPI
.CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA addPara = new
CAPI
.CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA(Marshal.SizeOf(typeof(
CAPI
.CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA)));
650
CAPI
.CryptMsgControl(hMsg, 0,
CAPI
.CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR, new IntPtr(&addPara));
664
pAttr = new IntPtr((long) pAttr + (long) Marshal.SizeOf(typeof(
CAPI
.CRYPT_ATTRIBUTE)));
676
throw new CryptographicException(
CAPI
.CRYPT_E_NO_SIGNER);
695
new IntPtr(
CAPI
.CERT_CHAIN_POLICY_BASE),
697
if (hr !=
CAPI
.S_OK)
702
if (String.Compare(extension.Oid.Value,
CAPI
.szOID_KEY_USAGE, StringComparison.OrdinalIgnoreCase) == 0) {
707
hr =
CAPI
.CERT_E_WRONG_USAGE;
731
if (!
CAPI
.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle,
732
CAPI
.CMSG_SIGNER_COUNT_PARAM,
741
if (!
CAPI
.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle,
742
CAPI
.CMSG_SIGNER_INFO_PARAM,
748
SafeLocalAllocHandle pbCmsgSignerInfo =
CAPI
.LocalAlloc(
CAPI
.LMEM_FIXED, new IntPtr(cbCmsgSignerInfo));
750
if (!
CAPI
.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle,
751
CAPI
.CMSG_SIGNER_INFO_PARAM,
771
if (attribute.Oid.Value ==
CAPI
.szOID_RSA_counterSign) {
779
if (attribute.Oid.Value ==
CAPI
.szOID_RSA_counterSign) {
system\security\cryptography\x509\x509ui.cs (18)
55
int dwErrorCode =
CAPI
.ERROR_SUCCESS;
58
CAPI
.CRYPTUI_VIEWCERTIFICATE_STRUCTW ViewInfo = new
CAPI
.CRYPTUI_VIEWCERTIFICATE_STRUCTW();
79
if (!
CAPI
.CryptUIDlgViewCertificateW(ViewInfo, IntPtr.Zero))
84
if (dwErrorCode !=
CAPI
.ERROR_SUCCESS && dwErrorCode !=
CAPI
.ERROR_CANCELLED)
112
int dwErrorCode =
CAPI
.ERROR_SUCCESS;
115
SafeCertStoreHandle safeCertStoreHandle =
CAPI
.CertOpenStore((IntPtr)
CAPI
.CERT_STORE_PROV_MEMORY,
116
CAPI
.X509_ASN_ENCODING |
CAPI
.PKCS_7_ASN_ENCODING,
124
CAPI
.CRYPTUI_SELECTCERTIFICATE_STRUCTW csc = new
CAPI
.CRYPTUI_SELECTCERTIFICATE_STRUCTW();
127
csc.dwSize = (uint) Marshal.OffsetOf(typeof(
CAPI
.CRYPTUI_SELECTCERTIFICATE_STRUCTW), "hSelectedCertStore");
145
SafeCertContextHandle safeCertContextHandle =
CAPI
.CryptUIDlgSelectCertificateW(csc);
150
if (!
CAPI
.CertAddCertificateLinkToStore(safeCertStoreHandle,
152
CAPI
.CERT_STORE_ADD_ALWAYS,
157
if (dwErrorCode !=
CAPI
.ERROR_SUCCESS)
system\security\cryptography\x509\x509utils.cs (52)
36
dwFlags |=
CAPI
.CERT_CHAIN_REVOCATION_CHECK_CACHE_ONLY;
39
dwFlags |=
CAPI
.CERT_CHAIN_REVOCATION_CHECK_END_CERT;
41
dwFlags |=
CAPI
.CERT_CHAIN_REVOCATION_CHECK_CHAIN;
43
dwFlags |=
CAPI
.CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT;
130
SafeLocalAllocHandle pb =
CAPI
.LocalAlloc(
CAPI
.LMEM_FIXED, new IntPtr(arr.Length));
137
SafeCertContextHandle safeCertContext =
CAPI
.CertDuplicateCertificateContext(certificate.Handle);
146
if (!
CAPI
.CAPISafe.CertGetCertificateContextProperty(safeCertContext,
147
CAPI
.CERT_KEY_PROV_INFO_PROP_ID,
151
if (dwErrorCode ==
CAPI
.CRYPT_E_NOT_FOUND)
157
ptr =
CAPI
.LocalAlloc(
CAPI
.LMEM_FIXED, new IntPtr(cbData));
158
if (!
CAPI
.CAPISafe.CertGetCertificateContextProperty(safeCertContext,
159
CAPI
.CERT_KEY_PROV_INFO_PROP_ID,
163
if (dwErrorCode ==
CAPI
.CRYPT_E_NOT_FOUND)
169
CAPI
.CRYPT_KEY_PROV_INFO pKeyProvInfo = (
CAPI
.CRYPT_KEY_PROV_INFO) Marshal.PtrToStructure(ptr.DangerousGetHandle(), typeof(
CAPI
.CRYPT_KEY_PROV_INFO));
174
parameters.Flags = (CspProviderFlags) ((pKeyProvInfo.dwFlags &
CAPI
.CRYPT_MACHINE_KEYSET) ==
CAPI
.CRYPT_MACHINE_KEYSET ? CspProviderFlags.UseMachineKeyStore : 0);
197
safeCertStoreHandle =
CAPI
.CertOpenStore(new IntPtr(
CAPI
.CERT_STORE_PROV_MEMORY),
198
CAPI
.X509_ASN_ENCODING |
CAPI
.PKCS_7_ASN_ENCODING,
200
CAPI
.CERT_STORE_ENUM_ARCHIVED_FLAG |
CAPI
.CERT_STORE_CREATE_NEW_FLAG,
226
if (!
CAPI
.CertAddCertificateLinkToStore(safeCertStoreHandle,
228
CAPI
.CERT_STORE_ADD_ALWAYS,
238
CAPI
.CRYPT_OID_INFO pOIDInfo =
CAPI
.CryptFindOIDInfo(
CAPI
.CRYPT_OID_INFO_OID_KEY, pszOid, 0);
264
safeLocalAllocHandle =
CAPI
.LocalAlloc(
CAPI
.LPTR, new IntPtr((uint) ptrSize + (uint) oidSize));
282
IntPtr pEnumContext =
CAPI
.CertEnumCertificatesInStore(safeCertStoreHandle, IntPtr.Zero);
286
pEnumContext =
CAPI
.CertEnumCertificatesInStore(safeCertStoreHandle, pEnumContext);
309
CAPI
.CERT_CHAIN_PARA ChainPara = new
CAPI
.CERT_CHAIN_PARA();
317
ChainPara.RequestedUsage.dwType =
CAPI
.USAGE_MATCH_TYPE_AND;
326
ChainPara.RequestedIssuancePolicy.dwType =
CAPI
.USAGE_MATCH_TYPE_AND;
340
if (!
CAPI
.CAPISafe.CertGetCertificateChain(hChainEngine,
353
return
CAPI
.S_OK;
377
CAPI
.CERT_CHAIN_POLICY_PARA PolicyPara = new
CAPI
.CERT_CHAIN_POLICY_PARA(Marshal.SizeOf(typeof(
CAPI
.CERT_CHAIN_POLICY_PARA)));
378
CAPI
.CERT_CHAIN_POLICY_STATUS PolicyStatus = new
CAPI
.CERT_CHAIN_POLICY_STATUS(Marshal.SizeOf(typeof(
CAPI
.CERT_CHAIN_POLICY_STATUS)));
382
int hr = X509Utils.BuildChain(new IntPtr(
CAPI
.HCCE_CURRENT_USER),
392
if (hr !=
CAPI
.S_OK)
396
if (
CAPI
.CAPISafe.CertVerifyCertificateChainPolicy(pszPolicy, pChainContext, ref PolicyPara, ref PolicyStatus)) {
401
return
CAPI
.S_FALSE;
407
return
CAPI
.S_OK;
system\security\cryptography\xml\keyinfo.cs (2)
541
throw new CryptographicException(
CAPI
.CERT_E_CHAINING);
559
throw new CryptographicException(
CAPI
.CERT_E_CHAINING);
system\security\cryptography\xml\signedxml.cs (1)
317
if (String.Compare(extension.Oid.Value,
CAPI
.szOID_KEY_USAGE, StringComparison.OrdinalIgnoreCase) == 0) {