I have designed a small method to generate a salt for a password. All this does is create a random salt and does nothing to add it to the password. I have a few questions regarding my very simple method:
- Is this a secure generator?
- Currently, it encodes in base64. Is this an issue in any way?
- Are there any other potential issues? How could I improve this in terms of security, speed, etc...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Text;
using System.Security.Cryptography;
namespace Test
{
public class Program
{
// Here is a method to generate a random password salt
private static string getSalt()
{
var random = new RNGCryptoServiceProvider();
// Maximum length of salt
int max_length = 32;
// Empty salt array
byte[] salt = new byte[max_length];
// Build the random bytes
random.GetNonZeroBytes(salt);
// Return the string encoded salt
return Convert.ToBase64String(salt);
}
static void Main(string[] args)
{
System.Console.WriteLine(getSalt());
System.Console.ReadKey();
}
}
}
GetNonZeroBytes
and notGetBytes
? This limits the output minimally (254 possible values per byte, instead of 255), but I'm just wondering. :) \$\endgroup\$