diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Convert/Md5Convert.cs b/src/Snap.Hutao/Snap.Hutao/Core/Convert/Md5Convert.cs index 001b5802..e20f3c09 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Convert/Md5Convert.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Convert/Md5Convert.cs @@ -21,9 +21,4 @@ internal abstract class Md5Convert byte[] hash = MD5.HashData(Encoding.UTF8.GetBytes(source)); return System.Convert.ToHexString(hash); } -} - -internal class RSAConvert -{ - } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/ApiEndpoints.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/ApiEndpoints.cs index a39a503c..716a3d2e 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/ApiEndpoints.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/ApiEndpoints.cs @@ -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; /// diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Passport/RSAUtil.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Passport/RSAUtil.cs new file mode 100644 index 00000000..44674ea3 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Passport/RSAUtil.cs @@ -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; + +/// +/// 支持RSA转换 +/// +internal static class RSAUtil +{ + private const string RsaPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDvekdPMHN3AYhm/vktJT+YJr7cI5DcsNKqdsx5DZX0gDuWFuIjzdwButrIYPNmRJ1G8ybDIF7oDW2eEpm5sMbL9zs\n9ExXCdvqrn51qELbqj0XxtMTIpaCHFSI50PfPpTFV9Xt/hmyVwokoOXFlAEgCn+Q\nCgGs52bFoYMtyi+xEQIDAQAB\n"; + + /// + /// 加密 + /// + /// 源 + /// 字节数组 + 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)); + } +} \ No newline at end of file