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.

141 lines
4.0 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. ioutest.cpp
  5. Abstract:
  6. incident object unit test
  7. Revision History:
  8. DerekM created 07/14/99
  9. ********************************************************************/
  10. #include <module.h>
  11. #include <mpc_utils.h>
  12. #include <mpc_com.h>
  13. #include <MPC_streams.h>
  14. #include <stdio.h>
  15. #include "HelpServiceTypeLib.h"
  16. #include "HelpServiceTypeLib_i.c"
  17. #include "HelpCenterTypeLib.h"
  18. #include "HelpCenterTypeLib_i.c"
  19. // #include "hsi.h"
  20. #include <fci.h>
  21. #include <initguid.h>
  22. #include <msscript.h>
  23. #include <encrypt.h>
  24. #include <SvcUtils.h>
  25. // **************************************************************************
  26. int __cdecl wmain(int argc, WCHAR **argv, WCHAR **envp)
  27. {
  28. __MPC_FUNC_ENTRY( COMMONID, "Encryption Testing" );
  29. CComObject<CSAFEncrypt> *pEO = NULL;
  30. CComBSTR bstrToBeEncrypted;
  31. CComBSTR bstrPassword;
  32. CComBSTR bstrEncryptedString;
  33. CComBSTR bstrDecryptedString;
  34. IUnknown *punkPlainStm;
  35. IUnknown *punkEncryptedStream;
  36. IUnknown *punkDecryptedStream;
  37. CComPtr<IStream> streamPlain;
  38. CComPtr<IStream> streamEncrypted;
  39. CComPtr<IStream> streamDecrypted;
  40. CComPtr<IStream> streamEncryptedOutput;
  41. CComPtr<IStream> streamDecryptedOutput;
  42. unsigned int uiLen;
  43. HRESULT hr = NOERROR;
  44. hr = CoInitialize(NULL);
  45. if (FAILED(hr))
  46. return hr;
  47. hr = CComObject<CSAFEncrypt>::CreateInstance(&pEO);
  48. if (FAILED(hr))
  49. goto done;
  50. bstrToBeEncrypted = L"Encrypt this string";
  51. bstrPassword = L"Password";
  52. bstrToBeEncrypted = L"Will you encrypt this string please?";
  53. bstrPassword = L"Pwd";
  54. // Tests for the String Encryption.
  55. hr = pEO->EncryptString(bstrPassword, bstrToBeEncrypted, &bstrEncryptedString);
  56. if (FAILED(hr))
  57. goto done;
  58. // Get the length of the encrypted String.
  59. uiLen = bstrEncryptedString.Length();
  60. hr = pEO->DecryptString( bstrPassword, bstrEncryptedString, &bstrDecryptedString);
  61. if (FAILED(hr))
  62. goto done;
  63. uiLen = bstrDecryptedString.Length();
  64. // Tests for the File Encryption
  65. hr = pEO->EncryptFile(bstrPassword, L"D:\\enc.xml", L"D:\\enc1.xml");
  66. if (FAILED(hr))
  67. goto done;
  68. hr = pEO->DecryptFile(bstrPassword, L"D:\\enc1.xml", L"D:\\enc2.xml");
  69. if (FAILED(hr))
  70. goto done;
  71. // Tests for Stream Encryption
  72. __MPC_EXIT_IF_METHOD_FAILS(hr, SVC::OpenStreamForRead( L"D:\\test.enc" , &streamPlain ));
  73. __MPC_EXIT_IF_METHOD_FAILS(hr, pEO->EncryptStream(bstrPassword, streamPlain, &punkEncryptedStream));
  74. __MPC_EXIT_IF_METHOD_FAILS(hr, punkEncryptedStream->QueryInterface( IID_IStream, (void**)&streamEncrypted ));
  75. __MPC_EXIT_IF_METHOD_FAILS(hr, SVC::OpenStreamForWrite( L"D:\\test1.enc", &streamEncryptedOutput ));
  76. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::BaseStream::TransferData( streamEncrypted, streamEncryptedOutput ));
  77. // Tests for Stream Decryption
  78. __MPC_EXIT_IF_METHOD_FAILS(hr, SVC::OpenStreamForRead( L"D:\\test2.enc" , &streamEncryptedOutput ));
  79. __MPC_EXIT_IF_METHOD_FAILS(hr, pEO->DecryptStream(bstrPassword, streamEncryptedOutput, &punkDecryptedStream));
  80. __MPC_EXIT_IF_METHOD_FAILS(hr, punkDecryptedStream->QueryInterface( IID_IStream, (void**)&streamDecrypted ));
  81. __MPC_EXIT_IF_METHOD_FAILS(hr, SVC::OpenStreamForWrite( L"D:\\test3.enc", &streamDecryptedOutput ));
  82. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::BaseStream::TransferData( streamDecrypted, streamDecryptedOutput ));
  83. done:
  84. __MPC_FUNC_CLEANUP;
  85. if (pEO != NULL)
  86. pEO->Release();
  87. CoUninitialize();
  88. // Free HGlobal
  89. __MPC_FUNC_EXIT(hr);
  90. }