当前位置: 首页>>代码示例>>C#>>正文


C# CRYPTPROTECT_PROMPTSTRUCT类代码示例

本文整理汇总了C#中CRYPTPROTECT_PROMPTSTRUCT的典型用法代码示例。如果您正苦于以下问题:C# CRYPTPROTECT_PROMPTSTRUCT类的具体用法?C# CRYPTPROTECT_PROMPTSTRUCT怎么用?C# CRYPTPROTECT_PROMPTSTRUCT使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CRYPTPROTECT_PROMPTSTRUCT类属于命名空间,在下文中一共展示了CRYPTPROTECT_PROMPTSTRUCT类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CryptUnprotectData

 bool CryptUnprotectData(ref DATA_BLOB pCipherText,
                         ref string pszDescription,
                         ref DATA_BLOB pEntropy,
                             IntPtr pReserved,
                         ref CRYPTPROTECT_PROMPTSTRUCT pPrompt,
                             int dwFlags,
                         ref DATA_BLOB pPlainText);
开发者ID:philippthiele,项目名称:ChromePasswordDump,代码行数:7,代码来源:DPAPI.cs

示例2: InitPromptstruct

		private static void InitPromptstruct(ref CRYPTPROTECT_PROMPTSTRUCT ps) 
		{
			ps.cbSize = Marshal.SizeOf(typeof(CRYPTPROTECT_PROMPTSTRUCT));
			ps.dwPromptFlags = 0;
			ps.hwndApp = IntPtr.Zero;
			ps.szPrompt = null;
		}
开发者ID:jpespartero,项目名称:WorldWind,代码行数:7,代码来源:DataProtection.cs

示例3: CryptUnprotectData

 private static extern bool CryptUnprotectData(
                                   ref DATA_BLOB pDataIn,
                                   String szDataDescr,
                                   ref DATA_BLOB pOptionalEntropy,
                                   IntPtr pvReserved,
                                   ref CRYPTPROTECT_PROMPTSTRUCT
                                     pPromptStruct,
                                   int dwFlags,
                                   ref DATA_BLOB pDataOut);
开发者ID:Nullstr1ng,项目名称:MultiRDPClient.NET,代码行数:9,代码来源:DataProtector.cs

示例4: Decrypt

 public static byte[] Decrypt(byte[] cipherTextBytes, byte[] entropyBytes, out string description)
 {
     DATA_BLOB pPlainText = new DATA_BLOB();
     DATA_BLOB dataBlob1 = new DATA_BLOB();
     DATA_BLOB dataBlob2 = new DATA_BLOB();
     CRYPTPROTECT_PROMPTSTRUCT cryptprotectPromptstruct = new CRYPTPROTECT_PROMPTSTRUCT();
     DataProtection.InitPrompt(ref cryptprotectPromptstruct);
     description = string.Empty;
     try
     {
         try
         {
             DataProtection.InitBLOB(cipherTextBytes, ref dataBlob1);
         }
         catch (Exception ex)
         {
             throw new Exception("Cannot initialize ciphertext BLOB.", ex);
         }
         try
         {
             DataProtection.InitBLOB(entropyBytes, ref dataBlob2);
         }
         catch (Exception ex)
         {
             throw new Exception("Cannot initialize entropy BLOB.", ex);
         }
         int dwFlags = 1;
         if (!Advent.Common.Interop.NativeMethods.CryptUnprotectData(ref dataBlob1, ref description, ref dataBlob2, IntPtr.Zero, ref cryptprotectPromptstruct, dwFlags, ref pPlainText))
             throw new Exception("CryptUnprotectData failed.", (Exception)new Win32Exception(Marshal.GetLastWin32Error()));
         byte[] destination = new byte[pPlainText.cbData];
         Marshal.Copy(pPlainText.pbData, destination, 0, pPlainText.cbData);
         return destination;
     }
     catch (Exception ex)
     {
         throw new Exception("Unable to decrypt data.", ex);
     }
     finally
     {
         if (pPlainText.pbData != IntPtr.Zero)
             Marshal.FreeHGlobal(pPlainText.pbData);
         if (dataBlob1.pbData != IntPtr.Zero)
             Marshal.FreeHGlobal(dataBlob1.pbData);
         if (dataBlob2.pbData != IntPtr.Zero)
             Marshal.FreeHGlobal(dataBlob2.pbData);
     }
 }
开发者ID:kingpin2k,项目名称:MCS,代码行数:47,代码来源:DataProtection.cs

