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

  • Home
  • SEARCH
  • 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 8502121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:23:49+00:00 2026-06-11T01:23:49+00:00

I would like to encrypt and decrypt strings with a password. I use C#

  • 0

I would like to encrypt and decrypt strings with a password. I use C# and WinRT (MetroStyle). Have somebody a class for encryption/decryption?

  • 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-11T01:23:51+00:00Added an answer on June 11, 2026 at 1:23 am

    The normal .Net System.Security.Cryptography namespace does not exist in Metro. You use the CryptographicEngine class in Windows.Security.Cryptography.Core namespace instead.

    If the password is only being verified/authenticated, do not encrypt it. Instead, use the following:

    using Windows.Security.Cryptography.Core;
    using Windows.Security.Cryptography;
    using Windows.Storage.Streams;
    
    ...
    // Use Password Based Key Derivation Function 2 (PBKDF2 or RFC2898)
    KeyDerivationAlgorithmProvider pbkdf2 = 
        KeyDerivationAlgorithmProvider.OpenAlgorithm(
            KeyDerivationAlgorithmNames.Pbkdf2Sha256);
    
    // Do not store passwords in strings if you can avoid them. The
    // password may be retained in memory until it is garbage collected.
    // Crashing the application and looking at the memory dump may 
    // reveal it.
    IBuffer passwordBuffer = 
         CryptographicBuffer.ConvertStringToBinary("password", 
             BinaryStringEncoding.Utf8);
    CryptographicKey key = pbkdf2.CreateKey(passwordBuffer);
    
    // Use random salt and 10,000 iterations. Store the salt along with 
    // the derviedBytes (see below).
    IBuffer salt = CryptographicBuffer.GenerateRandom(32);
    KeyDerivationParameters parameters = 
        KeyDerivationParameters.BuildForPbkdf2(salt, 10000);
    
    // Store the returned 32 bytes along with the salt for later verification
    byte[] derviedBytes = 
        CryptographicEngine.DeriveKeyMaterial(key, parameters, 32).ToArray();
    

    When a password is supplied run through the same process using the same salt and compare derivedBytes. Store the secret as you would an encryption key.

    If the password will be used, such as to connect to another service:

    // Use AES, CBC mode with PKCS#7 padding (good default choice)
    SymmetricKeyAlgorithmProvider aesCbcPkcs7 = 
        SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7);
    
    // Create an AES 128-bit (16 byte) key
    CryptographicKey key = 
        aesCbcPkcs7.CreateSymmetricKey(CryptographicBuffer.GenerateRandom(16));
    
    // Creata a 16 byte initialization vector
    IBuffer iv = CryptographicBuffer.GenerateRandom(aesCbcPkcs7.BlockLength);
    
    // Encrypt the data
    byte[] plainText = Encoding.UTF8.GetBytes("Hello, world!"); // Data to encrypt
    byte[] cipherText = CryptographicEngine.Encrypt(
        key, plainText.AsBuffer(), iv).ToArray();
    
    // Decrypt the data
    string newPlainText = new string(
        Encoding.UTF8.GetChars(CryptographicEngine.Decrypt(
            key, cipherText.AsBuffer(), iv).ToArray()));
    
    // newPlainText contains "Hello, world!"
    

    As with any cryptography, make sure to protect your keys appropriately and follow best practise. The linked documentation also provides examples.

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

Sidebar

Related Questions

I would like to encrypt and decrypt a password using 128 bit AES encryption
I need a help regarding sound file encryption/decryption. I would like to encrypt a
We would like to use SQL Server Encryption to encrypt a couple of columns
I have a dictionary object which i would like to encrypt, then put it
I would like to know if I could encrypt two or more strings in
I would like to encrypt strings of 1500-2500 characters using an Asymmetric Key. It
I wrote these two classes that simple encrypt and decrypt strings: Encode.php class Encode
For Extra Security, i would like to Encrypt/Decrypt a MS Access 2000 (*.mdb) Database
I would like to encrypt a file using a symmetric key and decrypt it
Would like to know the best way to encrypt and decrypt an XML file

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.