From 72ea01d56600051378f5b6dc6736481b77091aae Mon Sep 17 00:00:00 2001 From: Gang Zhuo Date: Tue, 15 Sep 2015 06:48:23 -0400 Subject: [PATCH] no repeat random number generator The stock code use class Random to generate IV, the Random is pseudo random number generator. The IV maybe repeat, this will cause shadowsocks-libev closed the sockets with the error message 'invalid password or cipher'. Reference https://github.com/shadowsocks/shadowsocks-libev/issues/389 Solution is use class RNGCryptoServiceProvider to generate IV, of course it's lower performance, but a little bit. --- shadowsocks-csharp/Encryption/IVEncryptor.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shadowsocks-csharp/Encryption/IVEncryptor.cs b/shadowsocks-csharp/Encryption/IVEncryptor.cs index 32948d6b..b82d3adf 100755 --- a/shadowsocks-csharp/Encryption/IVEncryptor.cs +++ b/shadowsocks-csharp/Encryption/IVEncryptor.cs @@ -88,7 +88,8 @@ namespace Shadowsocks.Encryption protected static void randBytes(byte[] buf, int length) { byte[] temp = new byte[length]; - new Random().NextBytes(temp); + RNGCryptoServiceProvider rngServiceProvider = new RNGCryptoServiceProvider(); + rngServiceProvider.GetBytes(temp); temp.CopyTo(buf, 0); }