diff --git a/shadowsocks-csharp/Encryption/RNG.cs b/shadowsocks-csharp/Encryption/RNG.cs index b44c51ac..cd6c49f3 100644 --- a/shadowsocks-csharp/Encryption/RNG.cs +++ b/shadowsocks-csharp/Encryption/RNG.cs @@ -9,14 +9,12 @@ namespace Shadowsocks.Encryption public static void Init() { - if (_rng == null) - _rng = new RNGCryptoServiceProvider(); + _rng = _rng ?? new RNGCryptoServiceProvider(); } public static void Close() { - if (_rng == null) return; - _rng.Dispose(); + _rng?.Dispose(); _rng = null; } @@ -33,12 +31,12 @@ namespace Shadowsocks.Encryption public static void GetBytes(byte[] buf, int len) { - if (_rng == null) Reload(); + if (_rng == null) Init(); try { _rng.GetBytes(buf, 0, len); } - catch (System.Exception) + catch { // the backup way byte[] tmp = new byte[len];