Skip to content

Commit b22be04

Browse files
authored
Merge pull request #17 from YassinLokhat/16-fix-code-scanning-alert---workflow-does-not-contain-permissions
16 fix code scanning alert workflow does not contain permissions
2 parents 0da3d67 + 77e7304 commit b22be04

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

.github/workflows/dotnet.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ jobs:
2525
run: dotnet build --no-restore
2626
- name: Test
2727
run: dotnet test --no-build --verbosity normal
28+
29+
permissions:
30+
contents: read
31+
issues: write
32+
pull-requests: write

Core/Public/Utils/CryptographyCenter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ private string _decryptAes(string source, string[] passwords)
281281
private string _encryptRsa(string source, RSACryptoServiceProvider csp)
282282
{
283283
byte[] bytesPlainTextData = Encoding.Unicode.GetBytes(source);
284-
byte[] bytesCypherText = csp.Encrypt(bytesPlainTextData, false);
284+
byte[] bytesCypherText = csp.Encrypt(bytesPlainTextData, true);
285285

286286
source = Convert.ToBase64String(bytesCypherText);
287287

@@ -293,7 +293,7 @@ private string _decryptRsa(string source, int level, RSACryptoServiceProvider cs
293293
try
294294
{
295295
byte[] bytesCypherText = Convert.FromBase64String(source);
296-
byte[] bytesPlainTextData = csp.Decrypt(bytesCypherText, false);
296+
byte[] bytesPlainTextData = csp.Decrypt(bytesCypherText, true);
297297

298298
return Encoding.Unicode.GetString(bytesPlainTextData);
299299
}

UnitTests/UnitTestsHelper.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using FluentAssertions;
22
using System.Runtime.CompilerServices;
3+
using System.Security.Cryptography;
34
using Upsilon.Apps.PassKey.Core.Public.Enums;
45
using Upsilon.Apps.PassKey.Core.Public.Interfaces;
56
using Upsilon.Apps.PassKey.Core.Public.Utils;
@@ -85,7 +86,14 @@ public static void ClearTestEnvironment([CallerMemberName] string username = "")
8586

8687
public static string GetUsername([CallerMemberName] string username = "") => username;
8788

88-
private static Random _getRandom() => new((int)DateTime.Now.Ticks);
89+
private static RandomNumberGenerator _randomNumberGenerator => RandomNumberGenerator.Create();
90+
private static Random _getRandom()
91+
{
92+
byte[] byteSeed = new byte[4];
93+
_randomNumberGenerator.GetBytes(byteSeed);
94+
int seed = BitConverter.ToInt32(byteSeed, 0);
95+
return new Random(seed);
96+
}
8997

9098
public static string[] GetRandomStringArray(int count = 0)
9199
{
@@ -125,12 +133,7 @@ public static string GetRandomString(int min = 10, int max = 0)
125133

126134
public static int GetRandomInt(int max) => GetRandomInt(0, max);
127135

128-
public static int GetRandomInt(int min, int max)
129-
{
130-
Random random = _getRandom();
131-
132-
return random.Next(min, max);
133-
}
136+
public static int GetRandomInt(int min, int max) => _getRandom().Next(min, max);
134137

135138
public static void LastLogsShouldMatch(IDatabase database, string[] expectedLogs)
136139
{

0 commit comments

Comments
 (0)