Skip to content

Commit

Permalink
🐛 Fix LuaCosmosCryptoLib sha256
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinbreiz committed Mar 3, 2024
1 parent 2599398 commit aa04b37
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion SRC/Aura_OS/Properties/VersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace Aura_OS
{
public class VersionInfo
{
public static string revision = "030320241840";
public static string revision = "030320241846";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ private static int CRYPTO_md5(ILuaState lua)
private static int CRYPTO_sha256(ILuaState lua)
{
string input = lua.L_CheckString(1);
var hashAlgorithm = new SHA256();
var hashBytes = hashAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(input));
lua.PushString(ToHexString(hashBytes));
var hashBytes = Aura_OS.System.Security.Sha256.hash(Encoding.UTF8.GetBytes(input));
lua.PushString(hashBytes);
return 1;
}

Expand Down Expand Up @@ -71,12 +70,9 @@ private static int FILE_CRYPTO_md5(ILuaState lua)
private static int FILE_CRYPTO_sha256(ILuaState lua)
{
string filePath = Path.Combine(Kernel.CurrentDirectory, lua.L_CheckString(1));
var hashAlgorithm = new SHA256();
using (var stream = File.OpenRead(filePath))
{
var hashBytes = hashAlgorithm.ComputeHash(stream);
lua.PushString(ToHexString(hashBytes));
}
byte[] file = File.ReadAllBytes(filePath);
var hashBytes = Aura_OS.System.Security.Sha256.hash(file);
lua.PushString(hashBytes);
return 1;
}

Expand Down
5 changes: 5 additions & 0 deletions SRC/Aura_OS/System/Security/SHA256.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public class Sha256
0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
};

public static string hash(byte[] tohash)
{
return Sha256.ComputeHash(tohash).ToUpperInvariant();
}

public static string hash(string tohash)
{
return Sha256.ComputeHash(Encoding.ASCII.GetBytes(tohash)).ToUpperInvariant();
Expand Down

0 comments on commit aa04b37

Please sign in to comment.