mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
support rsa encrypt for passport api #207
Co-Authored-By: HolographicHat <58809250+HolographicHat@users.noreply.github.com>
This commit is contained in:
@@ -21,9 +21,4 @@ internal abstract class Md5Convert
|
||||
byte[] hash = MD5.HashData(Encoding.UTF8.GetBytes(source));
|
||||
return System.Convert.ToHexString(hash);
|
||||
}
|
||||
}
|
||||
|
||||
internal class RSAConvert
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Snap.Hutao.Web.Hoyolab;
|
||||
|
||||
/// <summary>
|
||||
|
||||
28
src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Passport/RSAUtil.cs
Normal file
28
src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Passport/RSAUtil.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Snap.Hutao.Web.Hoyolab.Passport;
|
||||
|
||||
/// <summary>
|
||||
/// 支持RSA转换
|
||||
/// </summary>
|
||||
internal static class RSAUtil
|
||||
{
|
||||
private const string RsaPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDvekdPMHN3AYhm/vktJT+YJr7cI5DcsNKqdsx5DZX0gDuWFuIjzdwButrIYPNmRJ1G8ybDIF7oDW2eEpm5sMbL9zs\n9ExXCdvqrn51qELbqj0XxtMTIpaCHFSI50PfPpTFV9Xt/hmyVwokoOXFlAEgCn+Q\nCgGs52bFoYMtyi+xEQIDAQAB\n";
|
||||
|
||||
/// <summary>
|
||||
/// 加密
|
||||
/// </summary>
|
||||
/// <param name="source">源</param>
|
||||
/// <returns>字节数组</returns>
|
||||
public static string Encrypt(string source)
|
||||
{
|
||||
RSA rsa = RSA.Create();
|
||||
rsa.ImportFromPem($"-----BEGIN PUBLIC KEY-----\n{RsaPublicKey}\n-----END PUBLIC KEY-----");
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(source);
|
||||
return Convert.ToBase64String(rsa.Encrypt(bytes, RSAEncryptionPadding.Pkcs1));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user