internal static unsafe IntPtr CreateCryptAttributes(CryptographicAttributeObjectCollection attributes) { if (attributes.Count == 0) { return(IntPtr.Zero); } uint num1 = 0U; uint num2 = PkcsUtils.AlignedLength((uint)Marshal.SizeOf(typeof(PkcsUtils.I_CRYPT_ATTRIBUTE))); uint num3 = PkcsUtils.AlignedLength((uint)Marshal.SizeOf(typeof(CAPI.CRYPTOAPI_BLOB))); foreach (CryptographicAttributeObject cryptographicAttributeObject in attributes) { num1 = num1 + num2 + PkcsUtils.AlignedLength((uint)(cryptographicAttributeObject.Oid.Value.Length + 1)); foreach (AsnEncodedData asnEncodedData in cryptographicAttributeObject.Values) { num1 = num1 + num3 + PkcsUtils.AlignedLength((uint)asnEncodedData.RawData.Length); } } SafeLocalAllocHandle localAllocHandle = CAPI.LocalAlloc(64U, new IntPtr((long)num1)); PkcsUtils.I_CRYPT_ATTRIBUTE *iCryptAttributePtr = (PkcsUtils.I_CRYPT_ATTRIBUTE *)(void *) localAllocHandle.DangerousGetHandle(); IntPtr num4 = new IntPtr((long)localAllocHandle.DangerousGetHandle() + (long)num2 * (long)attributes.Count); foreach (CryptographicAttributeObject cryptographicAttributeObject in attributes) { byte * numPtr = (byte *)(void *)num4; byte[] numArray = new byte[cryptographicAttributeObject.Oid.Value.Length + 1]; CAPI.CRYPTOAPI_BLOB *cryptoapiBlobPtr = (CAPI.CRYPTOAPI_BLOB *)(numPtr + (int)PkcsUtils.AlignedLength((uint)numArray.Length)); iCryptAttributePtr->pszObjId = (IntPtr)((void *)numPtr); iCryptAttributePtr->cValue = (uint)cryptographicAttributeObject.Values.Count; iCryptAttributePtr->rgValue = (IntPtr)((void *)cryptoapiBlobPtr); Encoding.ASCII.GetBytes(cryptographicAttributeObject.Oid.Value, 0, cryptographicAttributeObject.Oid.Value.Length, numArray, 0); Marshal.Copy(numArray, 0, iCryptAttributePtr->pszObjId, numArray.Length); IntPtr destination = new IntPtr((long)cryptoapiBlobPtr + (long)cryptographicAttributeObject.Values.Count * (long)num3); foreach (AsnEncodedData asnEncodedData in cryptographicAttributeObject.Values) { byte[] rawData = asnEncodedData.RawData; if (rawData.Length > 0) { cryptoapiBlobPtr->cbData = (uint)rawData.Length; cryptoapiBlobPtr->pbData = destination; Marshal.Copy(rawData, 0, destination, rawData.Length); destination = new IntPtr((long)destination + (long)PkcsUtils.AlignedLength((uint)rawData.Length)); } ++cryptoapiBlobPtr; } ++iCryptAttributePtr; num4 = destination; } GC.SuppressFinalize((object)localAllocHandle); return(localAllocHandle.DangerousGetHandle()); }