using System;
using Com.Bocom.OpenApi.Security.Sign;

namespace Com.Bocom.OpenApi
{
    namespace Utils
    {
        public class BocomSignature
        {
            public static string Sign(string encryptType, string content, string privateKey, string charset)
            {
                if (BocomConstants.ENCRYPT_TYPE_RSA_AND_AES == encryptType)
                {
                    return RSASignature.Sign(content, privateKey, charset);
                }

                if (BocomConstants.ENCRYPT_TYPE_SM2_AND_SM4 == encryptType)
                {
                    return SM2Signature.Sign(content, privateKey, charset);
                }

                throw new BocomApiException("仅支持使用RSA和SM2签名！");
            }

            public static bool Verify(string encryptType, string content, string publicKey, string charset, string signature)
            {
                if (BocomConstants.ENCRYPT_TYPE_RSA_AND_AES == encryptType)
                {
                    return RSASignature.Verify(content, publicKey, charset, signature);
                }

                if (BocomConstants.ENCRYPT_TYPE_SM2_AND_SM4 == encryptType)
                {
                    return SM2Signature.Verify(content, publicKey, charset, signature);
                }

                throw new BocomApiException("仅支持使用RSA和SM2验签！");
            }
        }
    }
}