Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How does this translate to c++

How does this translate to c++

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    monsieur_jj
    wrote on last edited by
    #1

    Hi all, How does this translate to c++:

    string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));
    HashAlgorithm XHash = HashAlgorithm.Create("MD5");
    byte[] keyArray = XHash.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
    XHash.Clear();
    TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
    tdes.Key = keyArray;
    tdes.Mode = CipherMode.ECB;
    tdes.Padding = PaddingMode.PKCS7;

    This is what I did but i am not sure if its correct because I didnt do the UTF8Encoding part.

    TCHAR szKey[] = _T("Key");
    DWORD pwlen = _tcslen(szKey);
    result = CryptCreateHash(hProv,CALG_MD5,0,0,&hHash);
    result = CryptHashData(hHash,(BYTE *)szKey,pwlen,0);
    result = CryptDeriveKey(hProv,CALG_3DES,hHash,0,&hKey);
    BYTE PadMode = CRYPT_MODE_ECB;
    result = CryptSetKeyParam(hKey, PKCS5_PADDING, &PadMode, 0);

    Please help me clarify things. Thanks, Jayjay

    S 1 Reply Last reply
    0
    • M monsieur_jj

      Hi all, How does this translate to c++:

      string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));
      HashAlgorithm XHash = HashAlgorithm.Create("MD5");
      byte[] keyArray = XHash.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
      XHash.Clear();
      TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
      tdes.Key = keyArray;
      tdes.Mode = CipherMode.ECB;
      tdes.Padding = PaddingMode.PKCS7;

      This is what I did but i am not sure if its correct because I didnt do the UTF8Encoding part.

      TCHAR szKey[] = _T("Key");
      DWORD pwlen = _tcslen(szKey);
      result = CryptCreateHash(hProv,CALG_MD5,0,0,&hHash);
      result = CryptHashData(hHash,(BYTE *)szKey,pwlen,0);
      result = CryptDeriveKey(hProv,CALG_3DES,hHash,0,&hKey);
      BYTE PadMode = CRYPT_MODE_ECB;
      result = CryptSetKeyParam(hKey, PKCS5_PADDING, &PadMode, 0);

      Please help me clarify things. Thanks, Jayjay

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      Does it produce the same hash for a sample string as the C# code? That's a good way to tell if it's the same.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups