//
namespace SafeCampus.Core.Utils;
///
/// SM2加密解密
///
public class SM2Util
{
///
/// 公钥
///
public static string PublicKey = App.GetConfig("Cryptogram:SM2:PublicKey");
///
/// 私钥
///
public static string PrivateKey = App.GetConfig("Cryptogram:SM2:PrivateKey");
///
/// 公钥加密明文
///
/// 明文
/// 密文
public static string Encrypt(string plainText)
{
return SM2CryptoUtil.Encrypt(PublicKey, plainText);
}
///
/// 私钥解密密文
///
/// 密文
/// 明文
public static string Decrypt(string cipherText)
{
if (!cipherText.StartsWith("04")) cipherText = "04" + cipherText;//如果不是04开头加上04
return SM2CryptoUtil.Decrypt(PrivateKey, cipherText);
}
}