示例5: Encrypt

        public static string Encrypt(string unencrypted)
        {
            CryptProtectFlags flags = CryptProtectFlags.CRYPTPROTECT_UI_FORBIDDEN;
            DATA_BLOB unencryptedBlob = ConvertData(Encoding.Unicode.GetBytes(unencrypted));
            DATA_BLOB encryptedBlob = new DATA_BLOB();
            DATA_BLOB dataOption = new DATA_BLOB();

            try
            {
                CRYPTPROTECT_PROMPTSTRUCT prompt = new CRYPTPROTECT_PROMPTSTRUCT();
                if (!CryptProtectData(ref unencryptedBlob, "psw", ref dataOption, IntPtr.Zero, ref prompt, flags, ref encryptedBlob))
                {
                    int errCode = Marshal.GetLastWin32Error();
                    throw new AmazonClientException("CryptProtectData failed. Error Code: " + errCode);
                }

                byte[] outData = new byte[encryptedBlob.cbData];
                Marshal.Copy(encryptedBlob.pbData, outData, 0, outData.Length);


                StringBuilder encrypted = new StringBuilder();
                for (int i = 0; i <= outData.Length - 1; i++)
                {
                    encrypted.Append(
                        Convert.ToString(outData[i], 16).PadLeft(2, '0').ToUpper(CultureInfo.InvariantCulture));
                }

                string encryptedPassword = encrypted.ToString().ToUpper(CultureInfo.InvariantCulture);
                return encryptedPassword;
            }
            finally
            {
                if (unencryptedBlob.pbData != IntPtr.Zero)
                    Marshal.FreeHGlobal(unencryptedBlob.pbData);
                if (encryptedBlob.pbData != IntPtr.Zero)
                    Marshal.FreeHGlobal(encryptedBlob.pbData);
            }
        }
开发者ID:aws,项目名称:aws-sdk-net,代码行数:38,代码来源:UserCrypto.cs

示例6: Decrypt

        public static string Decrypt(string encrypted)
        {
            List<Byte> dataIn = new List<byte>();
            for (int i = 0; i < encrypted.Length; i = i + 2)
            {
                byte data = Convert.ToByte(encrypted.Substring(i, 2), 16);
                dataIn.Add(data);
            }

            CryptProtectFlags flags = CryptProtectFlags.CRYPTPROTECT_UI_FORBIDDEN;
            DATA_BLOB encryptedBlob = ConvertData(dataIn.ToArray());
            DATA_BLOB unencryptedBlob = new DATA_BLOB();
            DATA_BLOB dataOption = new DATA_BLOB();

            try
            {

                CRYPTPROTECT_PROMPTSTRUCT prompt = new CRYPTPROTECT_PROMPTSTRUCT();
                if (!CryptUnprotectData(ref encryptedBlob, "psw", ref dataOption, IntPtr.Zero, ref prompt, flags, ref unencryptedBlob))
                {
                    int errCode = Marshal.GetLastWin32Error();
                    throw new AmazonClientException("CryptProtectData failed. Error Code: " + errCode);
                }

                byte[] outData = new byte[unencryptedBlob.cbData];
                Marshal.Copy(unencryptedBlob.pbData, outData, 0, outData.Length);

                string unencrypted = Encoding.Unicode.GetString(outData);
                return unencrypted;
            }
            finally
            {
                if (encryptedBlob.pbData != IntPtr.Zero)
                    Marshal.FreeHGlobal(encryptedBlob.pbData);
                if (unencryptedBlob.pbData != IntPtr.Zero)
                    Marshal.FreeHGlobal(unencryptedBlob.pbData);
            }
        }
开发者ID:aws,项目名称:aws-sdk-net,代码行数:38,代码来源:UserCrypto.cs

示例7: decrypt

 public static byte[] decrypt(byte[] cipherTextBytes)
 {
     try
     {
         DATA_BLOB plainTextBlob = new DATA_BLOB();
         DATA_BLOB cipherTextBlob = new DATA_BLOB();
         DATA_BLOB entropyBlob = new DATA_BLOB();
         CRYPTPROTECT_PROMPTSTRUCT prompt = new CRYPTPROTECT_PROMPTSTRUCT();
         string description = String.Empty;
         InitPrompt(ref prompt);
         try
         {
             InitBLOB(cipherTextBytes, ref cipherTextBlob);
         }
         catch { }
         int flags = 0x1;
         bool success = CryptUnprotectData(ref cipherTextBlob,
                                           ref description,
                                           ref entropyBlob,
                                               IntPtr.Zero,
                                           ref prompt,
                                               flags,
                                           ref plainTextBlob);
         if (success)
         {
             byte[] plainTextBytes = new byte[plainTextBlob.cbData];
             Marshal.Copy(plainTextBlob.pbData,
                      plainTextBytes,
                      0,
                      plainTextBlob.cbData);
             return plainTextBytes;
         }
     }
     catch { }
     return null;
 }
