Beispiel #1
0
 /// <summary>
 ///helper method that fills in a DATA_BLOB, copies  
 ///data from managed to unmanaged memory
 /// </summary>
 /// <param name="blob"></param>
 /// <param name="bits"></param>
 private static void SetBlobData(ref Crypt32.DATA_BLOB blob, byte[] bits)
 {
     blob.cbData = bits.Length;
     blob.pbData = Marshal.AllocHGlobal(bits.Length);
     Marshal.Copy(bits, 0, blob.pbData, bits.Length);
 }
Beispiel #2
0
        /// <summary>
        ///helper method that gets data from a DATA_BLOB,
        ///copies data from unmanaged memory to managed
        /// </summary>
        /// <param name="blob"></param>
        /// <returns></returns>
        private static byte[] GetBlobData(ref Crypt32.DATA_BLOB blob)
        {
            // return an empty string if the blob is empty
            if (blob.pbData.ToInt32() == 0)
                return null;

            // copy information from the blob
            byte[] data = new byte[blob.cbData];
            Marshal.Copy(blob.pbData, data, 0, blob.cbData);
            Kernel32.LocalFree(blob.pbData);

            return data;
        }