Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

vb net code snippets for storing password

    /// <summary>
    /// Encrypts a given password and returns the encrypted data
    /// as a base64 string.
    /// </summary>
    /// <param name="plainText">An unencrypted string that needs
    /// to be secured.</param>
    /// <returns>A base64 encoded string that represents the encrypted
    /// binary data.
    /// </returns>
    /// <remarks>This solution is not really secure as we are
    /// keeping strings in memory. If runtime protection is essential,
    /// <see cref="SecureString"/> should be used.</remarks>
    /// <exception cref="ArgumentNullException">If <paramref name="plainText"/>
    /// is a null reference.</exception>
    public string Encrypt(string plainText)
    {
        if (plainText == null) throw new ArgumentNullException("plainText");

        //encrypt data
        var data = Encoding.Unicode.GetBytes(plainText);
        byte[] encrypted = ProtectedData.Protect(data, null, Scope);

        //return as base64 string
        return Convert.ToBase64String(encrypted);
    }

    /// <summary>
    /// Decrypts a given string.
    /// </summary>
    /// <param name="cipher">A base64 encoded string that was created
    /// through the <see cref="Encrypt(string)"/> or
    /// <see cref="Encrypt(SecureString)"/> extension methods.</param>
    /// <returns>The decrypted string.</returns>
    /// <remarks>Keep in mind that the decrypted string remains in memory
    /// and makes your application vulnerable per se. If runtime protection
    /// is essential, <see cref="SecureString"/> should be used.</remarks>
    /// <exception cref="ArgumentNullException">If <paramref name="cipher"/>
    /// is a null reference.</exception>
    public string Decrypt(string cipher)
    {
        if (cipher == null) throw new ArgumentNullException("cipher");

        //parse base64 string
        byte[] data = Convert.FromBase64String(cipher);

        //decrypt data
        byte[] decrypted = ProtectedData.Unprotect(data, null, Scope);
        return Encoding.Unicode.GetString(decrypted);
    }
Comment

PREVIOUS NEXT
Code Example
Typescript :: python write a program that asks the user for a weight in kilograms and converts it to pounds 
Typescript :: instruments du marché monétaire 
Typescript :: install vsts client version 14.102.0 
Typescript :: The dialect mongodb+srv is not supported. Supported dialects feathers 
Cpp :: how to convert string to wchar_t in c++ 
Cpp :: dart async function 
Cpp :: c++ measure time 
Cpp :: qt debug 
Cpp :: c++ primality test 
Cpp :: cpp print vector 
Cpp :: c++ how to loop through a vector but not the last element 
Cpp :: how to check datatype of a variable in c++ 
Cpp :: initialize vector to all zeros c++ 
Cpp :: log base c++ 
Cpp :: C++ system text format 
Cpp :: fatal error: opencv2/opencv.hpp: No such file or directory 
Cpp :: cpp how to input a variable without hitting enter 
Cpp :: ue4 get bone location c++ 
Cpp :: c++ how to generate a random number in a range 
Cpp :: ue4 find component c++ 
Cpp :: C++ add value to exception message 
Cpp :: c++ loop programs 
Cpp :: differency between c++ std and stl 
Cpp :: initialize 2d vector of ints c++ 
Cpp :: recursive power in c++ 
Cpp :: winmain example 
Cpp :: how to make crypto 
Cpp :: fork was not declared in this scope 
Cpp :: how to get input in cpp 
Cpp :: c++ code for selection sort 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =