Search code examples
c++visual-c++mfccryptographyencode

How to use getBytes() in VC++


How to Use GetBytes() Method in VC++

In Java ,

         **byte[] saltedPassword = (password + getSalt()).getBytes();**

output :

 SaltedPassword :[B@3eca90

here saltedPassword get encoded value in the same way i want to implement in VC++

Please anyone give me a Solution.

Thanks in Advance..


Solution

  • A possible solution using MFC goes like this:

    CString getSalt()
    {
      return (CString)"mysalt" ;  // dummy function, should be replaced by *your* code
    }
    ...
    
    CByteArray saltedPassword ;
    CString password ;
    ...
    
    CString saltedpasswordstring = password + getSalt() ;
    
    for (int i = 0; i < saltedpasswordstring.GetLength() ; i++)
    {
      saltedPassword.Add((BYTE)saltedpasswordstring[i]) ;
    }
    
    // now the saltedPassword array contains what you want
    

    But maybe you should learn MFC and/or C++ before