Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8518629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:02:02+00:00 2026-06-11T06:02:02+00:00

In a windows c++ console application I would like to read a password from

  • 0

In a windows c++ console application I would like to read a password from command-line input. The password is used for encryption (and later decryption, maybe elsewhere in the world on a windows pc with a different locale). So I worry about locales and encoding of that passphrase not giving the same numerical representation. On the same computer or a computer with the same locale this does obviously not give a problem.

Therefore I would like to be able to fixed encode (and normalize?) and store as UTF-8. which is recommended here: http://www.jasypt.org/howtoencryptuserpasswords.html (point 4).

There are many issues relating to encoding/unicode/UTF-8/codepages I don’t fully (or fully don’t) grasp. I fiddled with boost:locale and boost::nowide, but couldn’t figure it out or it doesn’t work under windows (dunno). Some links with more clarification on the issues (windows) involved:

http://alfps.wordpress.com/2011/11/22/unicode-part-1-windows-console-io-approaches/

http://alfps.wordpress.com/2011/12/08/unicode-part-2-utf-8-stream-mode/

But these links address the opposite problem! How to make things look the same no matter what underlying representation, I need the same underlying [bit-wise] representation, no matter how it looks!

So the question is, how do I make sure (and do I have to?) that the locale/encoding has no effect on the basic data that get encrypted, data, as in the sense of an array of 8-bit integers? I don’t necessarilly care about UTF-8 or Unicode, just need to be able to recover data, no matter what locale/encoding. The first link is helpful in explaining the issue.

Thoughts, C is not Unicode aware, would linking in some C-code help, or does C++ change that then again? Or will limiting input to “ASCII” characters (I know that doesn’t exist on windows) ALWAYS, as in ‘on any windows computer’) work?

Accepted solution:

void EncryptFileNames ( const boost::filesystem::path& p, const std::string& pw );

int main ( int argc, char **argv ) // No checking
{
    // Call with encrypt.exe c:\tmp pässwörd

    boost::nowide::args a ( argc, argv ); // Fix arguments - make them UTF-8

    boost::filesystem::path p ( argv [ 1 ] );

    EncryptFileNames ( p, boost::locale::normalize ( argv [ 2 ], boost::locale::norm_nfc, std::locale ( ) ) );

    return 0;
}

Thanks to all contributers.

PS: For encryption I use Crypto++ with VS2008SP1 and Boost (without ICU backend).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:02:04+00:00Added an answer on June 11, 2026 at 6:02 am

    Firstly UTF-8 is a red herring. To be international you must use an international character set, there is only one worth considering and it’s called Unicode. How you represent Unicode within your program (i.e. how you encode it) is up to you, as long as the encoding can represent all of Unicode there is no problem. You could pick UTF-8 but since you are working on Windows it seems reasonable to pick the encoding that Windows uses internally which is UTF-16. As bmargulies says you can use MultiByteToWideChar to get from the local representation (i.e. the local code page) to UTF-16. I don’t see the need to do the extra step and generate UTF-8 from UTF-16 but if you wanted to do that you could use WideCharToMultiByte.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A Delphi console application can be run from the command line of an existing
I'm writing a Windows console application in C++ and would like to return zero
I have console application and would like to run it as Windows service. VS2010
I want to run a console application (eg app.exe) from a windows form load
I have to run a console application from my Windows Application. The console application
I have a basic C# console application that I would like to run as
I have a console application that I would like to run as 'NT AUTHORITY\NetworkService',
I would like to develop GUI Windows Applications (not Console, but Forms and Buttons)
I am writing a console application which is rapidly gaining many command line arguments
I would like to know if it's possible to write a console application to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.