Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am able to encrypt the string using public key provided using c#. But i want to save the encrypted string in windows vault folder in c#.

What I have tried:

Core code is as below:
using System;
using System.Linq;
using System.Numerics;
using System.Text;

class Test
{
    const int p = 61;
    const int q = 53;
    const int n = 3233;
    const int totient = 3120;
    const int e = 991;
    const int d = 1231;

    static void Main()
    {
        var encrypted = Encrypt("Hello, world.", Encoding.UTF8);
        var decrypted = Decrypt(encrypted, Encoding.UTF8);
        Console.WriteLine(decrypted);
    }

    static BigInteger[] Encrypt(string text, Encoding encoding)
    {
        byte[] bytes = encoding.GetBytes(text);
        return bytes.Select(b => BigInteger.ModPow(b, (BigInteger)e, n))
                    .ToArray();
    }

    static string Decrypt(BigInteger[] encrypted, Encoding encoding)
    {
        byte[] bytes = encrypted.Select(bi => (byte) BigInteger.ModPow(bi, d, n))
                                .ToArray();
        return encoding.GetString(bytes);
    }
Posted
Updated 17-May-18 7:13am

 
Share this answer
 
In addition to Richard's answer, here is an example: How to store and retrieve credentials on windows using C# - Stack Overflow[^]
 
Share this answer
 
Comments
ranio 18-May-18 3:06am    
I am able to save the credentials in the windows vault folder, but I can see the same and edit by going to Control Panel->User Accounts->Credential Manager. i need to keep it secured
ranio 18-May-18 3:40am    
What is the Password length limit while saving in Windows vault folder using c#?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900