23 lines
768 B
C#
23 lines
768 B
C#
using System.Security.Cryptography;
|
|
using System.Text;
|
|
|
|
namespace XWorld.PublishTool
|
|
{
|
|
public static class ManifestSigner
|
|
{
|
|
public static byte[] Sign(string content, string privateKeyPem)
|
|
{
|
|
using var rsa = RSA.Create();
|
|
rsa.ImportFromPem(privateKeyPem);
|
|
return rsa.SignData(Encoding.UTF8.GetBytes(content), HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
|
}
|
|
|
|
public static bool Verify(string content, byte[] signature, string publicKeyPem)
|
|
{
|
|
using var rsa = RSA.Create();
|
|
rsa.ImportFromPem(publicKeyPem);
|
|
return rsa.VerifyData(Encoding.UTF8.GetBytes(content), signature, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
|
}
|
|
}
|
|
}
|