Sto cercando di capire quanto segue:Perché C# Convert.ToBase64String() mi dà 88 come lunghezza quando sto passando 64 byte?
Se sto dichiarando 64 byte come lunghezza dell'array (buffer). Quando converto in una stringa 64 di base, si dice che la lunghezza è 88. Non dovrebbe essere la lunghezza solo 64, dal momento che sto passando in 64 byte? Potrei essere totalmente frainteso come funziona questo reale. Se è così, potresti spiegarlo per favore.
//Generate a cryptographic random number
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
// Create byte array
byte[] buffer = new byte[64];
// Get random bytes
rng.GetBytes(buffer);
// This line gives me 88 as a result.
// Shouldn't it give me 64 as declared above?
throw new Exception(Convert.ToBase64String(buffer).Length.ToString());
// Return a Base64 string representation of the random number
return Convert.ToBase64String(buffer);
Btw: lanciare un'eccezione è un modo terribile per registrare un valore semplice ... –
Non userò la Crittografia RGN personalmente, Un RNG crittograficamente forte sarà più lento --- richiede più calcolo --- e sarà spettralmente bianco, – MethodMan
Guarda questo StackOverFlow Spiegazione del motivo per cui non è sicuro usare RGN http://stackoverflow.com/questions/4892588/rngcryptoserviceprovider-random-number-review – MethodMan