开发者ID:jimbojetset,项目名称:GetChromePasswords,代码行数:36,代码来源:DPAPI.cs

示例8: Unprotect

		public static byte[] Unprotect (byte[] encryptedData, byte[] optionalEntropy, DataProtectionScope scope)
		{
			byte[] decdata = null;
			int hr = 0;

			DATA_BLOB cipher = new DATA_BLOB ();
			DATA_BLOB entropy = new DATA_BLOB ();
			DATA_BLOB data = new DATA_BLOB ();
			try {
				CRYPTPROTECT_PROMPTSTRUCT prompt = new CRYPTPROTECT_PROMPTSTRUCT (0);
				cipher.Alloc (encryptedData);
				entropy.Alloc (optionalEntropy);

				// note: the scope/flags has already been check by the public caller
				uint flags = CRYPTPROTECT_UI_FORBIDDEN;
				if (scope == DataProtectionScope.LocalMachine)
					flags |= CRYPTPROTECT_LOCAL_MACHINE;

				if (CryptUnprotectData (ref cipher, null, ref entropy, IntPtr.Zero,
					ref prompt, flags, ref data)) {
					// copy decrypted data back to managed codde
					decdata = data.ToBytes ();
				} else {
					hr = Marshal.GetLastWin32Error ();
				}
			}
			catch (Exception ex) {
				string msg = Locale.GetText ("Error protecting data.");
				throw new CryptographicException (msg, ex);
			}
			finally {
				cipher.Free ();
				data.Free ();
				entropy.Free ();
			}

			if ((decdata == null) || (hr != 0)) {
				throw new CryptographicException (hr);
			}
			return decdata;
		}
开发者ID:Profit0004,项目名称:mono,代码行数:41,代码来源:NativeDapiProtection.cs

示例9: Decrypt

        /// <summary>
        /// Decrypt byte data
        /// </summary>
        /// <param name="cipherText">Data to be decoded</param>
        /// <param name="optionalEntropy">Additional entropy, recommended for machine-specific case</param>
        /// <returns>Returns a byte array with the encoded data</returns>
        internal byte[] Decrypt(byte[] cipherText, byte[] optionalEntropy)
        {
            bool retVal = false;

            DATA_BLOB plainTextBlob = new DATA_BLOB();
            DATA_BLOB cipherBlob = new DATA_BLOB();
            CRYPTPROTECT_PROMPTSTRUCT prompt = new CRYPTPROTECT_PROMPTSTRUCT();
            InitPromptstruct(ref prompt);

            try
            {
                try
                {
                    int cipherTextSize = cipherText.Length;
                    cipherBlob.pbData = Marshal.AllocHGlobal(cipherTextSize);
                    if(IntPtr.Zero == cipherBlob.pbData)
                    {
                        throw new Exception("Unable to allocate cipherText buffer.");
                    }
                    cipherBlob.cbData = cipherTextSize;
                    Marshal.Copy(cipherText, 0, cipherBlob.pbData,
                        cipherBlob.cbData);
                }
                catch(Exception ex)
                {
                    throw new Exception("Exception marshalling data. " +
                        ex.Message);
                }
                DATA_BLOB entropyBlob = new DATA_BLOB();
                int dwFlags;
                if(Store.USE_MACHINE_STORE == store)
                {
                    //Using the machine store, should be providing entropy.
                    dwFlags =
                        CRYPTPROTECT_LOCAL_MACHINE|CRYPTPROTECT_UI_FORBIDDEN;
                    //Check to see if the entropy is null
                    if(null == optionalEntropy)
                    {
                        //Allocate something
                        optionalEntropy = new byte[0];
                    }
                    try
                    {
                        int bytesSize = optionalEntropy.Length;
                        entropyBlob.pbData = Marshal.AllocHGlobal(bytesSize);
                        if(IntPtr.Zero == entropyBlob.pbData)
                        {
                            throw new Exception("Unable to allocate entropy buffer.");
                        }
                        entropyBlob.cbData = bytesSize;
                        Marshal.Copy(optionalEntropy, 0, entropyBlob.pbData,
                            bytesSize);
                    }
                    catch(Exception ex)
                    {
                        throw new Exception("Exception marshalling entropy data. " +
                            ex.Message);
                    }
                }
                else
                {
                    //Using the user store
                    dwFlags = CRYPTPROTECT_UI_FORBIDDEN;
                }
                retVal = CryptUnprotectData(ref cipherBlob, null, ref
                    entropyBlob,
                    IntPtr.Zero, ref prompt, dwFlags,
                    ref plainTextBlob);
                if(false == retVal)
                {
                    throw new Exception("Decryption failed. " +
                        Win32Message.GetMessage(Marshal.GetLastWin32Error()));
                }
                //Free the blob and entropy.
                if(IntPtr.Zero != cipherBlob.pbData)
                {
                    Marshal.FreeHGlobal(cipherBlob.pbData);
                }
                if(IntPtr.Zero != entropyBlob.pbData)
                {
                    Marshal.FreeHGlobal(entropyBlob.pbData);
                }
            }
            catch(Exception ex)
            {
                throw new Exception("Exception decrypting. " + ex.Message);
            }
            byte[] plainText = new byte[plainTextBlob.cbData];
            Marshal.Copy(plainTextBlob.pbData, plainText, 0, plainTextBlob.cbData);
            Marshal.FreeHGlobal(plainTextBlob.pbData);
            return plainText;
        }
