Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.3 KiB

  1. /*****************************************************************************\
  2. * MODULE: encrypt.cxx
  3. *
  4. * The module contains routines for encryption and decryption of data
  5. *
  6. * Copyright (C) 1996-1998 Microsoft Corporation
  7. *
  8. * History:
  9. * 05/19/00 WeihaiC Created
  10. *
  11. \*****************************************************************************/
  12. #include "precomp.h"
  13. //
  14. // The caller needs to call LocalFree to free the output data
  15. //
  16. BOOL
  17. EncryptData (
  18. PBYTE pDataInput,
  19. DWORD cbDataInput,
  20. PBYTE *ppDataOutput,
  21. PDWORD pcbDataOutput)
  22. {
  23. BOOL bRet = FALSE;
  24. DATA_BLOB DataIn;
  25. DATA_BLOB DataOut;
  26. DataIn.pbData = pDataInput;
  27. DataIn.cbData = cbDataInput;
  28. ZeroMemory (&DataOut, sizeof (DATA_BLOB));
  29. if(CryptProtectData(&DataIn,
  30. L"Encrypt", // A description sting.
  31. NULL, // Optional entropy not used.
  32. NULL, // Reserved.
  33. NULL, // Do not pass a PromptStruct.
  34. CRYPTPROTECT_UI_FORBIDDEN, // Never show UI
  35. &DataOut)) {
  36. bRet = TRUE;
  37. *ppDataOutput = DataOut.pbData;
  38. *pcbDataOutput = DataOut.cbData;
  39. }
  40. return bRet;
  41. }
  42. BOOL
  43. DecryptData (
  44. PBYTE pDataInput,
  45. DWORD cbDataInput,
  46. PBYTE *ppDataOutput,
  47. PDWORD pcbDataOutput)
  48. {
  49. BOOL bRet = FALSE;
  50. DATA_BLOB DataIn;
  51. DATA_BLOB DataOut;
  52. LPWSTR pDataDesp;
  53. DataIn.pbData = pDataInput;
  54. DataIn.cbData = cbDataInput;
  55. ZeroMemory (&DataOut, sizeof (DATA_BLOB));
  56. if(CryptUnprotectData(&DataIn,
  57. &pDataDesp, // A description sting.
  58. NULL, // Optional entropy not used.
  59. NULL, // Reserved.
  60. NULL, // Do not pass a PromptStruct.
  61. CRYPTPROTECT_UI_FORBIDDEN, // Never show UI
  62. &DataOut)) {
  63. bRet = TRUE;
  64. *ppDataOutput = DataOut.pbData;
  65. *pcbDataOutput = DataOut.cbData;
  66. LocalFree (pDataDesp);
  67. }
  68. return bRet;
  69. }