Inheritance: System.Runtime.InteropServices.SafeHandle
Beispiel #1
0
 internal extern static int NCryptProtectSecret(
     [In] NCryptProtectionDescriptorHandle hDescriptor,
     [In] uint dwFlags,
     [In] byte[] pbData,
     [In] uint cbData,
     [In] IntPtr pMemPara,
     [In] IntPtr hWnd,
     [Out] out LocalAllocHandle ppbProtectedBlob,
     [Out] out uint pcbProtectedBlob);
Beispiel #2
0
        public static byte[] Protect(NCryptProtectionDescriptorHandle descriptor, byte[] data)
        {
            LocalAllocHandle protectedBlobHandle;
            uint cbProtectedBlob;
            int status = NativeMethods.NCryptProtectSecret(descriptor, NCRYPT_SILENT_FLAG, data, (uint)data.Length, IntPtr.Zero, IntPtr.Zero, out protectedBlobHandle, out cbProtectedBlob);
            Util.ThrowExceptionForCryptoStatus(status);

            using (protectedBlobHandle)
            {
                byte[] retVal = new byte[cbProtectedBlob];
                Marshal.Copy(protectedBlobHandle.DangerousGetHandle(), retVal, 0, retVal.Length);
                return retVal;
            }
        }
Beispiel #3
0
        public static byte[] Protect(NCryptProtectionDescriptorHandle descriptor, byte[] data)
        {
            LocalAllocHandle protectedBlobHandle;
            uint             cbProtectedBlob;
            int status = NativeMethods.NCryptProtectSecret(descriptor, NCRYPT_SILENT_FLAG, data, (uint)data.Length, IntPtr.Zero, IntPtr.Zero, out protectedBlobHandle, out cbProtectedBlob);

            Util.ThrowExceptionForCryptoStatus(status);

            using (protectedBlobHandle)
            {
                byte[] retVal = new byte[cbProtectedBlob];
                Marshal.Copy(protectedBlobHandle.DangerousGetHandle(), retVal, 0, retVal.Length);
                return(retVal);
            }
        }
 // ASP.NET will call this API for us automatically. The 'applicationName' parameter comes from config,
 // and the 'primaryPurpose' and 'specificPurposes' parameters are generated automatically.
 public DpapiNGDataProtector(string protectionDescriptor, string applicationName, string primaryPurpose, string[] specificPurposes)
     : base(applicationName, primaryPurpose, specificPurposes)
 {
     _protectionDescriptorLazy = new Lazy<NCryptProtectionDescriptorHandle>(() => NCryptProtectionDescriptorHandle.Create(protectionDescriptor));
 }
Beispiel #5
0
 internal extern static int NCryptCreateProtectionDescriptor(
     [In] string pwszDescriptorString,
     [In] uint dwFlags,
     [Out] out NCryptProtectionDescriptorHandle phDescriptor);