From e6e1b146185ee554c9646771f8f4a5b137c9ef58 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 4 Dec 2021 13:08:49 -0600 Subject: add Random --- src/slskd/Common/Cryptography/Random.cs | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/slskd/Common/Cryptography/Random.cs (limited to 'src') diff --git a/src/slskd/Common/Cryptography/Random.cs b/src/slskd/Common/Cryptography/Random.cs new file mode 100644 index 00000000..94d4fa24 --- /dev/null +++ b/src/slskd/Common/Cryptography/Random.cs @@ -0,0 +1,35 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd.Cryptography +{ + using System.Security.Cryptography; + + public static class Random + { + public static byte[] GetBytes(int size) + { + var key = new byte[size]; + using (var generator = RandomNumberGenerator.Create()) + { + generator.GetBytes(key); + } + + return key; + } + } +} -- cgit v1.2.3