Create Salt for Cryptography - CSharp System.Security.Cryptography

CSharp examples for System.Security.Cryptography:Salt

Description

Create Salt for Cryptography

Demo Code


using System.Security.Cryptography;
using System.Text;
using System;/* w  w  w. j a  v a  2  s  .co m*/

public class Main{
        public static string CreateSalt(int length) {
            var data = new byte[length];
            var salt = new char[length];

            new Random().NextBytes(data);

            for (int i = 0; i < length; i++) {
                salt[i] = Base64[data[i] & 0x3F];
            }

            return new string(salt);
        }
}

Related Tutorials