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 7075067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:07:59+00:00 2026-05-28T06:07:59+00:00

I want to provide the user the ability to save personal data encrypted. This

  • 0

I want to provide the user the ability to save personal data encrypted. This might be trivial or might have been already asked, but I am not able to find an example of an easy to use way to encrypt/decrypt a password.

I really don’t need any super-magic-unbreakable password. I just need the password to be like difficult to break.

I’ve seen some MSDN and SO questions but haven’t found something to use.

  • 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-05-28T06:07:59+00:00Added an answer on May 28, 2026 at 6:07 am

    David, I thought your answer was nifty, but I thought those would be niftier as extension methods. That would allow such syntax as:

    string cypherText;
    string clearText;
    
    using (var secureString = "Some string to encrypt".ToSecureString())
    {
        cypherText = secureString.EncryptString();
    }
    
    using (var secureString = cypherText.DecryptString())
    {
        clearText = secureString.ToInsecureString();
    }
    

    Here’s the updated code:

    using System;
    using System.Collections.Generic;
    using System.Runtime.InteropServices;
    using System.Security;
    using System.Security.Cryptography;
    using System.Text;
    
    public static class SecureIt
    {
        private static readonly byte[] entropy = Encoding.Unicode.GetBytes("Salt Is Not A Password");
    
        public static string EncryptString(this SecureString input)
        {
            if (input == null)
            {
                return null;
            }
    
            var encryptedData = ProtectedData.Protect(
                Encoding.Unicode.GetBytes(input.ToInsecureString()),
                entropy,
                DataProtectionScope.CurrentUser);
    
            return Convert.ToBase64String(encryptedData);
        }
    
        public static SecureString DecryptString(this string encryptedData)
        {
            if (encryptedData == null)
            {
                return null;
            }
    
            try
            {
                var decryptedData = ProtectedData.Unprotect(
                    Convert.FromBase64String(encryptedData),
                    entropy,
                    DataProtectionScope.CurrentUser);
    
                return Encoding.Unicode.GetString(decryptedData).ToSecureString();
            }
            catch
            {
                return new SecureString();
            }
        }
    
        public static SecureString ToSecureString(this IEnumerable<char> input)
        {
            if (input == null)
            {
                return null;
            }
    
            var secure = new SecureString();
    
            foreach (var c in input)
            {
                secure.AppendChar(c);
            }
    
            secure.MakeReadOnly();
            return secure;
        }
    
        public static string ToInsecureString(this SecureString input)
        {
            if (input == null)
            {
                return null;
            }
    
            var ptr = Marshal.SecureStringToBSTR(input);
    
            try
            {
                return Marshal.PtrToStringBSTR(ptr);
            }
            finally
            {
                Marshal.ZeroFreeBSTR(ptr);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to provide the ability to save some rendered data/charts (with the titles
I'm working on a resource management class and want to have the user provide
Say you have an app, that you want to provide users ability to browse
Im making an application where i want to provide the user with the ability
I want to provide for the user a service of encrypting some data via
I want to provide my user with some meaningful error messages when network requests
I want to provide a custom Batcher for Hibernate to use (for this reason:
I have a reference/lookup table whose main purpose is to provide the user with
I want to provide the mobile user (e.g. iPhone, Android, etc...) of my web
I use XNA to develop small 2D games. The user should have the ability

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.