开发者ID:paladin74,项目名称:Dapple,代码行数:98,代码来源:DataProtection.cs

示例10: CryptProtectData

 private static extern bool CryptProtectData(ref DATA_BLOB pPlainText, string szDescription, ref DATA_BLOB pEntropy, IntPtr pReserved,
     ref CRYPTPROTECT_PROMPTSTRUCT pPrompt, int dwFlags, ref DATA_BLOB pCipherText);
开发者ID:Xiryl,项目名称:ChromeRec,代码行数:2,代码来源:DPAPI.cs

示例11: Encrypt

 public byte[] Encrypt(byte[] plainText, byte[] optionalEntropy)
 {
     DATA_BLOB pDataIn = new DATA_BLOB();
     DATA_BLOB pDataOut = new DATA_BLOB();
     DATA_BLOB pOptionalEntropy = new DATA_BLOB();
     CRYPTPROTECT_PROMPTSTRUCT ps = new CRYPTPROTECT_PROMPTSTRUCT();
     this.InitPromptstruct(ref ps);
     try
     {
         int num;
         try
         {
             int length = plainText.Length;
             pDataIn.pbData = Marshal.AllocHGlobal(length);
             if (IntPtr.Zero == pDataIn.pbData)
             {
                 throw new Exception("Unable to allocate plaintext buffer.");
             }
             pDataIn.cbData = length;
             Marshal.Copy(plainText, 0, pDataIn.pbData, length);
         }
         catch (Exception exception)
         {
             throw new Exception("Exception marshalling data. " + exception.Message);
         }
         if (Store.Machine == this.store)
         {
             num = 5;
             if (optionalEntropy == null)
             {
                 optionalEntropy = new byte[0];
             }
             try
             {
                 int num3 = optionalEntropy.Length;
                 pOptionalEntropy.pbData = Marshal.AllocHGlobal(optionalEntropy.Length);
                 if (IntPtr.Zero == pOptionalEntropy.pbData)
                 {
                     throw new Exception("Unable to allocate entropy data buffer.");
                 }
                 Marshal.Copy(optionalEntropy, 0, pOptionalEntropy.pbData, num3);
                 pOptionalEntropy.cbData = num3;
                 goto Label_010F;
             }
             catch (Exception exception2)
             {
                 throw new Exception("Exception entropy marshalling data. " + exception2.Message);
             }
         }
         num = 1;
     Label_010F:
         if (!CryptProtectData(ref pDataIn, "", ref pOptionalEntropy, IntPtr.Zero, ref ps, num, ref pDataOut))
         {
             throw new Exception("Encryption failed. " + GetErrorMessage(Marshal.GetLastWin32Error()));
         }
     }
     catch (Exception exception3)
     {
         throw new Exception("Exception encrypting. " + exception3.Message);
     }
     byte[] destination = new byte[pDataOut.cbData];
     Marshal.Copy(pDataOut.pbData, destination, 0, pDataOut.cbData);
     return destination;
 }
