Esempio n. 1
0
        internal static RecipientInfoType GetRecipientInfoType(X509Certificate2 certificate)
        {
            RecipientInfoType recipientInfoType = RecipientInfoType.Unknown;

            if (certificate != null)
            {
                switch (X509Utils.OidToAlgId(((CAPI.CERT_INFO)Marshal.PtrToStructure(((CAPI.CERT_CONTEXT)Marshal.PtrToStructure(X509Utils.GetCertContext(certificate).DangerousGetHandle(), typeof(CAPI.CERT_CONTEXT))).pCertInfo, typeof(CAPI.CERT_INFO))).SubjectPublicKeyInfo.Algorithm.pszObjId))
                {
                case 41984U:
                    recipientInfoType = RecipientInfoType.KeyTransport;
                    break;

                case 43521U:
                case 43522U:
                    recipientInfoType = RecipientInfoType.KeyAgreement;
                    break;

                default:
                    recipientInfoType = RecipientInfoType.Unknown;
                    break;
                }
            }
            return(recipientInfoType);
        }
Esempio n. 2
0
        internal AlgorithmIdentifier(CAPI.CRYPT_ALGORITHM_IDENTIFIER algorithmIdentifier)
        {
            int  keyLength      = 0;
            uint cbDecodedValue = 0U;
            SafeLocalAllocHandle decodedValue = SafeLocalAllocHandle.InvalidHandle;

            byte[] numArray = new byte[0];
            uint   num      = X509Utils.OidToAlgId(algorithmIdentifier.pszObjId);

            switch (num)
            {
            case 26114U:
                if (algorithmIdentifier.Parameters.cbData > 0U)
                {
                    if (!CAPI.DecodeObject(new IntPtr(41L), algorithmIdentifier.Parameters.pbData, algorithmIdentifier.Parameters.cbData, out decodedValue, out cbDecodedValue))
                    {
                        throw new CryptographicException(Marshal.GetLastWin32Error());
                    }
                    CAPI.CRYPT_RC2_CBC_PARAMETERS rc2CbcParameters = (CAPI.CRYPT_RC2_CBC_PARAMETERS)Marshal.PtrToStructure(decodedValue.DangerousGetHandle(), typeof(CAPI.CRYPT_RC2_CBC_PARAMETERS));
                    switch (rc2CbcParameters.dwVersion)
                    {
                    case 52U:
                        keyLength = 56;
                        break;

                    case 58U:
                        keyLength = 128;
                        break;

                    case 160U:
                        keyLength = 40;
                        break;
                    }
                    if (rc2CbcParameters.fIV)
                    {
                        numArray = (byte[])rc2CbcParameters.rgbIV.Clone();
                        break;
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }

            case 26625U:
            case 26113U:
            case 26115U:
                if (algorithmIdentifier.Parameters.cbData > 0U)
                {
                    if (!CAPI.DecodeObject(new IntPtr(25L), algorithmIdentifier.Parameters.pbData, algorithmIdentifier.Parameters.cbData, out decodedValue, out cbDecodedValue))
                    {
                        throw new CryptographicException(Marshal.GetLastWin32Error());
                    }
                    if (cbDecodedValue > 0U)
                    {
                        if ((int)num == 26625)
                        {
                            CAPI.CRYPTOAPI_BLOB cryptoapiBlob = (CAPI.CRYPTOAPI_BLOB)Marshal.PtrToStructure(decodedValue.DangerousGetHandle(), typeof(CAPI.CRYPTOAPI_BLOB));
                            if (cryptoapiBlob.cbData > 0U)
                            {
                                numArray = new byte[(IntPtr)cryptoapiBlob.cbData];
                                Marshal.Copy(cryptoapiBlob.pbData, numArray, 0, numArray.Length);
                            }
                        }
                        else
                        {
                            numArray = new byte[(IntPtr)cbDecodedValue];
                            Marshal.Copy(decodedValue.DangerousGetHandle(), numArray, 0, numArray.Length);
                        }
                    }
                }
                keyLength = (int)num != 26625 ? ((int)num != 26113 ? 192 : 64) : 128 - numArray.Length * 8;
                break;

            default:
                if (algorithmIdentifier.Parameters.cbData > 0U)
                {
                    numArray = new byte[(IntPtr)algorithmIdentifier.Parameters.cbData];
                    Marshal.Copy(algorithmIdentifier.Parameters.pbData, numArray, 0, numArray.Length);
                    break;
                }
                else
                {
                    break;
                }
            }
            this.Reset(new Oid(algorithmIdentifier.pszObjId), keyLength, numArray);
            decodedValue.Dispose();
        }