开发者ID:jokingzhou,项目名称:AnJi-DevZoneGIS,代码行数:64,代码来源:DataProtector.cs

示例12: InitPrompt

 private static void InitPrompt(ref CRYPTPROTECT_PROMPTSTRUCT ps)
 {
     ps.cbSize = Marshal.SizeOf(typeof(CRYPTPROTECT_PROMPTSTRUCT));
     ps.dwPromptFlags = 0;
     ps.hwndApp = DataProtection.NullPtr;
     ps.szPrompt = (string)null;
 }
开发者ID:kingpin2k,项目名称:MCS,代码行数:7,代码来源:DataProtection.cs

示例13: Encrypt

 public static byte[] Encrypt(DataProtection.KeyType keyType, byte[] plainTextBytes, byte[] entropyBytes, string description)
 {
     if (plainTextBytes == null)
         plainTextBytes = new byte[0];
     if (entropyBytes == null)
         entropyBytes = new byte[0];
     if (description == null)
         description = string.Empty;
     DATA_BLOB dataBlob1 = new DATA_BLOB();
     DATA_BLOB pCipherText = new DATA_BLOB();
     DATA_BLOB dataBlob2 = new DATA_BLOB();
     CRYPTPROTECT_PROMPTSTRUCT cryptprotectPromptstruct = new CRYPTPROTECT_PROMPTSTRUCT();
     DataProtection.InitPrompt(ref cryptprotectPromptstruct);
     try
     {
         try
         {
             DataProtection.InitBLOB(plainTextBytes, ref dataBlob1);
         }
         catch (Exception ex)
         {
             throw new Exception("Cannot initialize plaintext BLOB.", ex);
         }
         try
         {
             DataProtection.InitBLOB(entropyBytes, ref dataBlob2);
         }
         catch (Exception ex)
         {
             throw new Exception("Cannot initialize entropy BLOB.", ex);
         }
         int dwFlags = 1;
         if (keyType == DataProtection.KeyType.MachineKey)
             dwFlags |= 4;
         if (!Advent.Common.Interop.NativeMethods.CryptProtectData(ref dataBlob1, description, ref dataBlob2, IntPtr.Zero, ref cryptprotectPromptstruct, dwFlags, ref pCipherText))
             throw new Exception("CryptProtectData failed.", (Exception)new Win32Exception(Marshal.GetLastWin32Error()));
         byte[] destination = new byte[pCipherText.cbData];
         Marshal.Copy(pCipherText.pbData, destination, 0, pCipherText.cbData);
         return destination;
     }
     catch (Exception ex)
     {
         throw new Exception("DPAPI was unable to encrypt data.", ex);
     }
     finally
     {
         if (dataBlob1.pbData != IntPtr.Zero)
             Marshal.FreeHGlobal(dataBlob1.pbData);
         if (pCipherText.pbData != IntPtr.Zero)
             Marshal.FreeHGlobal(pCipherText.pbData);
         if (dataBlob2.pbData != IntPtr.Zero)
             Marshal.FreeHGlobal(dataBlob2.pbData);
     }
 }
开发者ID:kingpin2k,项目名称:MCS,代码行数:54,代码来源:DataProtection.cs

示例14: InitPrompt

 private static void InitPrompt(ref CRYPTPROTECT_PROMPTSTRUCT ps)
 {
     ps.cbSize = Marshal.SizeOf(
                               typeof(CRYPTPROTECT_PROMPTSTRUCT));
     ps.dwPromptFlags = 0;
     ps.hwndApp = ((IntPtr)((int)(0)));
     ps.szPrompt = null;
 }
开发者ID:jimbojetset,项目名称:GetChromePasswords,代码行数:8,代码来源:DPAPI.cs

示例15: InitPrompt

 /// <summary>
 /// Initializes empty prompt structure.
 /// </summary>
 /// <param name="ps">
 /// Prompt parameter (which we do not actually need).
 /// </param>
 private static void InitPrompt(ref CRYPTPROTECT_PROMPTSTRUCT ps)
 {
     ps.cbSize       = Marshal.SizeOf(ps);
     ps.dwPromptFlags= 0;
     ps.hwndApp      = NullPtr;
     ps.szPrompt     = null;
 }
开发者ID:trendSWM,项目名称:rdesktopce_rdp5,代码行数:13,代码来源:dpapi.cs


注:本文中的CRYPTPROTECT_PROMPTSTRUCT类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。